Skip to content

Commit

Permalink
Eliminate Linq usage in Packed
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcarbon authored and abergs committed Sep 28, 2022
1 parent 4942e2f commit e4cd129
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
21 changes: 14 additions & 7 deletions Src/Fido2/AttestationFormat/Packed.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;

using Fido2NetLib.Cbor;
Expand All @@ -9,18 +9,25 @@ namespace Fido2NetLib
{
internal sealed class Packed : AttestationVerifier
{
private static readonly string[] s_newLine = new string[] { Environment.NewLine };

public static bool IsValidPackedAttnCertSubject(string attnCertSubj)
{
// parse the DN string using standard rules
var dictSubjectObj = new X500DistinguishedName(attnCertSubj);

// form the string for splitting using new lines to avoid issues with commas
var dictSubjectString = dictSubjectObj.Decode(X500DistinguishedNameFlags.UseNewLines);
var dictSubject = dictSubjectString.Split(s_newLine, StringSplitOptions.None)
.Select(part => part.Split('='))
.ToDictionary(split => split[0], split => split[1]);
string dictSubjectString = dictSubjectObj.Decode(X500DistinguishedNameFlags.UseNewLines);

var dictSubject = new Dictionary<string, string>();

foreach (var line in dictSubjectString.AsSpan().EnumerateLines())
{
int equalIndex = line.IndexOf('=');

var lhs = line.Slice(0, equalIndex).ToString();
var rhs = line.Slice(equalIndex + 1).ToString();

dictSubject[lhs] = rhs;
}

return dictSubject["C"].Length != 0
&& dictSubject["O"].Length != 0
Expand Down
1 change: 1 addition & 0 deletions Src/Fido2/Fido2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<Nullable>enable</Nullable>
<RootNamespace>Fido2NetLib</RootNamespace>
<IsTrimmable>true</IsTrimmable>
<NoWarn>IDE0057</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit e4cd129

Please sign in to comment.