Skip to content

Commit 28347e3

Browse files
iamcarbonabergs
authored andcommitted
Add 5 variable Concat overload
1 parent c4d42f6 commit 28347e3

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

Src/Fido2/AttestationFormat/FidoU2f.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ X5c.Values.Count is 0 ||
6565
var publicKeyU2F = DataHelper.Concat(stackalloc byte[1] { 0x4 }, x, y);
6666

6767
// 5. Let verificationData be the concatenation of (0x00 || rpIdHash || clientDataHash || credentialId || publicKeyU2F)
68-
var verificationData = new byte[1] { 0x00 };
69-
verificationData = verificationData
70-
.Concat(AuthData.RpIdHash)
71-
.Concat(clientDataHash)
72-
.Concat(AuthData.AttestedCredentialData.CredentialID)
73-
.Concat(publicKeyU2F.ToArray())
74-
.ToArray();
68+
byte[] verificationData = DataHelper.Concat(
69+
stackalloc byte[1] { 0x00 },
70+
AuthData.RpIdHash,
71+
clientDataHash,
72+
AuthData.AttestedCredentialData.CredentialID,
73+
publicKeyU2F
74+
);
7575

7676
// 6. Verify the sig using verificationData and certificate public key
7777
if (Sig is null || Sig.Type != CBORType.ByteString || Sig.GetByteString().Length is 0)

Src/Fido2/Extensions/DataHelper.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23

34
namespace Fido2NetLib
45
{
@@ -24,5 +25,27 @@ public static byte[] Concat(ReadOnlySpan<byte> a, ReadOnlySpan<byte> b, ReadOnly
2425

2526
return result;
2627
}
28+
29+
public static byte[] Concat(ReadOnlySpan<byte> a, ReadOnlySpan<byte> b, ReadOnlySpan<byte> c, ReadOnlySpan<byte> d, ReadOnlySpan<byte> e)
30+
{
31+
var result = new byte[a.Length + b.Length + c.Length + d.Length + e.Length];
32+
33+
var position = 0;
34+
a.CopyTo(result);
35+
position += a.Length;
36+
37+
b.CopyTo(result.AsSpan(position));
38+
position += b.Length;
39+
40+
c.CopyTo(result.AsSpan(position));
41+
position += c.Length;
42+
43+
d.CopyTo(result.AsSpan(position));
44+
position += d.Length;
45+
46+
e.CopyTo(result.AsSpan(position));
47+
48+
return result;
49+
}
2750
}
2851
}

0 commit comments

Comments
 (0)