-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ROS<byte> instead of byte[] where it makes sense on S.S.C.Cose (#…
…66741) * Use ROS<byte> instead of byte[] on S.S.C.Cose * Add TrySign and improve Sign implementation to use less byte[] * Add TrySign tests * Address using scope feedback * Address src feedback * Refactor tests to avoid duplicated ones * Remove invalid asserts in Crypto code * Fix 'new()' without the type on the left-hand side * Fix ThreadStatic issues in tests * * Don't use ArrayPool in SignCore * Add comment describing reusability of encoded protected headers * Cache toBeSigned * Don't cache toBeSigned for detached content * Address nits in tests
- Loading branch information
Showing
12 changed files
with
977 additions
and
599 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...es/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHelpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Text; | ||
|
||
namespace System.Security.Cryptography.Cose | ||
{ | ||
internal static class CoseHelpers | ||
{ | ||
private static readonly UTF8Encoding s_utf8EncodingStrict = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true); | ||
|
||
internal static int GetByteStringEncodedSize(int bstrLength) | ||
{ | ||
return GetIntegerEncodedSize(bstrLength) + bstrLength; | ||
} | ||
|
||
internal static int GetTextStringEncodedSize(string value) | ||
{ | ||
int strEncodedLength = s_utf8EncodingStrict.GetByteCount(value); | ||
return GetIntegerEncodedSize(strEncodedLength) + strEncodedLength; | ||
} | ||
|
||
internal static int GetIntegerEncodedSize(long value) | ||
{ | ||
if (value < 0) | ||
{ | ||
ulong unsignedRepresentation = (value == long.MinValue) ? (ulong)long.MaxValue : (ulong)(-value) - 1; | ||
return GetIntegerEncodedSize(unsignedRepresentation); | ||
} | ||
else | ||
{ | ||
return GetIntegerEncodedSize((ulong)value); | ||
} | ||
} | ||
|
||
internal static int GetIntegerEncodedSize(ulong value) | ||
{ | ||
if (value < 24) | ||
{ | ||
return 1; | ||
} | ||
else if (value <= byte.MaxValue) | ||
{ | ||
return 1 + sizeof(byte); | ||
} | ||
else if (value <= ushort.MaxValue) | ||
{ | ||
return 1 + sizeof(ushort); | ||
} | ||
else if (value <= uint.MaxValue) | ||
{ | ||
return 1 + sizeof(uint); | ||
} | ||
else | ||
{ | ||
return 1 + sizeof(ulong); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.