From e4cd129b9fd12b5f2dce58244f532c9fccd44fbd Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 6 Sep 2022 14:37:49 -0700 Subject: [PATCH] Eliminate Linq usage in Packed --- Src/Fido2/AttestationFormat/Packed.cs | 21 ++++++++++++++------- Src/Fido2/Fido2.csproj | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Src/Fido2/AttestationFormat/Packed.cs b/Src/Fido2/AttestationFormat/Packed.cs index 4e655fc8..28683684 100644 --- a/Src/Fido2/AttestationFormat/Packed.cs +++ b/Src/Fido2/AttestationFormat/Packed.cs @@ -1,5 +1,5 @@ using System; -using System.Linq; +using System.Collections.Generic; using System.Security.Cryptography.X509Certificates; using Fido2NetLib.Cbor; @@ -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(); + + 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 diff --git a/Src/Fido2/Fido2.csproj b/Src/Fido2/Fido2.csproj index 469cb955..5b191c33 100644 --- a/Src/Fido2/Fido2.csproj +++ b/Src/Fido2/Fido2.csproj @@ -4,6 +4,7 @@ enable Fido2NetLib true + IDE0057