From 81ea94a4afd0e66721823729069a87965ef443e8 Mon Sep 17 00:00:00 2001 From: Yann Crumeyrolle Date: Wed, 8 Dec 2021 15:42:36 +0100 Subject: [PATCH 01/34] Update dotnetcore.yml --- .github/workflows/dotnetcore.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 7a447500..c6ad6787 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -56,6 +56,10 @@ jobs: uses: actions/setup-dotnet@v1 with: dotnet-version: '5.0.x' + - name: Setup dotnet '6.x' + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '6.0.x' - name: Restore dependencies run: dotnet restore From 3d18959f021091a954ab99a80375b81191f1120d Mon Sep 17 00:00:00 2001 From: Yann Crumeyrolle Date: Wed, 8 Dec 2021 15:44:15 +0100 Subject: [PATCH 02/34] Update JsonWebToken.csproj --- src/JsonWebToken/JsonWebToken.csproj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/JsonWebToken/JsonWebToken.csproj b/src/JsonWebToken/JsonWebToken.csproj index 62827ba8..db93337e 100644 --- a/src/JsonWebToken/JsonWebToken.csproj +++ b/src/JsonWebToken/JsonWebToken.csproj @@ -1,7 +1,7 @@  - net5.0;netstandard2.0;netcoreapp2.1;netcoreapp3.1 + net5.0;ne6.0;netstandard2.0;netcoreapp2.1;netcoreapp3.1 $(TargetFrameworks);net461;net47 9.0 enable @@ -116,4 +116,8 @@ $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD $(DefineConstants);SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_RUNE;SUPPORT_SPAN_STREAM;SUPPORT_SKIPLOCALINIT + + $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD + $(DefineConstants);SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_RUNE;SUPPORT_SPAN_STREAM;SUPPORT_SKIPLOCALINIT + From 9679ba8abe8a8f2cc17f0fe4e7df448a5a15ee20 Mon Sep 17 00:00:00 2001 From: Yann Crumeyrolle Date: Wed, 8 Dec 2021 15:46:16 +0100 Subject: [PATCH 03/34] Remove netcoreapp2.1 (deprecated) --- src/JsonWebToken/JsonWebToken.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/JsonWebToken/JsonWebToken.csproj b/src/JsonWebToken/JsonWebToken.csproj index db93337e..4fe852ea 100644 --- a/src/JsonWebToken/JsonWebToken.csproj +++ b/src/JsonWebToken/JsonWebToken.csproj @@ -1,7 +1,7 @@  - net5.0;ne6.0;netstandard2.0;netcoreapp2.1;netcoreapp3.1 + net5.0;ne6.0;netstandard2.0;netcoreapp2.2;netcoreapp3.1 $(TargetFrameworks);net461;net47 9.0 enable @@ -103,7 +103,7 @@ $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE CS8601;CS8602;CS8604;CS8618 - + $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING $(DefineConstants);SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_SPAN_STREAM CS8601;CS8602;CS8604;CS8618 From 588fd53bc22a38d6aeca6071b8fde3335a0610ee Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Tue, 23 Apr 2024 00:52:03 +0200 Subject: [PATCH 04/34] Add support for net7 & net8 --- README.md | 16 +- perf/Sandbox/FixedTimeEqualsBenchmark.cs | 2 +- perf/Sandbox/Sha256Benchmarks.cs | 56 ++--- perf/Sandbox/Sha512Benchmarks.cs | 112 +++++----- .../Internal/DoesNotReturnAttribute.cs | 2 +- .../Internal/MemberNotNullAttribute.cs | 2 +- .../Internal/NotNullWhenAttribute.cs | 2 +- src/JsonWebToken/JsonWebToken.csproj | 210 +++++++++--------- src/KeyVault/JsonWebToken.KeyVault.csproj | 2 +- src/OAuth2/JsonWebToken.OAuth2.csproj | 2 +- .../JsonWebToken.SecurityEventTokens.csproj | 2 +- .../JsonWebToken.OAuth2.Tests.csproj | 2 +- ...nWebToken.SecurityEventTokens.Tests.csproj | 2 +- .../JsonWebToken.Tests.Common.csproj | 2 +- test/JsonWebToken.Tests/DescriptorTests.cs | 2 +- .../JsonWebToken.Tests.csproj | 4 +- test/JsonWebToken.Tests/JwtMemberTests.cs | 2 +- 17 files changed, 215 insertions(+), 207 deletions(-) diff --git a/README.md b/README.md index f0e0ccb2..28d9a777 100644 --- a/README.md +++ b/README.md @@ -126,10 +126,10 @@ The main reason of the efficiency of this library is the usage of the new API pr | RS256 | RSASSA-PKCS1-v1_5 using SHA-256 | netstandard2.0 | RS384 | RSASSA-PKCS1-v1_5 using SHA-384 | netstandard2.0 | RS512 | RSASSA-PKCS1-v1_5 using SHA-512 | netstandard2.0 -| ES256 | ECDSA using curve P-256 and SHA-256 | netcoreapp2.1 -| ES384 | ECDSA using curve P-384 and SHA-384 | netcoreapp2.1 -| ES512 | ECDSA using curve P-521 and SHA-512 | netcoreapp2.1 -| ES256K | ECDSA using curve secp256k1 and SHA-256 | netcoreapp2.1 (not available on MacOS) +| ES256 | ECDSA using curve P-256 and SHA-256 | netcoreapp2.2 +| ES384 | ECDSA using curve P-384 and SHA-384 | netcoreapp2.2 +| ES512 | ECDSA using curve P-521 and SHA-512 | netcoreapp2.2 +| ES256K | ECDSA using curve secp256k1 and SHA-256 | netcoreapp2.2 (not available on MacOS) | PS256 | RSASSA-PSS using SHA-256 and MGF1 with SHA-256 | netstandard2.0 | PS384 | RSASSA-PSS using SHA-384 and MGF1 with SHA-384 | netstandard2.0 | PS512 | RSASSA-PSS using SHA-512 and MGF1 with SHA-512 | netstandard2.0 @@ -155,10 +155,10 @@ The main reason of the efficiency of this library is the usage of the new API pr | A192KW | AES Key Wrap with default initial value using 192-bit key | netstandard2.0 | A256KW | AES Key Wrap with default initial value using 256-bit key | netstandard2.0 | dir | Direct use of a shared symmetric key as the CEK | netstandard2.0 -| ECDH-ES | Elliptic Curve Diffie-Hellman Ephemeral Static key agreement using Concat KDF | netcoreapp2.1 -| ECDH-ES+A128KW | ECDH-ES using Concat KDF and CEK wrapped with "A128KW" | netcoreapp2.1 -| ECDH-ES+A192KW | ECDH-ES using Concat KDF and CEK wrapped with "A192KW" | netcoreapp2.1 -| ECDH-ES+A256KW | ECDH-ES using Concat KDF and CEK wrapped with "A256KW" | netcoreapp2.1 +| ECDH-ES | Elliptic Curve Diffie-Hellman Ephemeral Static key agreement using Concat KDF | netcoreapp2.2 +| ECDH-ES+A128KW | ECDH-ES using Concat KDF and CEK wrapped with "A128KW" | netcoreapp2.2 +| ECDH-ES+A192KW | ECDH-ES using Concat KDF and CEK wrapped with "A192KW" | netcoreapp2.2 +| ECDH-ES+A256KW | ECDH-ES using Concat KDF and CEK wrapped with "A256KW" | netcoreapp2.2 | A128GCMKW | Key wrapping with AES GCM using 128-bit key | netcoreapp3.0 | A192GCMKW | Key wrapping with AES GCM using 192-bit key | netcoreapp3.0 | A256GCMKW | Key wrapping with AES GCM using 256-bit key | netcoreapp3.0 diff --git a/perf/Sandbox/FixedTimeEqualsBenchmark.cs b/perf/Sandbox/FixedTimeEqualsBenchmark.cs index 1a0345e7..3cbbab31 100644 --- a/perf/Sandbox/FixedTimeEqualsBenchmark.cs +++ b/perf/Sandbox/FixedTimeEqualsBenchmark.cs @@ -92,7 +92,7 @@ public override string ToString() private static unsafe bool AreEqual_Current(ref byte first, ref byte second, int l) { IntPtr length = (IntPtr)l; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported && (byte*)length == (byte*)64) { return diff --git a/perf/Sandbox/Sha256Benchmarks.cs b/perf/Sandbox/Sha256Benchmarks.cs index c019135f..8e7d59e3 100644 --- a/perf/Sandbox/Sha256Benchmarks.cs +++ b/perf/Sandbox/Sha256Benchmarks.cs @@ -111,7 +111,7 @@ public sealed class Sha256_Original : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha256BlockSize ? 64 * 16 : 64 * 4; @@ -183,7 +183,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha256BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { ref byte src128EndRef = ref Unsafe.Add(ref srcStartRef, source.Length - 4 * Sha256BlockSize + 1); @@ -230,7 +230,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p Transform(ref stateRef, ref lastBlockRef, ref wRef); ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { Unsafe.WriteUnaligned(ref destinationRef, Avx2.Shuffle(Unsafe.ReadUnaligned>(ref Unsafe.As(ref MemoryMarshal.GetReference(state))), _shuffleMask256)); @@ -254,7 +254,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector128 Gather(ref byte message) { @@ -418,7 +418,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui private void Transform(ref uint state, ref byte currentBlock, ref uint w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -510,7 +510,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint RotateRight(uint a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (32 - b)); @@ -552,7 +552,7 @@ private static uint Maj(uint x, uint y, uint z) 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 // 3, 2, 1, 0, 7, 6, 5, 4, // 11, 10, 9, 8, 15, 14, 13, 12, // 19, 18, 17, 16, 23, 22, 21, 20, @@ -681,7 +681,7 @@ public sealed class Sha256_Original_IntPtr : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha256BlockSize ? 64 * 16 : 64 * 4; @@ -752,7 +752,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha256BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { ref byte src128EndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - 4 * Sha256BlockSize + 1)); @@ -799,7 +799,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p Transform(ref stateRef, ref lastBlockRef, ref wRef); ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { Unsafe.WriteUnaligned(ref destinationRef, Avx2.Shuffle(Unsafe.ReadUnaligned>(ref Unsafe.As(ref MemoryMarshal.GetReference(state))), _shuffleMask256)); @@ -823,7 +823,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector128 Gather(ref byte message) { @@ -1018,7 +1018,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui private void Transform(ref uint state, ref byte currentBlock, ref uint w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -1110,7 +1110,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint RotateRight(uint a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (32 - b)); @@ -1152,7 +1152,7 @@ private static uint Maj(uint x, uint y, uint z) 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 // 3, 2, 1, 0, 7, 6, 5, 4, // 11, 10, 9, 8, 15, 14, 13, 12, // 19, 18, 17, 16, 23, 22, 21, 20, @@ -1280,7 +1280,7 @@ public class Sha256_Original_IntPtr_MaskROS : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha256BlockSize ? 64 * 16 : 64 * 4; @@ -1351,7 +1351,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha256BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { ref byte src128EndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - 4 * Sha256BlockSize + 1)); @@ -1398,7 +1398,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p Transform(ref stateRef, ref lastBlockRef, ref wRef); ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { Unsafe.WriteUnaligned(ref destinationRef, Avx2.Shuffle(Unsafe.ReadUnaligned>(ref Unsafe.As(ref MemoryMarshal.GetReference(state))), _shuffleMask256)); @@ -1422,7 +1422,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector128 Gather(ref byte message) { @@ -1618,7 +1618,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui private void Transform(ref uint state, ref byte currentBlock, ref uint w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -1712,7 +1712,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint RotateRight(uint a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (32 - b)); @@ -1754,7 +1754,7 @@ private static uint Maj(uint x, uint y, uint z) 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector128 K128(IntPtr i) => Unsafe.Add(ref _k128[0], i); @@ -1865,7 +1865,7 @@ public class Sha256_Original_IntPtr_KROS : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha256BlockSize ? 64 * 16 : 64 * 4; @@ -1936,7 +1936,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha256BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { ref byte src128EndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - 4 * Sha256BlockSize + 1)); @@ -1983,7 +1983,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p Transform(ref stateRef, ref lastBlockRef, ref wRef); ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { Unsafe.WriteUnaligned(ref destinationRef, Avx2.Shuffle(Unsafe.ReadUnaligned>(ref Unsafe.As(ref MemoryMarshal.GetReference(state))), _shuffleMask256)); @@ -2007,7 +2007,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector128 Gather(ref byte message) { @@ -2216,7 +2216,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui private void Transform(ref uint state, ref byte currentBlock, ref uint w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -2308,7 +2308,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint RotateRight(uint a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (32 - b)); @@ -2540,7 +2540,7 @@ private static uint Maj(uint x, uint y, uint z) 242, 120, 113, 198 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 // 3, 2, 1, 0, 7, 6, 5, 4, // 11, 10, 9, 8, 15, 14, 13, 12, // 19, 18, 17, 16, 23, 22, 21, 20, diff --git a/perf/Sandbox/Sha512Benchmarks.cs b/perf/Sandbox/Sha512Benchmarks.cs index 41931eb7..0610a4aa 100644 --- a/perf/Sandbox/Sha512Benchmarks.cs +++ b/perf/Sandbox/Sha512Benchmarks.cs @@ -129,7 +129,7 @@ public class Sha512_ROS_Partial3 : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -204,7 +204,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha512BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - 4 * Sha512BlockSize + 1); @@ -256,7 +256,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { Unsafe.WriteUnaligned(ref destinationRef, Avx2.Shuffle(Unsafe.ReadUnaligned>(ref Unsafe.As(ref stateRef)), _littleEndianMask256)); @@ -283,7 +283,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 internal static Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -429,7 +429,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -527,7 +527,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -641,7 +641,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 23, 88, 71, 74, 140, 25, 68, 108 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(int i) => Vector256.Create(Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetReference(K)), i)); @@ -685,7 +685,7 @@ public class Sha512_ROS : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -760,7 +760,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha512BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - 4 * Sha512BlockSize + 1); @@ -812,7 +812,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { var littleEndianMask = EndiannessMask256UInt64; @@ -841,7 +841,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 private static readonly Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -989,7 +989,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -1089,7 +1089,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -1203,7 +1203,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 23, 88, 71, 74, 140, 25, 68, 108 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(int i) => Vector256.Create(Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetReference(K)), i)); @@ -1229,7 +1229,7 @@ public class Sha512_ROS_IntPtr_Unroll : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -1304,7 +1304,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - Sha512BlockSize + 1)); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - 4 * Sha512BlockSize + 1)); @@ -1356,7 +1356,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { var littleEndianMask = EndiannessMask256UInt64; @@ -1385,7 +1385,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 private static readonly Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -1584,7 +1584,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -1688,7 +1688,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -1802,7 +1802,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 23, 88, 71, 74, 140, 25, 68, 108 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(IntPtr i) => Vector256.Create(Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetReference(K)), i)); @@ -1828,7 +1828,7 @@ public class Sha512_ROS_IntPtr : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -1903,7 +1903,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - Sha512BlockSize + 1)); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - 4 * Sha512BlockSize + 1)); @@ -1955,7 +1955,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { var littleEndianMask = EndiannessMask256UInt64; @@ -1984,7 +1984,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 private static readonly Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -2153,7 +2153,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -2257,7 +2257,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -2371,7 +2371,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 23, 88, 71, 74, 140, 25, 68, 108 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(IntPtr i) => Vector256.Create(Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetReference(K)), i)); @@ -2397,7 +2397,7 @@ public class Sha512_IntPtr : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -2472,7 +2472,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - Sha512BlockSize + 1)); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - 4 * Sha512BlockSize + 1)); @@ -2524,7 +2524,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { Unsafe.WriteUnaligned(ref destinationRef, Avx2.Shuffle(Unsafe.ReadUnaligned>(ref Unsafe.As(ref stateRef)), _littleEndianMask256)); @@ -2551,7 +2551,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 internal static Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -2698,7 +2698,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -2800,7 +2800,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -2853,7 +2853,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(IntPtr i) => Unsafe.Add(ref _k256[0], i); @@ -2920,7 +2920,7 @@ public class Sha512_PartialROS2 : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -2995,7 +2995,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha512BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - 4 * Sha512BlockSize + 1); @@ -3047,7 +3047,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { var littleEndianMask = EndiannessMask256UInt64; @@ -3076,7 +3076,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 internal static Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -3223,7 +3223,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -3323,7 +3323,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -3437,7 +3437,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 23, 88, 71, 74, 140, 25, 68, 108 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(int i) => Unsafe.Add(ref _k256[0], i); @@ -3486,7 +3486,7 @@ public class Sha512_PartialROS : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -3561,7 +3561,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha512BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - 4 * Sha512BlockSize + 1); @@ -3613,7 +3613,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { var littleEndianMask = EndiannessMask256UInt64; @@ -3642,7 +3642,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 private static readonly Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -3790,7 +3790,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -3890,7 +3890,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -4004,7 +4004,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 23, 88, 71, 74, 140, 25, 68, 108 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(int i) => Unsafe.Add(ref _k256[0], i); @@ -4054,7 +4054,7 @@ public class Sha512_Original : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -4129,7 +4129,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha512BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - 4 * Sha512BlockSize + 1); @@ -4181,7 +4181,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { Unsafe.WriteUnaligned(ref destinationRef, Avx2.Shuffle(Unsafe.ReadUnaligned>(ref Unsafe.As(ref stateRef)), _littleEndianMask256)); @@ -4208,7 +4208,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 internal static Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -4354,7 +4354,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -4452,7 +4452,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -4505,7 +4505,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_1 +#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(int i) => Unsafe.Add(ref _k256[0], i); diff --git a/src/JsonWebToken/Internal/DoesNotReturnAttribute.cs b/src/JsonWebToken/Internal/DoesNotReturnAttribute.cs index 205e3338..330876cf 100644 --- a/src/JsonWebToken/Internal/DoesNotReturnAttribute.cs +++ b/src/JsonWebToken/Internal/DoesNotReturnAttribute.cs @@ -1,7 +1,7 @@ // Copyright (c) 2020 Yann Crumeyrolle. All rights reserved. // Licensed under the MIT license. See LICENSE in the project root for license information. -#if NETSTANDARD2_0 || NET461 || NET47 || NETCOREAPP2_1 +#if NETSTANDARD2_0 || NET461 || NET47 || NETCOREAPP2_2 namespace System.Diagnostics.CodeAnalysis { /// Applied to a method that will never return under any circumstance. diff --git a/src/JsonWebToken/Internal/MemberNotNullAttribute.cs b/src/JsonWebToken/Internal/MemberNotNullAttribute.cs index 8554c539..93a1cd33 100644 --- a/src/JsonWebToken/Internal/MemberNotNullAttribute.cs +++ b/src/JsonWebToken/Internal/MemberNotNullAttribute.cs @@ -1,7 +1,7 @@ // Copyright (c) 2020 Yann Crumeyrolle. All rights reserved. // Licensed under the MIT license. See LICENSE in the project root for license information. -#if NETSTANDARD2_0 || NET461 || NET47 || NETCOREAPP2_1 || NETCOREAPP3_1 +#if NETSTANDARD2_0 || NET461 || NET47 || NETCOREAPP2_2 || NETCOREAPP3_1 namespace System.Diagnostics.CodeAnalysis { /// Specifies that the method or property will ensure that the listed field and property members have values that aren't null. diff --git a/src/JsonWebToken/Internal/NotNullWhenAttribute.cs b/src/JsonWebToken/Internal/NotNullWhenAttribute.cs index 041485d8..3ca257ad 100644 --- a/src/JsonWebToken/Internal/NotNullWhenAttribute.cs +++ b/src/JsonWebToken/Internal/NotNullWhenAttribute.cs @@ -1,7 +1,7 @@ // Copyright (c) 2020 Yann Crumeyrolle. All rights reserved. // Licensed under the MIT license. See LICENSE in the project root for license information. -#if NETSTANDARD2_0 || NET461 || NET47 || NETCOREAPP2_1 +#if NETSTANDARD2_0 || NET461 || NET47 || NETCOREAPP2_2 namespace System.Diagnostics.CodeAnalysis { /// Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it. diff --git a/src/JsonWebToken/JsonWebToken.csproj b/src/JsonWebToken/JsonWebToken.csproj index 4fe852ea..3ac3cc5e 100644 --- a/src/JsonWebToken/JsonWebToken.csproj +++ b/src/JsonWebToken/JsonWebToken.csproj @@ -1,87 +1,87 @@  - - net5.0;ne6.0;netstandard2.0;netcoreapp2.2;netcoreapp3.1 - $(TargetFrameworks);net461;net47 - 9.0 - enable - true - true - true - ../../jwt.snk - 3021;IDE0057 - + + net5.0;net6.0;net7.0;net8.0;netstandard2.0;netcoreapp2.2;netcoreapp3.1 + $(TargetFrameworks);net461;net47 + 12.0 + enable + true + true + true + ../../jwt.snk + 3021;IDE0057 + - - jwt security jsonwebtoken cryptography - High-performance JWT library. Provides Json Web Token primitives. - $(OutputPath)JsonWebToken.xml - + + jwt security jsonwebtoken cryptography + High-performance JWT library. Provides Json Web Token primitives. + $(OutputPath)JsonWebToken.xml + - - full - true - + + full + true + - - + + - - - + + + - - - - false - Analyzer - - + + + + false + Analyzer + + - - - - - - - - + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - $(DefineConstants);SUPPORT_JAVASCRIPT_ENCODER - CS8601;CS8602;CS8604;CS8618 - - - $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING - $(DefineConstants);SUPPORT_JAVASCRIPT_ENCODER - CS8601;CS8602;CS8604;CS8618 - - - $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE - CS8601;CS8602;CS8604;CS8618 - - - $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING - $(DefineConstants);SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_SPAN_STREAM - CS8601;CS8602;CS8604;CS8618 - - - $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD - $(DefineConstants);SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_RUNE;SUPPORT_SPAN_STREAM - - - $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD - $(DefineConstants);SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_RUNE;SUPPORT_SPAN_STREAM;SUPPORT_SKIPLOCALINIT - - - $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD - $(DefineConstants);SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_RUNE;SUPPORT_SPAN_STREAM;SUPPORT_SKIPLOCALINIT - + + $(DefineConstants);SUPPORT_JAVASCRIPT_ENCODER + CS8601;CS8602;CS8604;CS8618 + + + $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING + $(DefineConstants);SUPPORT_JAVASCRIPT_ENCODER + CS8601;CS8602;CS8604;CS8618 + + + $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE + CS8601;CS8602;CS8604;CS8618 + + + $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING + $(DefineConstants);SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_SPAN_STREAM + CS8601;CS8602;CS8604;CS8618 + + + $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD + $(DefineConstants);SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_RUNE;SUPPORT_SPAN_STREAM + + + $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD + $(DefineConstants);SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_RUNE;SUPPORT_SPAN_STREAM;SUPPORT_SKIPLOCALINIT + + + $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD + $(DefineConstants);SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_RUNE;SUPPORT_SPAN_STREAM;SUPPORT_SKIPLOCALINIT + + + $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD + $(DefineConstants);SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_RUNE;SUPPORT_SPAN_STREAM;SUPPORT_SKIPLOCALINIT + + + $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD + $(DefineConstants);SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_RUNE;SUPPORT_SPAN_STREAM;SUPPORT_SKIPLOCALINIT + diff --git a/src/KeyVault/JsonWebToken.KeyVault.csproj b/src/KeyVault/JsonWebToken.KeyVault.csproj index 98483feb..a11b4bc4 100644 --- a/src/KeyVault/JsonWebToken.KeyVault.csproj +++ b/src/KeyVault/JsonWebToken.KeyVault.csproj @@ -1,7 +1,7 @@  - net5.0;netstandard2.0;netcoreapp2.1;netcoreapp3.1 + net5.0;netstandard2.0;netcoreapp2.2;netcoreapp3.1 $(TargetFrameworks);net461;net47 9.0 enable diff --git a/src/OAuth2/JsonWebToken.OAuth2.csproj b/src/OAuth2/JsonWebToken.OAuth2.csproj index 313b60a8..07aff1bb 100644 --- a/src/OAuth2/JsonWebToken.OAuth2.csproj +++ b/src/OAuth2/JsonWebToken.OAuth2.csproj @@ -1,7 +1,7 @@  - net5.0;netstandard2.0;netcoreapp2.1;netcoreapp3.1 + net5.0;netstandard2.0;netcoreapp2.2;netcoreapp3.1 $(TargetFrameworks);net461;net47 9.0 enable diff --git a/src/SecurityEventTokens/JsonWebToken.SecurityEventTokens.csproj b/src/SecurityEventTokens/JsonWebToken.SecurityEventTokens.csproj index 6af2facf..98b7e5e3 100644 --- a/src/SecurityEventTokens/JsonWebToken.SecurityEventTokens.csproj +++ b/src/SecurityEventTokens/JsonWebToken.SecurityEventTokens.csproj @@ -1,7 +1,7 @@  - net5.0;netstandard2.0;netcoreapp2.1;netcoreapp3.1 + net5.0;netstandard2.0;netcoreapp2.2;netcoreapp3.1 $(TargetFrameworks);net461;net47 9.0 enable diff --git a/test/JsonWebToken.OAuth2.Tests/JsonWebToken.OAuth2.Tests.csproj b/test/JsonWebToken.OAuth2.Tests/JsonWebToken.OAuth2.Tests.csproj index c5088c0b..409a70b8 100644 --- a/test/JsonWebToken.OAuth2.Tests/JsonWebToken.OAuth2.Tests.csproj +++ b/test/JsonWebToken.OAuth2.Tests/JsonWebToken.OAuth2.Tests.csproj @@ -2,7 +2,7 @@ net5.0;netcoreapp3.1 - $(TargetFrameworks);netcoreapp2.1;net461;net47 + $(TargetFrameworks);netcoreapp2.2;net461;net47 9.0 false diff --git a/test/JsonWebToken.SecurityEventTokens.Tests/JsonWebToken.SecurityEventTokens.Tests.csproj b/test/JsonWebToken.SecurityEventTokens.Tests/JsonWebToken.SecurityEventTokens.Tests.csproj index ddf9aa8e..00e761e8 100644 --- a/test/JsonWebToken.SecurityEventTokens.Tests/JsonWebToken.SecurityEventTokens.Tests.csproj +++ b/test/JsonWebToken.SecurityEventTokens.Tests/JsonWebToken.SecurityEventTokens.Tests.csproj @@ -2,7 +2,7 @@ net5.0;netcoreapp3.1 - $(TargetFrameworks);netcoreapp2.1;net461;net47 + $(TargetFrameworks);netcoreapp2.2;net461;net47 9.0 false diff --git a/test/JsonWebToken.Tests.Common/JsonWebToken.Tests.Common.csproj b/test/JsonWebToken.Tests.Common/JsonWebToken.Tests.Common.csproj index ec0cad56..e06f20a9 100644 --- a/test/JsonWebToken.Tests.Common/JsonWebToken.Tests.Common.csproj +++ b/test/JsonWebToken.Tests.Common/JsonWebToken.Tests.Common.csproj @@ -2,7 +2,7 @@ net5.0;netcoreapp3.1 - $(TargetFrameworks);netcoreapp2.1;net461;net47 + $(TargetFrameworks);netcoreapp2.2;net461;net47 9.0 true diff --git a/test/JsonWebToken.Tests/DescriptorTests.cs b/test/JsonWebToken.Tests/DescriptorTests.cs index 2402f102..e378a0b9 100644 --- a/test/JsonWebToken.Tests/DescriptorTests.cs +++ b/test/JsonWebToken.Tests/DescriptorTests.cs @@ -34,7 +34,7 @@ public void ValueType() writer.Flush(); var json = Encoding.UTF8.GetString(stream.ToArray()); string expected = "{\"long\":9223372036854775807,\"ulong\":18446744073709551615,\"int\":2147483647,\"uint\":4294967295,\"short\":32767,\"ushort\":65535,\"sbyte\":127,\"byte\":255,\"float\":3.4028235E+38,\"double\":1.7976931348623157E+308,\"true\":true,\"false\":false}"; -#if NETCOREAPP2_1 || NET46_OR_GREATER +#if NETCOREAPP2_2 || NET46_OR_GREATER expected = expected.Replace("\"float\":3.40282347E+38", "\"float\":3.4028235E+38"); #else Assert.Equal(expected, json); diff --git a/test/JsonWebToken.Tests/JsonWebToken.Tests.csproj b/test/JsonWebToken.Tests/JsonWebToken.Tests.csproj index 83f1bb71..7a0642fa 100644 --- a/test/JsonWebToken.Tests/JsonWebToken.Tests.csproj +++ b/test/JsonWebToken.Tests/JsonWebToken.Tests.csproj @@ -1,7 +1,7 @@  net5.0;netcoreapp3.1 - $(TargetFrameworks);netcoreapp2.1;net461;net47 + $(TargetFrameworks);netcoreapp2.2;net461;net47 false false @@ -54,7 +54,7 @@ $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE - + $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO diff --git a/test/JsonWebToken.Tests/JwtMemberTests.cs b/test/JsonWebToken.Tests/JwtMemberTests.cs index 4b6c2742..97a49491 100644 --- a/test/JsonWebToken.Tests/JwtMemberTests.cs +++ b/test/JsonWebToken.Tests/JwtMemberTests.cs @@ -160,7 +160,7 @@ public static IEnumerable GetPropertiesToWrite() yield return new object[] { new JwtMember(JsonEncodedText.Encode("int32"), 1), "{\"int32\":1}" }; yield return new object[] { new JwtMember(JsonEncodedText.Encode("int16"), (short)1), "{\"int16\":1}" }; yield return new object[] { new JwtMember(JsonEncodedText.Encode("int8"), (byte)1), "{\"int8\":1}" }; -#if NETCOREAPP2_1 || NETFRAMEWORK || NETSTANDARD +#if NETCOREAPP2_2 || NETFRAMEWORK || NETSTANDARD yield return new object[] { new JwtMember(JsonEncodedText.Encode("float"), 1.0f), "{\"float\":1}" }; yield return new object[] { new JwtMember(JsonEncodedText.Encode("float"), 1.1f), "{\"float\":" + ((double)1.1f).ToString("G9", CultureInfo.InvariantCulture) + "}" }; yield return new object[] { new JwtMember(JsonEncodedText.Encode("double"), 1.0d), "{\"double\":1}" }; From be2b43ba09ba4f5d48dd672b6beeb882ae3bb25d Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Wed, 24 Apr 2024 00:36:34 +0200 Subject: [PATCH 05/34] Remove support of netcoreapp and net5, add support of net7 and net8 --- src/JsonWebToken/Cryptography/Aes128EncryptionKeys.cs | 2 +- src/JsonWebToken/Cryptography/HmacHelper.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/JsonWebToken/Cryptography/Aes128EncryptionKeys.cs b/src/JsonWebToken/Cryptography/Aes128EncryptionKeys.cs index 0766833b..c5c908c3 100644 --- a/src/JsonWebToken/Cryptography/Aes128EncryptionKeys.cs +++ b/src/JsonWebToken/Cryptography/Aes128EncryptionKeys.cs @@ -59,7 +59,7 @@ private static Vector128 KeyGenAssist(Vector128 key, byte control) public void Clear() { - ref byte that = ref Unsafe.As(ref Unsafe.AsRef(this)); + ref byte that = ref Unsafe.As(ref Unsafe.AsRef(ref this)); Unsafe.InitBlock(ref that, 0, Count * 16); } } diff --git a/src/JsonWebToken/Cryptography/HmacHelper.cs b/src/JsonWebToken/Cryptography/HmacHelper.cs index 144c3fa7..cbe0de67 100644 --- a/src/JsonWebToken/Cryptography/HmacHelper.cs +++ b/src/JsonWebToken/Cryptography/HmacHelper.cs @@ -28,7 +28,7 @@ public static void InitializeIOKeys(ReadOnlySpan key, Span keys, int { ref byte keyRef = ref MemoryMarshal.GetReference(key); ref byte keyEndRef = ref Unsafe.Add(ref keyRef, key.Length); - ref byte innerKeyRef = ref Unsafe.AsRef(keys[0]); + ref byte innerKeyRef = ref Unsafe.AsRef(in keys[0]); ref byte outerKeyRef = ref Unsafe.Add(ref innerKeyRef, blockSize); ref byte innerKeyEndRef = ref outerKeyRef; while (Unsafe.IsAddressLessThan(ref keyRef, ref keyEndRef)) From a27343c99218f32123aae35379dd0847adb2f195 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 17:18:11 +0200 Subject: [PATCH 06/34] fix support for net7 & net8 --- perf/Benchmarks/Benchmarks.csproj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/perf/Benchmarks/Benchmarks.csproj b/perf/Benchmarks/Benchmarks.csproj index 81d7d2f2..2fa14f62 100644 --- a/perf/Benchmarks/Benchmarks.csproj +++ b/perf/Benchmarks/Benchmarks.csproj @@ -37,8 +37,7 @@ - - + From a4b440d4f6cc4158f533f99c2826a11bd526ee86 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 17:23:03 +0200 Subject: [PATCH 07/34] net8 --- fuzz/FuzzTest/FuzzTest.csproj | 2 +- perf/Benchmarks/Benchmarks.csproj | 99 ++++++++++--------- perf/Sandbox/Sandbox.csproj | 19 ++-- perf/ValidatePerf/ValidatePerf.csproj | 2 +- .../BinaryJwtCreationSample.csproj | 18 ++-- .../JweCreationSample.csproj | 18 ++-- .../JweValidationSample.csproj | 18 ++-- .../JwkEncryptionSample.csproj | 18 ++-- samples/JwkSample/JwkSample.csproj | 50 +++++----- .../JwsCreationSample.csproj | 18 ++-- .../JwsValidationSample.csproj | 18 ++-- .../MultiIssuersValidationSample.csproj | 2 +- .../PlaintextJwtCreationSample.csproj | 18 ++-- .../SecEventCreationSample.csproj | 12 +-- .../UnsecureJwtCreationSample.csproj | 18 ++-- .../Cryptography/Aes128CbcDecryptor.cs | 5 +- .../Cryptography/Aes128DecryptionKeys.cs | 5 +- .../Cryptography/Aes128EncryptionKeys.cs | 5 +- .../Cryptography/Aes192DecryptionKeys.cs | 7 +- .../Cryptography/Aes192EncryptionKeys.cs | 2 +- .../Cryptography/Aes256DecryptionKeys.cs | 5 +- .../Cryptography/Aes256EncryptionKeys.cs | 5 +- .../Cryptography/AesGcmDecryptor.cs | 11 ++- .../Cryptography/AesGcmEncryptor.cs | 10 +- .../Cryptography/AesGcmKeyWrapper.cs | 31 +++--- src/JsonWebToken/Cryptography/HmacHelper.cs | 2 +- .../Internal/ConstantExpectedAttribute.cs | 18 ++++ src/JsonWebToken/Internal/StreamExtensions.cs | 1 + src/JsonWebToken/JsonWebToken.csproj | 35 +++---- src/JsonWebToken/Reader/Decompressor`1.cs | 4 - src/JsonWebToken/Reader/JsonMetadata.cs | 16 +++ src/JsonWebToken/Writer/Compressor`1.cs | 7 +- src/JsonWebToken/Writer/DeflateCompressor.cs | 2 +- src/KeyVault/JsonWebToken.KeyVault.csproj | 2 +- src/OAuth2/JsonWebToken.OAuth2.csproj | 2 +- .../JsonWebToken.SecurityEventTokens.csproj | 2 +- .../JsonWebToken.Analyzers.Tests.csproj | 2 +- .../JsonWebToken.OAuth2.Tests.csproj | 4 +- ...nWebToken.SecurityEventTokens.Tests.csproj | 4 +- .../JsonWebToken.Tests.Common.csproj | 4 +- .../DeflateCompressorTests.cs | 27 +++++ .../JsonWebToken.Tests.csproj | 6 +- test/JsonWebToken.Tests/JwksTests.cs | 20 ++-- .../KeyWrapper_EcdhKeyWrapperTests.cs | 2 +- 44 files changed, 328 insertions(+), 248 deletions(-) create mode 100644 src/JsonWebToken/Internal/ConstantExpectedAttribute.cs create mode 100644 test/JsonWebToken.Tests/DeflateCompressorTests.cs diff --git a/fuzz/FuzzTest/FuzzTest.csproj b/fuzz/FuzzTest/FuzzTest.csproj index e8c66a76..d44b57cd 100644 --- a/fuzz/FuzzTest/FuzzTest.csproj +++ b/fuzz/FuzzTest/FuzzTest.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net8.0 false false diff --git a/perf/Benchmarks/Benchmarks.csproj b/perf/Benchmarks/Benchmarks.csproj index 2fa14f62..eec6318f 100644 --- a/perf/Benchmarks/Benchmarks.csproj +++ b/perf/Benchmarks/Benchmarks.csproj @@ -1,56 +1,61 @@  - - netcoreapp3.1;net5 - false - false - + + net6.0;net7.0;net8.0 + false + false + - - true - Exe - false - AnyCPU - 9.0 - enable - true - ../../jwt.snk - false - pdbonly - true - + + true + Exe + false + AnyCPU + 9.0 + enable + true + ../../jwt.snk + false + pdbonly + true + - - 1701;1702;8002 - + + 1701;1702;8002 + - - - - - - - - - - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - - + + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + diff --git a/perf/Sandbox/Sandbox.csproj b/perf/Sandbox/Sandbox.csproj index cbbd5286..ef6a6cd3 100644 --- a/perf/Sandbox/Sandbox.csproj +++ b/perf/Sandbox/Sandbox.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1;net5 + net6.0;net7.0;net8.0 false false @@ -34,13 +34,18 @@ - - - - - - + + + + + + + + + + + diff --git a/perf/ValidatePerf/ValidatePerf.csproj b/perf/ValidatePerf/ValidatePerf.csproj index e5781459..ed2c5dd8 100644 --- a/perf/ValidatePerf/ValidatePerf.csproj +++ b/perf/ValidatePerf/ValidatePerf.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net8.0 false false true diff --git a/samples/BinaryJwtCreationSample/BinaryJwtCreationSample.csproj b/samples/BinaryJwtCreationSample/BinaryJwtCreationSample.csproj index 67567d7b..7cbb75ad 100644 --- a/samples/BinaryJwtCreationSample/BinaryJwtCreationSample.csproj +++ b/samples/BinaryJwtCreationSample/BinaryJwtCreationSample.csproj @@ -1,14 +1,14 @@  - - Exe - net5.0 - false - false - + + Exe + net8.0 + false + false + - - - + + + diff --git a/samples/JweCreationSample/JweCreationSample.csproj b/samples/JweCreationSample/JweCreationSample.csproj index 67567d7b..7cbb75ad 100644 --- a/samples/JweCreationSample/JweCreationSample.csproj +++ b/samples/JweCreationSample/JweCreationSample.csproj @@ -1,14 +1,14 @@  - - Exe - net5.0 - false - false - + + Exe + net8.0 + false + false + - - - + + + diff --git a/samples/JweValidationSample/JweValidationSample.csproj b/samples/JweValidationSample/JweValidationSample.csproj index 67567d7b..7cbb75ad 100644 --- a/samples/JweValidationSample/JweValidationSample.csproj +++ b/samples/JweValidationSample/JweValidationSample.csproj @@ -1,14 +1,14 @@  - - Exe - net5.0 - false - false - + + Exe + net8.0 + false + false + - - - + + + diff --git a/samples/JwkEncryptionSample/JwkEncryptionSample.csproj b/samples/JwkEncryptionSample/JwkEncryptionSample.csproj index 67567d7b..7cbb75ad 100644 --- a/samples/JwkEncryptionSample/JwkEncryptionSample.csproj +++ b/samples/JwkEncryptionSample/JwkEncryptionSample.csproj @@ -1,14 +1,14 @@  - - Exe - net5.0 - false - false - + + Exe + net8.0 + false + false + - - - + + + diff --git a/samples/JwkSample/JwkSample.csproj b/samples/JwkSample/JwkSample.csproj index cf9a952c..72dd954f 100644 --- a/samples/JwkSample/JwkSample.csproj +++ b/samples/JwkSample/JwkSample.csproj @@ -1,32 +1,32 @@  - - Exe - net5.0 - false - false - + + Exe + net8.0 + false + false + - - - - - + + + + + - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + - - - + + + diff --git a/samples/JwsCreationSample/JwsCreationSample.csproj b/samples/JwsCreationSample/JwsCreationSample.csproj index 67567d7b..7cbb75ad 100644 --- a/samples/JwsCreationSample/JwsCreationSample.csproj +++ b/samples/JwsCreationSample/JwsCreationSample.csproj @@ -1,14 +1,14 @@  - - Exe - net5.0 - false - false - + + Exe + net8.0 + false + false + - - - + + + diff --git a/samples/JwsValidationSample/JwsValidationSample.csproj b/samples/JwsValidationSample/JwsValidationSample.csproj index 67567d7b..7cbb75ad 100644 --- a/samples/JwsValidationSample/JwsValidationSample.csproj +++ b/samples/JwsValidationSample/JwsValidationSample.csproj @@ -1,14 +1,14 @@  - - Exe - net5.0 - false - false - + + Exe + net8.0 + false + false + - - - + + + diff --git a/samples/MultiIssuersValidationSample/MultiIssuersValidationSample.csproj b/samples/MultiIssuersValidationSample/MultiIssuersValidationSample.csproj index 8a17153f..0d16b498 100644 --- a/samples/MultiIssuersValidationSample/MultiIssuersValidationSample.csproj +++ b/samples/MultiIssuersValidationSample/MultiIssuersValidationSample.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net8.0 false false diff --git a/samples/PlaintextJwtCreationSample/PlaintextJwtCreationSample.csproj b/samples/PlaintextJwtCreationSample/PlaintextJwtCreationSample.csproj index 67567d7b..7cbb75ad 100644 --- a/samples/PlaintextJwtCreationSample/PlaintextJwtCreationSample.csproj +++ b/samples/PlaintextJwtCreationSample/PlaintextJwtCreationSample.csproj @@ -1,14 +1,14 @@  - - Exe - net5.0 - false - false - + + Exe + net8.0 + false + false + - - - + + + diff --git a/samples/SecEventCreationSample/SecEventCreationSample.csproj b/samples/SecEventCreationSample/SecEventCreationSample.csproj index 27dc445f..909e717b 100644 --- a/samples/SecEventCreationSample/SecEventCreationSample.csproj +++ b/samples/SecEventCreationSample/SecEventCreationSample.csproj @@ -1,11 +1,11 @@  - - Exe - net5.0 - false - false - + + Exe + net8.0 + false + false + diff --git a/samples/UnsecureJwtCreationSample/UnsecureJwtCreationSample.csproj b/samples/UnsecureJwtCreationSample/UnsecureJwtCreationSample.csproj index 67567d7b..7cbb75ad 100644 --- a/samples/UnsecureJwtCreationSample/UnsecureJwtCreationSample.csproj +++ b/samples/UnsecureJwtCreationSample/UnsecureJwtCreationSample.csproj @@ -1,14 +1,14 @@  - - Exe - net5.0 - false - false - + + Exe + net8.0 + false + false + - - - + + + diff --git a/src/JsonWebToken/Cryptography/Aes128CbcDecryptor.cs b/src/JsonWebToken/Cryptography/Aes128CbcDecryptor.cs index 3ee07a15..e15c45be 100644 --- a/src/JsonWebToken/Cryptography/Aes128CbcDecryptor.cs +++ b/src/JsonWebToken/Cryptography/Aes128CbcDecryptor.cs @@ -4,6 +4,7 @@ #if SUPPORT_SIMD using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; @@ -139,7 +140,7 @@ public Aes128DecryptionKeys(ReadOnlySpan key) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static Vector128 KeyGenAssist(Vector128 key, byte control) + private static Vector128 KeyGenAssist(Vector128 key, [ConstantExpected] byte control) { var keyGened = Aes.KeygenAssist(key, control); keyGened = Sse2.Shuffle(keyGened.AsInt32(), 0xFF).AsByte(); @@ -151,7 +152,7 @@ private static Vector128 KeyGenAssist(Vector128 key, byte control) public void Clear() { - ref byte that = ref Unsafe.As(ref Unsafe.AsRef(this)); + ref byte that = ref Unsafe.As(ref Unsafe.AsRef(in this)); Unsafe.InitBlock(ref that, 0, Count * 16); } } diff --git a/src/JsonWebToken/Cryptography/Aes128DecryptionKeys.cs b/src/JsonWebToken/Cryptography/Aes128DecryptionKeys.cs index b1f7f027..a057fe34 100644 --- a/src/JsonWebToken/Cryptography/Aes128DecryptionKeys.cs +++ b/src/JsonWebToken/Cryptography/Aes128DecryptionKeys.cs @@ -4,6 +4,7 @@ #if SUPPORT_SIMD using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; @@ -56,7 +57,7 @@ public Aes128DecryptionKeys(ReadOnlySpan key) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static Vector128 KeyGenAssist(Vector128 key, byte control) + private static Vector128 KeyGenAssist(Vector128 key, [ConstantExpected] byte control) { var keyGened = Aes.KeygenAssist(key, control); keyGened = Sse2.Shuffle(keyGened.AsInt32(), 0xFF).AsByte(); @@ -68,7 +69,7 @@ private static Vector128 KeyGenAssist(Vector128 key, byte control) public void Clear() { - ref byte that = ref Unsafe.As(ref Unsafe.AsRef(this)); + ref byte that = ref Unsafe.As(ref Unsafe.AsRef(in this)); Unsafe.InitBlock(ref that, 0, Count * 16); } } diff --git a/src/JsonWebToken/Cryptography/Aes128EncryptionKeys.cs b/src/JsonWebToken/Cryptography/Aes128EncryptionKeys.cs index c5c908c3..a9b9149b 100644 --- a/src/JsonWebToken/Cryptography/Aes128EncryptionKeys.cs +++ b/src/JsonWebToken/Cryptography/Aes128EncryptionKeys.cs @@ -3,6 +3,7 @@ #if SUPPORT_SIMD using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; @@ -47,7 +48,7 @@ public Aes128EncryptionKeys(ReadOnlySpan key) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static Vector128 KeyGenAssist(Vector128 key, byte control) + private static Vector128 KeyGenAssist(Vector128 key, [ConstantExpected] byte control) { var keyGened = Aes.KeygenAssist(key, control); keyGened = Sse2.Shuffle(keyGened.AsInt32(), 0xFF).AsByte(); @@ -59,7 +60,7 @@ private static Vector128 KeyGenAssist(Vector128 key, byte control) public void Clear() { - ref byte that = ref Unsafe.As(ref Unsafe.AsRef(ref this)); + ref byte that = ref Unsafe.As(ref Unsafe.AsRef(in this)); Unsafe.InitBlock(ref that, 0, Count * 16); } } diff --git a/src/JsonWebToken/Cryptography/Aes192DecryptionKeys.cs b/src/JsonWebToken/Cryptography/Aes192DecryptionKeys.cs index 93d66ac5..cd964667 100644 --- a/src/JsonWebToken/Cryptography/Aes192DecryptionKeys.cs +++ b/src/JsonWebToken/Cryptography/Aes192DecryptionKeys.cs @@ -4,6 +4,7 @@ #if SUPPORT_SIMD using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; @@ -70,16 +71,16 @@ public Aes192DecryptionKeys(ReadOnlySpan key) public void Clear() { - ref byte that = ref Unsafe.As(ref Unsafe.AsRef(this)); + ref byte that = ref Unsafe.As(ref Unsafe.AsRef(in this)); Unsafe.InitBlock(ref that, 0, Count * 16); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static Vector128 Shuffle(Vector128 left, Vector128 right, byte control) + private static Vector128 Shuffle(Vector128 left, Vector128 right, [ConstantExpected] byte control) => Sse2.Shuffle(left.AsDouble(), right.AsDouble(), control).AsByte(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static Vector128 KeyGenAssist(ref Vector128 tmp1, Vector128 tmp3, byte control) + private static Vector128 KeyGenAssist(ref Vector128 tmp1, Vector128 tmp3, [ConstantExpected] byte control) { var keyGened = Aes.KeygenAssist(tmp3, control); keyGened = Aes.Shuffle(keyGened.AsInt32(), 0x55).AsByte(); diff --git a/src/JsonWebToken/Cryptography/Aes192EncryptionKeys.cs b/src/JsonWebToken/Cryptography/Aes192EncryptionKeys.cs index 6b6e70c1..6d4425f0 100644 --- a/src/JsonWebToken/Cryptography/Aes192EncryptionKeys.cs +++ b/src/JsonWebToken/Cryptography/Aes192EncryptionKeys.cs @@ -90,7 +90,7 @@ private static Vector128 KeyGenAssist(ref Vector128 tmp1, Vector128< public void Clear() { - ref byte that = ref Unsafe.As(ref Unsafe.AsRef(this)); + ref byte that = ref Unsafe.As(ref Unsafe.AsRef(in this)); Unsafe.InitBlock(ref that, 0, Count * 16); } } diff --git a/src/JsonWebToken/Cryptography/Aes256DecryptionKeys.cs b/src/JsonWebToken/Cryptography/Aes256DecryptionKeys.cs index f5bd13b1..e43202c8 100644 --- a/src/JsonWebToken/Cryptography/Aes256DecryptionKeys.cs +++ b/src/JsonWebToken/Cryptography/Aes256DecryptionKeys.cs @@ -4,6 +4,7 @@ #if SUPPORT_SIMD using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; @@ -71,7 +72,7 @@ public Aes256DecryptionKeys(ReadOnlySpan key) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void KeyGenAssist1(ref Vector128 tmp1, Vector128 tmp3, byte control) + private static void KeyGenAssist1(ref Vector128 tmp1, Vector128 tmp3, [ConstantExpected] byte control) { var keyGened = Aes.KeygenAssist(tmp3, control); keyGened = Sse2.Shuffle(keyGened.AsInt32(), 0xFF).AsByte(); @@ -94,7 +95,7 @@ private static void KeyGenAssist2(Vector128 tmp1, ref Vector128 tmp3 public void Clear() { - ref byte that = ref Unsafe.As(ref Unsafe.AsRef(this)); + ref byte that = ref Unsafe.As(ref Unsafe.AsRef(in this)); Unsafe.InitBlock(ref that, 0, Count * 16); } } diff --git a/src/JsonWebToken/Cryptography/Aes256EncryptionKeys.cs b/src/JsonWebToken/Cryptography/Aes256EncryptionKeys.cs index d6bbd175..9cfc52f7 100644 --- a/src/JsonWebToken/Cryptography/Aes256EncryptionKeys.cs +++ b/src/JsonWebToken/Cryptography/Aes256EncryptionKeys.cs @@ -3,6 +3,7 @@ #if SUPPORT_SIMD using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; @@ -72,7 +73,7 @@ public Aes256EncryptionKeys(ReadOnlySpan key) [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void KeyGenAssist1(ref Vector128 tmp1, Vector128 tmp3, byte control) + private static void KeyGenAssist1(ref Vector128 tmp1, Vector128 tmp3, [ConstantExpected] byte control) { var keyGened = Aes.KeygenAssist(tmp3, control); keyGened = Sse2.Shuffle(keyGened.AsInt32(), 0xFF).AsByte(); @@ -95,7 +96,7 @@ private static void KeyGenAssist2(Vector128 tmp1, ref Vector128 tmp3 public void Clear() { - ref byte that = ref Unsafe.As(ref Unsafe.AsRef(this)); + ref byte that = ref Unsafe.As(ref Unsafe.AsRef(in this)); Unsafe.InitBlock(ref that, 0, Count * 16); } } diff --git a/src/JsonWebToken/Cryptography/AesGcmDecryptor.cs b/src/JsonWebToken/Cryptography/AesGcmDecryptor.cs index fc3c9904..e1bd3fa5 100644 --- a/src/JsonWebToken/Cryptography/AesGcmDecryptor.cs +++ b/src/JsonWebToken/Cryptography/AesGcmDecryptor.cs @@ -11,6 +11,7 @@ namespace JsonWebToken.Cryptography /// Provides authenticated decryption for AES GCM algorithm. internal sealed class AesGcmDecryptor : AuthenticatedDecryptor { + private const int TagSizeInBytes = 16; private readonly EncryptionAlgorithm _encryptionAlgorithm; public AesGcmDecryptor(EncryptionAlgorithm encryptionAlgorithm) @@ -21,7 +22,7 @@ public AesGcmDecryptor(EncryptionAlgorithm encryptionAlgorithm) } /// - public override int GetTagSize() => 16; + public override int GetTagSize() => TagSizeInBytes; /// public override bool TryDecrypt(ReadOnlySpan key, ReadOnlySpan ciphertext, ReadOnlySpan associatedData, ReadOnlySpan nonce, ReadOnlySpan authenticationTag, Span plaintext, out int bytesWritten) @@ -33,13 +34,17 @@ public override bool TryDecrypt(ReadOnlySpan key, ReadOnlySpan ciphe try { - using var aes = new AesGcm(key); +#if NET8_0_OR_GREATER + using var aesGcm = new AesGcm(key, TagSizeInBytes); +#else + using var aesGcm = new AesGcm(key); +#endif if (plaintext.Length > ciphertext.Length) { plaintext = plaintext.Slice(0, ciphertext.Length); } - aes.Decrypt(nonce, ciphertext, authenticationTag, plaintext, associatedData); + aesGcm.Decrypt(nonce, ciphertext, authenticationTag, plaintext, associatedData); bytesWritten = plaintext.Length; return true; } diff --git a/src/JsonWebToken/Cryptography/AesGcmEncryptor.cs b/src/JsonWebToken/Cryptography/AesGcmEncryptor.cs index 90a9db14..841873b0 100644 --- a/src/JsonWebToken/Cryptography/AesGcmEncryptor.cs +++ b/src/JsonWebToken/Cryptography/AesGcmEncryptor.cs @@ -27,14 +27,18 @@ public override void Encrypt(ReadOnlySpan key, ReadOnlySpan plaintex { ThrowHelper.ThrowArgumentOutOfRangeException_EncryptionKeyTooSmall(_encryptionAlgorithm, _encryptionAlgorithm.RequiredKeySizeInBytes << 3, key.Length << 8); } - - using var aes = new AesGcm(key); + +#if NET8_0_OR_GREATER + using var aesGcm = new AesGcm(key, authenticationTag.Length); +#else + using var aesGcm = new AesGcm(key); +#endif if (ciphertext.Length > plaintext.Length) { ciphertext = ciphertext.Slice(0, plaintext.Length); } - aes.Encrypt(nonce, plaintext, ciphertext, authenticationTag, associatedData); + aesGcm.Encrypt(nonce, plaintext, ciphertext, authenticationTag, associatedData); authenticationTagBytesWritten = authenticationTag.Length; } diff --git a/src/JsonWebToken/Cryptography/AesGcmKeyWrapper.cs b/src/JsonWebToken/Cryptography/AesGcmKeyWrapper.cs index 26cb2663..c2c89763 100644 --- a/src/JsonWebToken/Cryptography/AesGcmKeyWrapper.cs +++ b/src/JsonWebToken/Cryptography/AesGcmKeyWrapper.cs @@ -39,25 +39,26 @@ public override SymmetricJwk WrapKey(Jwk? staticKey, JwtHeader header, Span tag = stackalloc byte[TagSize]; - - using (var aesGcm = new AesGcm(_key.K)) +#if NET8_0_OR_GREATER + using var aesGcm = new AesGcm(_key.K, TagSize); +#else + using var aesGcm = new AesGcm(_key.K); +#endif + var keyBytes = cek.AsSpan(); + if (destination.Length > keyBytes.Length) { - var keyBytes = cek.AsSpan(); - if (destination.Length > keyBytes.Length) - { - destination = destination.Slice(0, keyBytes.Length); - } + destination = destination.Slice(0, keyBytes.Length); + } - aesGcm.Encrypt(nonce, keyBytes, destination, tag); + aesGcm.Encrypt(nonce, keyBytes, destination, tag); - Span nonceB64 = stackalloc byte[IVB64Size]; - Base64Url.Encode(nonce, nonceB64); - header.Add(JwtHeaderParameterNames.IV, Utf8.GetString(nonceB64)); + Span nonceB64 = stackalloc byte[IVB64Size]; + Base64Url.Encode(nonce, nonceB64); + header.Add(JwtHeaderParameterNames.IV, Utf8.GetString(nonceB64)); - Span tagB64 = stackalloc byte[TagB64Size]; - Base64Url.Encode(tag, tagB64); - header.Add(JwtHeaderParameterNames.Tag, Utf8.GetString(tagB64)); - } + Span tagB64 = stackalloc byte[TagB64Size]; + Base64Url.Encode(tag, tagB64); + header.Add(JwtHeaderParameterNames.Tag, Utf8.GetString(tagB64)); return cek; } diff --git a/src/JsonWebToken/Cryptography/HmacHelper.cs b/src/JsonWebToken/Cryptography/HmacHelper.cs index cbe0de67..f88c5c5a 100644 --- a/src/JsonWebToken/Cryptography/HmacHelper.cs +++ b/src/JsonWebToken/Cryptography/HmacHelper.cs @@ -56,7 +56,7 @@ public static void InitializeIOKeys(ReadOnlySpan key, Span keys, int { ref byte keyRef = ref MemoryMarshal.GetReference(key); ref byte keyEndRef = ref Unsafe.Add(ref keyRef, key.Length); - ref byte innerKeyRef = ref Unsafe.AsRef(keys[0]); + ref byte innerKeyRef = ref Unsafe.AsRef(in keys[0]); ref byte outerKeyRef = ref Unsafe.Add(ref innerKeyRef, blockSize); ref byte innerKeyEndRef = ref outerKeyRef; while (Unsafe.IsAddressLessThan(ref keyRef, ref keyEndRef)) diff --git a/src/JsonWebToken/Internal/ConstantExpectedAttribute.cs b/src/JsonWebToken/Internal/ConstantExpectedAttribute.cs new file mode 100644 index 00000000..fb1f5e89 --- /dev/null +++ b/src/JsonWebToken/Internal/ConstantExpectedAttribute.cs @@ -0,0 +1,18 @@ +// Copyright (c) 2020 Yann Crumeyrolle. All rights reserved. +// Licensed under the MIT license. See LICENSE in the project root for license information. + +#if NET5_0 || NET6_0 || NETCOREAPP3_1 +namespace System.Diagnostics.CodeAnalysis +{ + /// Indicates that the specified method parameter expects a constant. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] + public sealed class ConstantExpectedAttribute : Attribute + { + /// Gets or sets the maximum bound of the expected constant, inclusive. + public object? Max { get; set; } + + /// Gets or sets the minimum bound of the expected constant, inclusive. + public object? Min { get; set; } + } +} +#endif \ No newline at end of file diff --git a/src/JsonWebToken/Internal/StreamExtensions.cs b/src/JsonWebToken/Internal/StreamExtensions.cs index 9b5c03c8..68d2b745 100644 --- a/src/JsonWebToken/Internal/StreamExtensions.cs +++ b/src/JsonWebToken/Internal/StreamExtensions.cs @@ -13,6 +13,7 @@ internal static class StreamExtensions public static unsafe void Write(this Stream stream, ReadOnlySpan data) { stream.Write(data.ToArray(), 0, data.Length); + //stream.Flush(); } public static int Read(this Stream stream, Span buffer) diff --git a/src/JsonWebToken/JsonWebToken.csproj b/src/JsonWebToken/JsonWebToken.csproj index 3ac3cc5e..957498f8 100644 --- a/src/JsonWebToken/JsonWebToken.csproj +++ b/src/JsonWebToken/JsonWebToken.csproj @@ -1,7 +1,7 @@  - net5.0;net6.0;net7.0;net8.0;netstandard2.0;netcoreapp2.2;netcoreapp3.1 + net8.0;net6.0;net7.0;netstandard2.0 $(TargetFrameworks);net461;net47 12.0 enable @@ -31,14 +31,14 @@ - false Analyzer - + + @@ -47,17 +47,18 @@ - - - + + - - - - + + + + + + @@ -70,6 +71,7 @@ + @@ -103,19 +105,6 @@ $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE CS8601;CS8602;CS8604;CS8618 - - $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING - $(DefineConstants);SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_SPAN_STREAM - CS8601;CS8602;CS8604;CS8618 - - - $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD - $(DefineConstants);SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_RUNE;SUPPORT_SPAN_STREAM - - - $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD - $(DefineConstants);SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_RUNE;SUPPORT_SPAN_STREAM;SUPPORT_SKIPLOCALINIT - $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD $(DefineConstants);SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO;SUPPORT_RUNE;SUPPORT_SPAN_STREAM;SUPPORT_SKIPLOCALINIT diff --git a/src/JsonWebToken/Reader/Decompressor`1.cs b/src/JsonWebToken/Reader/Decompressor`1.cs index 607633a2..640c398a 100644 --- a/src/JsonWebToken/Reader/Decompressor`1.cs +++ b/src/JsonWebToken/Reader/Decompressor`1.cs @@ -27,10 +27,6 @@ public override unsafe void Decompress(ReadOnlySpan compressedData, IBuffe { uncompressedLength += readData; bufferWritter.Advance(readData); - if (readData < buffer.Length) - { - break; - } buffer = bufferWritter.GetSpan(Constants.DecompressionBufferLength); } diff --git a/src/JsonWebToken/Reader/JsonMetadata.cs b/src/JsonWebToken/Reader/JsonMetadata.cs index a0c23e13..55041bad 100644 --- a/src/JsonWebToken/Reader/JsonMetadata.cs +++ b/src/JsonWebToken/Reader/JsonMetadata.cs @@ -90,7 +90,11 @@ internal void Append(JsonTokenType tokenType, int startLocation, int length) } JsonRow row = new JsonRow(tokenType, startLocation, length); +#if NET8_0_OR_GREATER + MemoryMarshal.Write(_data.AsSpan(Length), in row); +#else MemoryMarshal.Write(_data.AsSpan(Length), ref row); +#endif Length += JsonRow.Size; } @@ -116,7 +120,11 @@ internal void SetLength(int index, int length) AssertValidIndex(index); Debug.Assert(length >= 0); Span destination = _data.AsSpan(index + SizeOrLengthOffset); +#if NET8_0_OR_GREATER + MemoryMarshal.Write(destination, in length); +#else MemoryMarshal.Write(destination, ref length); +#endif } internal void SetNumberOfRows(int index, int numberOfRows) @@ -129,7 +137,11 @@ internal void SetNumberOfRows(int index, int numberOfRows) // Persist the most significant nybble int value = (current & unchecked((int)0xF0000000)) | numberOfRows; +#if NET8_0_OR_GREATER + MemoryMarshal.Write(dataPos, in value); +#else MemoryMarshal.Write(dataPos, ref value); +#endif } internal void SetNeedUnescaping(int index) @@ -141,7 +153,11 @@ internal void SetNeedUnescaping(int index) int current = MemoryMarshal.Read(dataPos); int value = current | unchecked((int)0x80000000); +#if NET8_0_OR_GREATER + MemoryMarshal.Write(dataPos, in value); +#else MemoryMarshal.Write(dataPos, ref value); +#endif } internal JsonRow Get(int index) diff --git a/src/JsonWebToken/Writer/Compressor`1.cs b/src/JsonWebToken/Writer/Compressor`1.cs index daae0039..e13431d8 100644 --- a/src/JsonWebToken/Writer/Compressor`1.cs +++ b/src/JsonWebToken/Writer/Compressor`1.cs @@ -15,18 +15,19 @@ public abstract class Compressor : Compressor where TStream : Stream /// public override unsafe int Compress(ReadOnlySpan ciphertext, Span destination) { - int result; + int compressedBytes; fixed (byte* pinnedCiphertext = destination) { using var outputStream = new UnmanagedMemoryStream(pinnedCiphertext, destination.Length, destination.Length, FileAccess.Write); using var compressionStream = CreateCompressionStream(outputStream); compressionStream.Write(ciphertext); compressionStream.Flush(); - result = (int)outputStream.Length; compressionStream.Close(); + compressedBytes = (int)outputStream.Position + 1; + outputStream.Close(); } - return result; + return compressedBytes; } } } diff --git a/src/JsonWebToken/Writer/DeflateCompressor.cs b/src/JsonWebToken/Writer/DeflateCompressor.cs index 9e89c2df..b2ce3962 100644 --- a/src/JsonWebToken/Writer/DeflateCompressor.cs +++ b/src/JsonWebToken/Writer/DeflateCompressor.cs @@ -10,7 +10,7 @@ internal sealed class DeflateCompressor : Compressor { public override DeflateStream CreateCompressionStream(Stream outputStream) { - return new DeflateStream(outputStream, CompressionLevel.Optimal, false); + return new DeflateStream(outputStream, CompressionLevel.Optimal, true); } } } diff --git a/src/KeyVault/JsonWebToken.KeyVault.csproj b/src/KeyVault/JsonWebToken.KeyVault.csproj index a11b4bc4..4a53ee27 100644 --- a/src/KeyVault/JsonWebToken.KeyVault.csproj +++ b/src/KeyVault/JsonWebToken.KeyVault.csproj @@ -1,7 +1,7 @@  - net5.0;netstandard2.0;netcoreapp2.2;netcoreapp3.1 + net6.0;net7.0;net8.0;netstandard2.0 $(TargetFrameworks);net461;net47 9.0 enable diff --git a/src/OAuth2/JsonWebToken.OAuth2.csproj b/src/OAuth2/JsonWebToken.OAuth2.csproj index 07aff1bb..c559085b 100644 --- a/src/OAuth2/JsonWebToken.OAuth2.csproj +++ b/src/OAuth2/JsonWebToken.OAuth2.csproj @@ -1,7 +1,7 @@  - net5.0;netstandard2.0;netcoreapp2.2;netcoreapp3.1 + net6.0;net7.0;net8.0;netstandard2.0 $(TargetFrameworks);net461;net47 9.0 enable diff --git a/src/SecurityEventTokens/JsonWebToken.SecurityEventTokens.csproj b/src/SecurityEventTokens/JsonWebToken.SecurityEventTokens.csproj index 98b7e5e3..b8be47d0 100644 --- a/src/SecurityEventTokens/JsonWebToken.SecurityEventTokens.csproj +++ b/src/SecurityEventTokens/JsonWebToken.SecurityEventTokens.csproj @@ -1,7 +1,7 @@  - net5.0;netstandard2.0;netcoreapp2.2;netcoreapp3.1 + net6.0;net7.0;net8.0;netstandard2.0 $(TargetFrameworks);net461;net47 9.0 enable diff --git a/test/JsonWebToken.Analyzers.Test/JsonWebToken.Analyzers.Tests.csproj b/test/JsonWebToken.Analyzers.Test/JsonWebToken.Analyzers.Tests.csproj index 32de855e..b3cffe2e 100644 --- a/test/JsonWebToken.Analyzers.Test/JsonWebToken.Analyzers.Tests.csproj +++ b/test/JsonWebToken.Analyzers.Test/JsonWebToken.Analyzers.Tests.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0;net7.0;net8.0 Enable 9.0 diff --git a/test/JsonWebToken.OAuth2.Tests/JsonWebToken.OAuth2.Tests.csproj b/test/JsonWebToken.OAuth2.Tests/JsonWebToken.OAuth2.Tests.csproj index 409a70b8..0ed31dcd 100644 --- a/test/JsonWebToken.OAuth2.Tests/JsonWebToken.OAuth2.Tests.csproj +++ b/test/JsonWebToken.OAuth2.Tests/JsonWebToken.OAuth2.Tests.csproj @@ -1,8 +1,8 @@  - net5.0;netcoreapp3.1 - $(TargetFrameworks);netcoreapp2.2;net461;net47 + net6.0;net7.0;net8.0 + $(TargetFrameworks);net461;net47 9.0 false diff --git a/test/JsonWebToken.SecurityEventTokens.Tests/JsonWebToken.SecurityEventTokens.Tests.csproj b/test/JsonWebToken.SecurityEventTokens.Tests/JsonWebToken.SecurityEventTokens.Tests.csproj index 00e761e8..075c375b 100644 --- a/test/JsonWebToken.SecurityEventTokens.Tests/JsonWebToken.SecurityEventTokens.Tests.csproj +++ b/test/JsonWebToken.SecurityEventTokens.Tests/JsonWebToken.SecurityEventTokens.Tests.csproj @@ -1,8 +1,8 @@  - net5.0;netcoreapp3.1 - $(TargetFrameworks);netcoreapp2.2;net461;net47 + net6.0;net7.0;net8.0 + $(TargetFrameworks);net461;net47 9.0 false diff --git a/test/JsonWebToken.Tests.Common/JsonWebToken.Tests.Common.csproj b/test/JsonWebToken.Tests.Common/JsonWebToken.Tests.Common.csproj index e06f20a9..504a44cc 100644 --- a/test/JsonWebToken.Tests.Common/JsonWebToken.Tests.Common.csproj +++ b/test/JsonWebToken.Tests.Common/JsonWebToken.Tests.Common.csproj @@ -1,8 +1,8 @@  - net5.0;netcoreapp3.1 - $(TargetFrameworks);netcoreapp2.2;net461;net47 + net6.0;net7.0;net8.0 + $(TargetFrameworks);net461;net47 9.0 true diff --git a/test/JsonWebToken.Tests/DeflateCompressorTests.cs b/test/JsonWebToken.Tests/DeflateCompressorTests.cs new file mode 100644 index 00000000..ecbc71cc --- /dev/null +++ b/test/JsonWebToken.Tests/DeflateCompressorTests.cs @@ -0,0 +1,27 @@ +using JsonWebToken.Compression; +using System; +using System.Security.Cryptography; +using Xunit; + +namespace JsonWebToken.Tests +{ + public class DeflateCompressorTests + { + [Theory] + [InlineData(1)] + [InlineData(1024)] + [InlineData(1024 * 1024 * 1)] + public void Compress(int size) + { + var compressor = new DeflateCompressor(); + var data = new byte[size]; + RandomNumberGenerator.Create().GetBytes(data); + var compressedData = new byte[16+size * 2]; + int compressedSize = compressor.Compress(data, compressedData); + using var bw = new PooledByteBufferWriter(); + var decompressor = new DeflateDecompressor(); + decompressor.Decompress(compressedData.AsSpan(0, compressedSize), bw); + Assert.Equal(data.AsSpan().ToArray(), bw.WrittenSpan.ToArray()); + } + } +} diff --git a/test/JsonWebToken.Tests/JsonWebToken.Tests.csproj b/test/JsonWebToken.Tests/JsonWebToken.Tests.csproj index 7a0642fa..eb457034 100644 --- a/test/JsonWebToken.Tests/JsonWebToken.Tests.csproj +++ b/test/JsonWebToken.Tests/JsonWebToken.Tests.csproj @@ -1,7 +1,7 @@  - net5.0;netcoreapp3.1 - $(TargetFrameworks);netcoreapp2.2;net461;net47 + net6.0;net7.0;net8.0 + $(TargetFrameworks);net461;net47 false false @@ -63,7 +63,7 @@ $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD;SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO - + $(DefineConstants);SUPPORT_ELLIPTIC_CURVE;SUPPORT_ELLIPTIC_CURVE_SIGNATURE;SUPPORT_ELLIPTIC_CURVE_KEYWRAPPING;SUPPORT_SIMD;SUPPORT_AESGCM;SUPPORT_JAVASCRIPT_ENCODER;SUPPORT_SPAN_CRYPTO diff --git a/test/JsonWebToken.Tests/JwksTests.cs b/test/JsonWebToken.Tests/JwksTests.cs index 9105f674..86a86cd9 100644 --- a/test/JsonWebToken.Tests/JwksTests.cs +++ b/test/JsonWebToken.Tests/JwksTests.cs @@ -156,6 +156,8 @@ public void ReadJwks_Invalid(string issuer, string json) Assert.ThrowsAny(() => Jwks.FromJson(issuer, json)); } + private object _lock = new object(); + [Fact] public void OnJwksRefreshed() { @@ -178,14 +180,18 @@ public void OnJwksRefreshed() key384, key512 }; - Jwks.OnJwksRefreshed += Jwks_OnJwksRefreshed; - try - { - Jwks.PublishJwksRefreshed(oldJwks, newJwks); - } - finally + + lock (_lock) { - Jwks.OnJwksRefreshed -= Jwks_OnJwksRefreshed; + Jwks.OnJwksRefreshed += Jwks_OnJwksRefreshed; + try + { + Jwks.PublishJwksRefreshed(oldJwks, newJwks); + } + finally + { + Jwks.OnJwksRefreshed -= Jwks_OnJwksRefreshed; + } } } diff --git a/test/JsonWebToken.Tests/KeyWrapper_EcdhKeyWrapperTests.cs b/test/JsonWebToken.Tests/KeyWrapper_EcdhKeyWrapperTests.cs index 8fc58b15..d7181de3 100644 --- a/test/JsonWebToken.Tests/KeyWrapper_EcdhKeyWrapperTests.cs +++ b/test/JsonWebToken.Tests/KeyWrapper_EcdhKeyWrapperTests.cs @@ -1,4 +1,4 @@ -#if NETCOREAPP +#if !NET461 using System; using System.Collections.Generic; using JsonWebToken.Cryptography; From 255dfc5adfc12c5b27ddfb9b6d19d87b023e9a98 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 17:26:42 +0200 Subject: [PATCH 08/34] fix CI for net8 --- .github/workflows/dotnetcore.yml | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index c6ad6787..f1172806 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -44,22 +44,30 @@ jobs: run: | ln -s /usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib /usr/local/lib/libssl.1.1.dylib ln -s /usr/local/opt/openssl@1.1/lib/libcrypto.1.1.dylib /usr/local/lib/libcrypto.1.1.dylib - - name: setup dotnet '2.2.x' - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '2.2.x' - - name: Setup dotnet '3.1.x' + # - name: setup dotnet '2.2.x' + # uses: actions/setup-dotnet@v1 + # with: + # dotnet-version: '2.2.x' + # - name: Setup dotnet '3.1.x' + # uses: actions/setup-dotnet@v1 + # with: + # dotnet-version: '3.1.x' + # - name: Setup dotnet '5.x' + # uses: actions/setup-dotnet@v1 + # with: + # dotnet-version: '5.0.x' + - name: Setup dotnet '6.x' uses: actions/setup-dotnet@v1 with: - dotnet-version: '3.1.x' - - name: Setup dotnet '5.x' + dotnet-version: '6.x' + - name: Setup dotnet '7.x' uses: actions/setup-dotnet@v1 with: - dotnet-version: '5.0.x' - - name: Setup dotnet '6.x' + dotnet-version: '7.x' + - name: Setup dotnet '8.x' uses: actions/setup-dotnet@v1 with: - dotnet-version: '6.0.x' + dotnet-version: '8.x' - name: Restore dependencies run: dotnet restore From c2067782d9e380cc844c07482c201404c0b504ff Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 17:32:01 +0200 Subject: [PATCH 09/34] disable openssl fix for macos --- .github/workflows/dotnetcore.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index f1172806..06d2f433 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -39,11 +39,11 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Setup OpenSSL (macOS) - if: matrix.os == 'macos-latest' - run: | - ln -s /usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib /usr/local/lib/libssl.1.1.dylib - ln -s /usr/local/opt/openssl@1.1/lib/libcrypto.1.1.dylib /usr/local/lib/libcrypto.1.1.dylib + # - name: Setup OpenSSL (macOS) + # if: matrix.os == 'macos-latest' + # run: | + # ln -s /usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib /usr/local/lib/libssl.1.1.dylib + # ln -s /usr/local/opt/openssl@1.1/lib/libcrypto.1.1.dylib /usr/local/lib/libcrypto.1.1.dylib # - name: setup dotnet '2.2.x' # uses: actions/setup-dotnet@v1 # with: From 64b41e19d1138c81cc2097f4f3a64e6f5e343800 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 17:52:32 +0200 Subject: [PATCH 10/34] try fix --- src/JsonWebToken/Cryptography/Pkcs1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonWebToken/Cryptography/Pkcs1.cs b/src/JsonWebToken/Cryptography/Pkcs1.cs index 2346384d..938c8dc4 100644 --- a/src/JsonWebToken/Cryptography/Pkcs1.cs +++ b/src/JsonWebToken/Cryptography/Pkcs1.cs @@ -11,7 +11,7 @@ internal static class Pkcs1 public static ReadOnlySpan PrivatRsaKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'R', 'S', 'A', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #if SUPPORT_ELLIPTIC_CURVE - public static ReadOnlySpan PrivateECKeyPrefix => new[] { '-', '-', '-', '-', '-', 'B', 'E', 'G', 'I', 'N', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; + public static ReadOnlySpan PrivateECKeyPrefix => ['-', '-', '-', '-', '-', 'B', 'E', 'G', 'I', 'N', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-']; public static ReadOnlySpan PrivateECKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #endif From 4a72ad85cd617d08c49fec6cf19f086d32f02f76 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 17:56:56 +0200 Subject: [PATCH 11/34] try fix2 --- src/JsonWebToken/Cryptography/PemParser.cs | 2 +- src/JsonWebToken/Cryptography/Pkcs1.cs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/JsonWebToken/Cryptography/PemParser.cs b/src/JsonWebToken/Cryptography/PemParser.cs index 3537cd52..307171e8 100644 --- a/src/JsonWebToken/Cryptography/PemParser.cs +++ b/src/JsonWebToken/Cryptography/PemParser.cs @@ -29,7 +29,7 @@ public static AsymmetricJwk Read(string key) return Pkcs1.ReadRsaPublicKey(data); } #if SUPPORT_ELLIPTIC_CURVE - if (data.StartsWith(Pkcs1.PrivateECKeyPrefix, StringComparison.Ordinal) && data.EndsWith(Pkcs1.PrivateECKeySuffix, StringComparison.Ordinal)) + if (data.StartsWith(Pkcs1.GetPrivateECKeyPrefix(), StringComparison.Ordinal) && data.EndsWith(Pkcs1.PrivateECKeySuffix, StringComparison.Ordinal)) { return Pkcs1.ReadECPrivateKey(data); } diff --git a/src/JsonWebToken/Cryptography/Pkcs1.cs b/src/JsonWebToken/Cryptography/Pkcs1.cs index 938c8dc4..5a25c2b3 100644 --- a/src/JsonWebToken/Cryptography/Pkcs1.cs +++ b/src/JsonWebToken/Cryptography/Pkcs1.cs @@ -11,7 +11,11 @@ internal static class Pkcs1 public static ReadOnlySpan PrivatRsaKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'R', 'S', 'A', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #if SUPPORT_ELLIPTIC_CURVE - public static ReadOnlySpan PrivateECKeyPrefix => ['-', '-', '-', '-', '-', 'B', 'E', 'G', 'I', 'N', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-']; + public static ReadOnlySpan GetPrivateECKeyPrefix() + { + return ['-', '-', '-', '-', '-', 'B', 'E', 'G', 'I', 'N', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-']; + } + public static ReadOnlySpan PrivateECKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #endif @@ -111,7 +115,7 @@ public static RsaJwk ReadRsaPrivateKey(ReadOnlySpan key) // BIT STRING public key public static ECJwk ReadECPrivateKey(ReadOnlySpan key) { - var data = key.Slice(PrivateECKeyPrefix.Length, key.Length - PrivateECKeyPrefix.Length - PrivateECKeySuffix.Length); + var data = key.Slice(GetPrivateECKeyPrefix().Length, key.Length - GetPrivateECKeyPrefix().Length - PrivateECKeySuffix.Length); byte[] tmpArray; Span keyData = tmpArray = ArrayPool.Shared.Rent(Base64.GetArraySizeRequiredToDecode(data.Length)); try From 995af43ffaa67125d6ccebaef94a02e6048182ba Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 18:33:12 +0200 Subject: [PATCH 12/34] try fix 3 --- src/JsonWebToken/Cryptography/PemParser.cs | 2 +- src/JsonWebToken/Cryptography/Pkcs1.cs | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/JsonWebToken/Cryptography/PemParser.cs b/src/JsonWebToken/Cryptography/PemParser.cs index 307171e8..3537cd52 100644 --- a/src/JsonWebToken/Cryptography/PemParser.cs +++ b/src/JsonWebToken/Cryptography/PemParser.cs @@ -29,7 +29,7 @@ public static AsymmetricJwk Read(string key) return Pkcs1.ReadRsaPublicKey(data); } #if SUPPORT_ELLIPTIC_CURVE - if (data.StartsWith(Pkcs1.GetPrivateECKeyPrefix(), StringComparison.Ordinal) && data.EndsWith(Pkcs1.PrivateECKeySuffix, StringComparison.Ordinal)) + if (data.StartsWith(Pkcs1.PrivateECKeyPrefix, StringComparison.Ordinal) && data.EndsWith(Pkcs1.PrivateECKeySuffix, StringComparison.Ordinal)) { return Pkcs1.ReadECPrivateKey(data); } diff --git a/src/JsonWebToken/Cryptography/Pkcs1.cs b/src/JsonWebToken/Cryptography/Pkcs1.cs index 5a25c2b3..c641772d 100644 --- a/src/JsonWebToken/Cryptography/Pkcs1.cs +++ b/src/JsonWebToken/Cryptography/Pkcs1.cs @@ -11,10 +11,7 @@ internal static class Pkcs1 public static ReadOnlySpan PrivatRsaKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'R', 'S', 'A', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #if SUPPORT_ELLIPTIC_CURVE - public static ReadOnlySpan GetPrivateECKeyPrefix() - { - return ['-', '-', '-', '-', '-', 'B', 'E', 'G', 'I', 'N', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-']; - } + public static ReadOnlySpan PrivateECKeyPrefix => "-----BEGIN EC PRIVATE KEY-----"; public static ReadOnlySpan PrivateECKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #endif @@ -115,7 +112,7 @@ public static RsaJwk ReadRsaPrivateKey(ReadOnlySpan key) // BIT STRING public key public static ECJwk ReadECPrivateKey(ReadOnlySpan key) { - var data = key.Slice(GetPrivateECKeyPrefix().Length, key.Length - GetPrivateECKeyPrefix().Length - PrivateECKeySuffix.Length); + var data = key.Slice(PrivateECKeyPrefix.Length, key.Length - PrivateECKeyPrefix.Length - PrivateECKeySuffix.Length); byte[] tmpArray; Span keyData = tmpArray = ArrayPool.Shared.Rent(Base64.GetArraySizeRequiredToDecode(data.Length)); try From 2ad6f28320f36e49e41d610e8d158216710246b4 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 18:36:22 +0200 Subject: [PATCH 13/34] try fix 4 --- src/JsonWebToken/Cryptography/Pkcs1.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/JsonWebToken/Cryptography/Pkcs1.cs b/src/JsonWebToken/Cryptography/Pkcs1.cs index c641772d..2c5d5b9d 100644 --- a/src/JsonWebToken/Cryptography/Pkcs1.cs +++ b/src/JsonWebToken/Cryptography/Pkcs1.cs @@ -11,8 +11,8 @@ internal static class Pkcs1 public static ReadOnlySpan PrivatRsaKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'R', 'S', 'A', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #if SUPPORT_ELLIPTIC_CURVE - public static ReadOnlySpan PrivateECKeyPrefix => "-----BEGIN EC PRIVATE KEY-----"; - + public static ReadOnlySpan PrivateECKeyPrefix => "-----BEGIN EC PRIVATE KEY-----".AsSpan(); + public static ReadOnlySpan PrivateECKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #endif From 8e52d85790025a1d5b7049ac74030b35e2f97c84 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 18:54:04 +0200 Subject: [PATCH 14/34] try reduce impact of fix --- src/JsonWebToken/Cryptography/Pkcs1.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/JsonWebToken/Cryptography/Pkcs1.cs b/src/JsonWebToken/Cryptography/Pkcs1.cs index 2c5d5b9d..eb94b572 100644 --- a/src/JsonWebToken/Cryptography/Pkcs1.cs +++ b/src/JsonWebToken/Cryptography/Pkcs1.cs @@ -11,8 +11,12 @@ internal static class Pkcs1 public static ReadOnlySpan PrivatRsaKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'R', 'S', 'A', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #if SUPPORT_ELLIPTIC_CURVE +#if NET6_0 public static ReadOnlySpan PrivateECKeyPrefix => "-----BEGIN EC PRIVATE KEY-----".AsSpan(); - +#else + public static ReadOnlySpan PrivateECKeyPrefix => { '-', '-', '-', '-', '-', 'B', 'E', 'G', 'I', 'N', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' };; +#endif + public static ReadOnlySpan PrivateECKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #endif From 91a2dc8494cbb96712e743b19b99e67afce5788a Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 19:44:25 +0200 Subject: [PATCH 15/34] fix --- src/JsonWebToken/Cryptography/Pkcs1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonWebToken/Cryptography/Pkcs1.cs b/src/JsonWebToken/Cryptography/Pkcs1.cs index eb94b572..ce924fc3 100644 --- a/src/JsonWebToken/Cryptography/Pkcs1.cs +++ b/src/JsonWebToken/Cryptography/Pkcs1.cs @@ -14,7 +14,7 @@ internal static class Pkcs1 #if NET6_0 public static ReadOnlySpan PrivateECKeyPrefix => "-----BEGIN EC PRIVATE KEY-----".AsSpan(); #else - public static ReadOnlySpan PrivateECKeyPrefix => { '-', '-', '-', '-', '-', 'B', 'E', 'G', 'I', 'N', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' };; + public static ReadOnlySpan PrivateECKeyPrefix => new[] { '-', '-', '-', '-', '-', 'B', 'E', 'G', 'I', 'N', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #endif public static ReadOnlySpan PrivateECKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; From e06910e4a0ac1ea5a7ed57ca634d6a58f9c97f33 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 19:50:16 +0200 Subject: [PATCH 16/34] update gh actions versions --- .github/workflows/dotnetcore.yml | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 8bf3d98e..ff3a7c61 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -38,7 +38,7 @@ jobs: DYLD_FALLBACK_LIBRARY_PATH: /usr/local/Cellar/openssl@1.1/ steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 # - name: Setup OpenSSL (macOS) # if: matrix.os == 'macos-latest' # run: | @@ -56,18 +56,13 @@ jobs: # uses: actions/setup-dotnet@v1 # with: # dotnet-version: '5.0.x' - - name: Setup dotnet '6.x' - uses: actions/setup-dotnet@v1 + - name: Setup dotnet + uses: actions/setup-dotnet@v4 with: - dotnet-version: '6.x' - - name: Setup dotnet '7.x' - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '7.x' - - name: Setup dotnet '8.x' - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '8.x' + dotnet-version: | + 6.x + 7.x + 8.x - name: Restore dependencies run: dotnet restore From 76b90488c76052a5a581f1b6b3b99c7e5edeede3 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 19:54:17 +0200 Subject: [PATCH 17/34] Fix warnings --- src/JsonWebToken/Cryptography/Aes192EncryptionKeys.cs | 5 +++-- src/JsonWebToken/Cryptography/AesGcmKeyUnwrapper.cs | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/JsonWebToken/Cryptography/Aes192EncryptionKeys.cs b/src/JsonWebToken/Cryptography/Aes192EncryptionKeys.cs index 6d4425f0..d7bd84f1 100644 --- a/src/JsonWebToken/Cryptography/Aes192EncryptionKeys.cs +++ b/src/JsonWebToken/Cryptography/Aes192EncryptionKeys.cs @@ -3,6 +3,7 @@ #if SUPPORT_SIMD using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; @@ -72,11 +73,11 @@ public Aes192EncryptionKeys(ReadOnlySpan key) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static Vector128 Shuffle(Vector128 left, Vector128 right, byte control) + private static Vector128 Shuffle(Vector128 left, Vector128 right, [ConstantExpected] byte control) => Sse2.Shuffle(left.AsDouble(), right.AsDouble(), control).AsByte(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static Vector128 KeyGenAssist(ref Vector128 tmp1, Vector128 tmp3, byte control) + private static Vector128 KeyGenAssist(ref Vector128 tmp1, Vector128 tmp3, [ConstantExpected] byte control) { var keyGened = Aes.KeygenAssist(tmp3, control); keyGened = Sse2.Shuffle(keyGened.AsInt32(), 0x55).AsByte(); diff --git a/src/JsonWebToken/Cryptography/AesGcmKeyUnwrapper.cs b/src/JsonWebToken/Cryptography/AesGcmKeyUnwrapper.cs index 2d5d8866..7b0774bf 100644 --- a/src/JsonWebToken/Cryptography/AesGcmKeyUnwrapper.cs +++ b/src/JsonWebToken/Cryptography/AesGcmKeyUnwrapper.cs @@ -48,7 +48,11 @@ public override bool TryUnwrapKey(ReadOnlySpan keyBytes, Span destin { Base64Url.Decode(rawIV.Span, nonce); Base64Url.Decode(rawTag.Span, tag); +#if NET8_0_OR_GREATER + using var aesGcm = new AesGcm(_key.K, TagSize); +#else using var aesGcm = new AesGcm(_key.K); +#endif if (destination.Length > keyBytes.Length) { destination = destination.Slice(0, keyBytes.Length); From a085094b7e3e6d20641903edc5e6197f404e9558 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 19:55:40 +0200 Subject: [PATCH 18/34] fix --- src/JsonWebToken/Cryptography/Pkcs1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonWebToken/Cryptography/Pkcs1.cs b/src/JsonWebToken/Cryptography/Pkcs1.cs index ce924fc3..8e0a1a01 100644 --- a/src/JsonWebToken/Cryptography/Pkcs1.cs +++ b/src/JsonWebToken/Cryptography/Pkcs1.cs @@ -11,7 +11,7 @@ internal static class Pkcs1 public static ReadOnlySpan PrivatRsaKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'R', 'S', 'A', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #if SUPPORT_ELLIPTIC_CURVE -#if NET6_0 +#if NET7_0 public static ReadOnlySpan PrivateECKeyPrefix => "-----BEGIN EC PRIVATE KEY-----".AsSpan(); #else public static ReadOnlySpan PrivateECKeyPrefix => new[] { '-', '-', '-', '-', '-', 'B', 'E', 'G', 'I', 'N', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; From 8fbd6ea8e84b05a1b8ea6cb5328ffd30f215d2ca Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 19:59:37 +0200 Subject: [PATCH 19/34] fix --- src/JsonWebToken/Cryptography/Pkcs1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonWebToken/Cryptography/Pkcs1.cs b/src/JsonWebToken/Cryptography/Pkcs1.cs index 8e0a1a01..38b2d9db 100644 --- a/src/JsonWebToken/Cryptography/Pkcs1.cs +++ b/src/JsonWebToken/Cryptography/Pkcs1.cs @@ -11,7 +11,7 @@ internal static class Pkcs1 public static ReadOnlySpan PrivatRsaKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'R', 'S', 'A', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #if SUPPORT_ELLIPTIC_CURVE -#if NET7_0 +#if NET6_0 || NET7_0 public static ReadOnlySpan PrivateECKeyPrefix => "-----BEGIN EC PRIVATE KEY-----".AsSpan(); #else public static ReadOnlySpan PrivateECKeyPrefix => new[] { '-', '-', '-', '-', '-', 'B', 'E', 'G', 'I', 'N', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; From c00bde270e22fd7951463e4a82d2a317b6b6e4b1 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 20:05:56 +0200 Subject: [PATCH 20/34] fix --- .github/workflows/dotnetcore.yml | 12 ------------ src/JsonWebToken/Cryptography/Pkcs1.cs | 4 ---- 2 files changed, 16 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index ff3a7c61..1d4b167d 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -44,18 +44,6 @@ jobs: # run: | # ln -s /usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib /usr/local/lib/libssl.1.1.dylib # ln -s /usr/local/opt/openssl@1.1/lib/libcrypto.1.1.dylib /usr/local/lib/libcrypto.1.1.dylib - # - name: setup dotnet '2.2.x' - # uses: actions/setup-dotnet@v1 - # with: - # dotnet-version: '2.2.x' - # - name: Setup dotnet '3.1.x' - # uses: actions/setup-dotnet@v1 - # with: - # dotnet-version: '3.1.x' - # - name: Setup dotnet '5.x' - # uses: actions/setup-dotnet@v1 - # with: - # dotnet-version: '5.0.x' - name: Setup dotnet uses: actions/setup-dotnet@v4 with: diff --git a/src/JsonWebToken/Cryptography/Pkcs1.cs b/src/JsonWebToken/Cryptography/Pkcs1.cs index 38b2d9db..28dae4a0 100644 --- a/src/JsonWebToken/Cryptography/Pkcs1.cs +++ b/src/JsonWebToken/Cryptography/Pkcs1.cs @@ -11,11 +11,7 @@ internal static class Pkcs1 public static ReadOnlySpan PrivatRsaKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'R', 'S', 'A', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #if SUPPORT_ELLIPTIC_CURVE -#if NET6_0 || NET7_0 public static ReadOnlySpan PrivateECKeyPrefix => "-----BEGIN EC PRIVATE KEY-----".AsSpan(); -#else - public static ReadOnlySpan PrivateECKeyPrefix => new[] { '-', '-', '-', '-', '-', 'B', 'E', 'G', 'I', 'N', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; -#endif public static ReadOnlySpan PrivateECKeySuffix => new[] { '-', '-', '-', '-', '-', 'E', 'N', 'D', ' ', 'E', 'C', ' ', 'P', 'R', 'I', 'V', 'A', 'T', 'E', ' ', 'K', 'E', 'Y', '-', '-', '-', '-', '-' }; #endif From 065e74539769bdbb3f802e11ebb041889918a522 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 21:36:52 +0200 Subject: [PATCH 21/34] updates --- perf/Benchmarks/Benchmarks.csproj | 2 +- perf/Sandbox/FixedTimeEqualsBenchmark.cs | 2 +- perf/Sandbox/Sandbox.csproj | 2 +- perf/Sandbox/Sha256Benchmarks.cs | 56 ++++----- perf/Sandbox/Sha512Benchmarks.cs | 112 +++++++++--------- src/JsonWebToken/Base64.cs | 2 +- src/JsonWebToken/Base64Url.cs | 2 +- .../Cryptography/RsaKeyUnwrapper.cs | 2 +- .../Cryptography/RsaKeyWrapper.cs | 2 +- .../Cryptography/RsaObjectPoolPolicy.cs | 2 +- .../Internal/DoesNotReturnAttribute.cs | 2 +- .../Internal/EncodingExtensions.cs | 2 +- .../Internal/MemberNotNullAttribute.cs | 2 +- .../Internal/NotNullWhenAttribute.cs | 2 +- src/JsonWebToken/Internal/OSPlatform.cs | 2 +- .../Internal/RuntimeInformation.cs | 2 +- src/JsonWebToken/Internal/StreamExtensions.cs | 2 +- src/JsonWebToken/JsonWebToken.csproj | 30 ++--- src/JsonWebToken/RsaJwk.cs | 6 +- src/JsonWebToken/SymmetricJwk.cs | 8 +- src/JsonWebToken/Writer/JweDescriptor`1.cs | 4 +- src/KeyVault/JsonWebToken.KeyVault.csproj | 4 +- src/OAuth2/JsonWebToken.OAuth2.csproj | 2 +- .../JsonWebToken.SecurityEventTokens.csproj | 2 +- .../JsonWebToken.OAuth2.Tests.csproj | 6 +- ...nWebToken.SecurityEventTokens.Tests.csproj | 6 +- .../JsonWebToken.Tests.Common.csproj | 8 +- test/JsonWebToken.Tests.Common/KeyFixture.cs | 4 +- .../AlgorithmCompatibilityTests.cs | 2 +- test/JsonWebToken.Tests/ECJwkTests.cs | 2 +- .../JsonWebToken.Tests.csproj | 16 +-- test/JsonWebToken.Tests/JwksTests.cs | 48 ++++---- .../KeyWrapper_EcdhKeyWrapperTests.cs | 2 +- test/JsonWebToken.Tests/RsaJwkTests.cs | 2 +- 34 files changed, 174 insertions(+), 176 deletions(-) diff --git a/perf/Benchmarks/Benchmarks.csproj b/perf/Benchmarks/Benchmarks.csproj index eec6318f..c8988ddf 100644 --- a/perf/Benchmarks/Benchmarks.csproj +++ b/perf/Benchmarks/Benchmarks.csproj @@ -34,7 +34,7 @@ - + diff --git a/perf/Sandbox/FixedTimeEqualsBenchmark.cs b/perf/Sandbox/FixedTimeEqualsBenchmark.cs index 3cbbab31..462849eb 100644 --- a/perf/Sandbox/FixedTimeEqualsBenchmark.cs +++ b/perf/Sandbox/FixedTimeEqualsBenchmark.cs @@ -92,7 +92,7 @@ public override string ToString() private static unsafe bool AreEqual_Current(ref byte first, ref byte second, int l) { IntPtr length = (IntPtr)l; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported && (byte*)length == (byte*)64) { return diff --git a/perf/Sandbox/Sandbox.csproj b/perf/Sandbox/Sandbox.csproj index ef6a6cd3..e2c865d9 100644 --- a/perf/Sandbox/Sandbox.csproj +++ b/perf/Sandbox/Sandbox.csproj @@ -38,7 +38,7 @@ - + diff --git a/perf/Sandbox/Sha256Benchmarks.cs b/perf/Sandbox/Sha256Benchmarks.cs index 8e7d59e3..e9ab3ca2 100644 --- a/perf/Sandbox/Sha256Benchmarks.cs +++ b/perf/Sandbox/Sha256Benchmarks.cs @@ -111,7 +111,7 @@ public sealed class Sha256_Original : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha256BlockSize ? 64 * 16 : 64 * 4; @@ -183,7 +183,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha256BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { ref byte src128EndRef = ref Unsafe.Add(ref srcStartRef, source.Length - 4 * Sha256BlockSize + 1); @@ -230,7 +230,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p Transform(ref stateRef, ref lastBlockRef, ref wRef); ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { Unsafe.WriteUnaligned(ref destinationRef, Avx2.Shuffle(Unsafe.ReadUnaligned>(ref Unsafe.As(ref MemoryMarshal.GetReference(state))), _shuffleMask256)); @@ -254,7 +254,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector128 Gather(ref byte message) { @@ -418,7 +418,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui private void Transform(ref uint state, ref byte currentBlock, ref uint w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -510,7 +510,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint RotateRight(uint a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (32 - b)); @@ -552,7 +552,7 @@ private static uint Maj(uint x, uint y, uint z) 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 // 3, 2, 1, 0, 7, 6, 5, 4, // 11, 10, 9, 8, 15, 14, 13, 12, // 19, 18, 17, 16, 23, 22, 21, 20, @@ -681,7 +681,7 @@ public sealed class Sha256_Original_IntPtr : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha256BlockSize ? 64 * 16 : 64 * 4; @@ -752,7 +752,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha256BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { ref byte src128EndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - 4 * Sha256BlockSize + 1)); @@ -799,7 +799,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p Transform(ref stateRef, ref lastBlockRef, ref wRef); ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { Unsafe.WriteUnaligned(ref destinationRef, Avx2.Shuffle(Unsafe.ReadUnaligned>(ref Unsafe.As(ref MemoryMarshal.GetReference(state))), _shuffleMask256)); @@ -823,7 +823,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector128 Gather(ref byte message) { @@ -1018,7 +1018,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui private void Transform(ref uint state, ref byte currentBlock, ref uint w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -1110,7 +1110,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint RotateRight(uint a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (32 - b)); @@ -1152,7 +1152,7 @@ private static uint Maj(uint x, uint y, uint z) 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 // 3, 2, 1, 0, 7, 6, 5, 4, // 11, 10, 9, 8, 15, 14, 13, 12, // 19, 18, 17, 16, 23, 22, 21, 20, @@ -1280,7 +1280,7 @@ public class Sha256_Original_IntPtr_MaskROS : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha256BlockSize ? 64 * 16 : 64 * 4; @@ -1351,7 +1351,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha256BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { ref byte src128EndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - 4 * Sha256BlockSize + 1)); @@ -1398,7 +1398,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p Transform(ref stateRef, ref lastBlockRef, ref wRef); ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { Unsafe.WriteUnaligned(ref destinationRef, Avx2.Shuffle(Unsafe.ReadUnaligned>(ref Unsafe.As(ref MemoryMarshal.GetReference(state))), _shuffleMask256)); @@ -1422,7 +1422,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector128 Gather(ref byte message) { @@ -1618,7 +1618,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui private void Transform(ref uint state, ref byte currentBlock, ref uint w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -1712,7 +1712,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint RotateRight(uint a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (32 - b)); @@ -1754,7 +1754,7 @@ private static uint Maj(uint x, uint y, uint z) 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector128 K128(IntPtr i) => Unsafe.Add(ref _k128[0], i); @@ -1865,7 +1865,7 @@ public class Sha256_Original_IntPtr_KROS : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha256BlockSize ? 64 * 16 : 64 * 4; @@ -1936,7 +1936,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha256BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { ref byte src128EndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - 4 * Sha256BlockSize + 1)); @@ -1983,7 +1983,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p Transform(ref stateRef, ref lastBlockRef, ref wRef); ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { Unsafe.WriteUnaligned(ref destinationRef, Avx2.Shuffle(Unsafe.ReadUnaligned>(ref Unsafe.As(ref MemoryMarshal.GetReference(state))), _shuffleMask256)); @@ -2007,7 +2007,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector128 Gather(ref byte message) { @@ -2216,7 +2216,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui private void Transform(ref uint state, ref byte currentBlock, ref uint w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -2308,7 +2308,7 @@ private static void Round(uint a, uint b, uint c, ref uint d, uint e, uint f, ui [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint RotateRight(uint a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (32 - b)); @@ -2540,7 +2540,7 @@ private static uint Maj(uint x, uint y, uint z) 242, 120, 113, 198 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 // 3, 2, 1, 0, 7, 6, 5, 4, // 11, 10, 9, 8, 15, 14, 13, 12, // 19, 18, 17, 16, 23, 22, 21, 20, diff --git a/perf/Sandbox/Sha512Benchmarks.cs b/perf/Sandbox/Sha512Benchmarks.cs index 0610a4aa..877a6456 100644 --- a/perf/Sandbox/Sha512Benchmarks.cs +++ b/perf/Sandbox/Sha512Benchmarks.cs @@ -129,7 +129,7 @@ public class Sha512_ROS_Partial3 : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -204,7 +204,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha512BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - 4 * Sha512BlockSize + 1); @@ -256,7 +256,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { Unsafe.WriteUnaligned(ref destinationRef, Avx2.Shuffle(Unsafe.ReadUnaligned>(ref Unsafe.As(ref stateRef)), _littleEndianMask256)); @@ -283,7 +283,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 internal static Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -429,7 +429,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -527,7 +527,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -641,7 +641,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 23, 88, 71, 74, 140, 25, 68, 108 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(int i) => Vector256.Create(Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetReference(K)), i)); @@ -685,7 +685,7 @@ public class Sha512_ROS : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -760,7 +760,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha512BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - 4 * Sha512BlockSize + 1); @@ -812,7 +812,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { var littleEndianMask = EndiannessMask256UInt64; @@ -841,7 +841,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 private static readonly Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -989,7 +989,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -1089,7 +1089,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -1203,7 +1203,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 23, 88, 71, 74, 140, 25, 68, 108 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(int i) => Vector256.Create(Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetReference(K)), i)); @@ -1229,7 +1229,7 @@ public class Sha512_ROS_IntPtr_Unroll : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -1304,7 +1304,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - Sha512BlockSize + 1)); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - 4 * Sha512BlockSize + 1)); @@ -1356,7 +1356,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { var littleEndianMask = EndiannessMask256UInt64; @@ -1385,7 +1385,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 private static readonly Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -1584,7 +1584,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -1688,7 +1688,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -1802,7 +1802,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 23, 88, 71, 74, 140, 25, 68, 108 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(IntPtr i) => Vector256.Create(Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetReference(K)), i)); @@ -1828,7 +1828,7 @@ public class Sha512_ROS_IntPtr : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -1903,7 +1903,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - Sha512BlockSize + 1)); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - 4 * Sha512BlockSize + 1)); @@ -1955,7 +1955,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { var littleEndianMask = EndiannessMask256UInt64; @@ -1984,7 +1984,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 private static readonly Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -2153,7 +2153,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -2257,7 +2257,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -2371,7 +2371,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 23, 88, 71, 74, 140, 25, 68, 108 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(IntPtr i) => Vector256.Create(Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetReference(K)), i)); @@ -2397,7 +2397,7 @@ public class Sha512_IntPtr : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -2472,7 +2472,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - Sha512BlockSize + 1)); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, (IntPtr)(source.Length - 4 * Sha512BlockSize + 1)); @@ -2524,7 +2524,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { Unsafe.WriteUnaligned(ref destinationRef, Avx2.Shuffle(Unsafe.ReadUnaligned>(ref Unsafe.As(ref stateRef)), _littleEndianMask256)); @@ -2551,7 +2551,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 internal static Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -2698,7 +2698,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -2800,7 +2800,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -2853,7 +2853,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(IntPtr i) => Unsafe.Add(ref _k256[0], i); @@ -2920,7 +2920,7 @@ public class Sha512_PartialROS2 : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -2995,7 +2995,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha512BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - 4 * Sha512BlockSize + 1); @@ -3047,7 +3047,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { var littleEndianMask = EndiannessMask256UInt64; @@ -3076,7 +3076,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 internal static Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -3223,7 +3223,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -3323,7 +3323,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -3437,7 +3437,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 23, 88, 71, 74, 140, 25, 68, 108 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(int i) => Unsafe.Add(ref _k256[0], i); @@ -3486,7 +3486,7 @@ public class Sha512_PartialROS : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -3561,7 +3561,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha512BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - 4 * Sha512BlockSize + 1); @@ -3613,7 +3613,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { var littleEndianMask = EndiannessMask256UInt64; @@ -3642,7 +3642,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 private static readonly Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -3790,7 +3790,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -3890,7 +3890,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -4004,7 +4004,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 23, 88, 71, 74, 140, 25, 68, 108 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(int i) => Unsafe.Add(ref _k256[0], i); @@ -4054,7 +4054,7 @@ public class Sha512_Original : Sha2 /// public override int GetWorkingSetSize(int sourceLength) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Ssse3.IsSupported) { return sourceLength >= 4 * Sha512BlockSize ? 80 * 32 : 80 * 8; @@ -4129,7 +4129,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } ref byte srcEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - Sha512BlockSize + 1); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { ref byte srcSimdEndRef = ref Unsafe.Add(ref srcStartRef, source.Length - 4 * Sha512BlockSize + 1); @@ -4181,7 +4181,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p // reverse all the bytes when copying the final state to the output hash. ref byte destinationRef = ref MemoryMarshal.GetReference(destination); -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 if (Avx2.IsSupported) { Unsafe.WriteUnaligned(ref destinationRef, Avx2.Shuffle(Unsafe.ReadUnaligned>(ref Unsafe.As(ref stateRef)), _littleEndianMask256)); @@ -4208,7 +4208,7 @@ public override void ComputeHash(ReadOnlySpan source, ReadOnlySpan p } } -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 internal static Vector256 GatherMask = Vector256.Create(0L, 16, 32, 48); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -4354,7 +4354,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong internal static void Transform(ref ulong state, ref byte currentBlock, ref ulong w) { -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 ref byte wRef = ref Unsafe.As(ref w); if (Avx2.IsSupported) { @@ -4452,7 +4452,7 @@ private static void Round(ulong a, ulong b, ulong c, ref ulong d, ulong e, ulong [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateRight(ulong a, byte b) -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 => BitOperations.RotateRight(a, b); #else => (a >> b) | (a << (64 - b)); @@ -4505,7 +4505,7 @@ private static ulong Maj(ulong x, ulong y, ulong z) 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 }; -#if !NETSTANDARD2_0 && !NET461 && !NET47 && !NETCOREAPP2_2 +#if !NETSTANDARD2_0 && !NET462 && !NET47 && !NETCOREAPP2_2 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Vector256 K256(int i) => Unsafe.Add(ref _k256[0], i); diff --git a/src/JsonWebToken/Base64.cs b/src/JsonWebToken/Base64.cs index 7a35f423..a7b88e91 100644 --- a/src/JsonWebToken/Base64.cs +++ b/src/JsonWebToken/Base64.cs @@ -217,7 +217,7 @@ public static int GetArraySizeRequiredToDecode(int count) public static int GetArraySizeRequiredToEncode(int count) => gfoidl.Base64.Base64.Default.GetEncodedLength(count); -#if NET461 || NET47 || NETSTANDARD +#if NET462 || NET47 || NETSTANDARD internal static unsafe bool IsBase64String(string value) => IsBase64String(value.AsSpan()); #endif diff --git a/src/JsonWebToken/Base64Url.cs b/src/JsonWebToken/Base64Url.cs index 1d193720..8723a2d9 100644 --- a/src/JsonWebToken/Base64Url.cs +++ b/src/JsonWebToken/Base64Url.cs @@ -191,7 +191,7 @@ public static int GetArraySizeRequiredToDecode(int count) public static int GetArraySizeRequiredToEncode(int count) => gfoidl.Base64.Base64.Url.GetEncodedLength(count); -#if NET461 || NET47 || NETSTANDARD +#if NET462 || NET47 || NETSTANDARD internal static unsafe bool IsBase64UrlString(string value) => IsBase64UrlString(value.AsSpan()); #endif diff --git a/src/JsonWebToken/Cryptography/RsaKeyUnwrapper.cs b/src/JsonWebToken/Cryptography/RsaKeyUnwrapper.cs index 691b676c..90f0269b 100644 --- a/src/JsonWebToken/Cryptography/RsaKeyUnwrapper.cs +++ b/src/JsonWebToken/Cryptography/RsaKeyUnwrapper.cs @@ -24,7 +24,7 @@ public RsaKeyUnwrapper(RsaJwk key, EncryptionAlgorithm encryptionAlgorithm, KeyM #if SUPPORT_SPAN_CRYPTO _rsa = RSA.Create(key.ExportParameters()); #else -#if NET461 || NET47 +#if NET462 || NET47 _rsa = new RSACng(); #else _rsa = RSA.Create(); diff --git a/src/JsonWebToken/Cryptography/RsaKeyWrapper.cs b/src/JsonWebToken/Cryptography/RsaKeyWrapper.cs index 58e85118..20ad9487 100644 --- a/src/JsonWebToken/Cryptography/RsaKeyWrapper.cs +++ b/src/JsonWebToken/Cryptography/RsaKeyWrapper.cs @@ -24,7 +24,7 @@ public RsaKeyWrapper(RsaJwk key, EncryptionAlgorithm encryptionAlgorithm, KeyMan #if SUPPORT_SPAN_CRYPTO _rsa = RSA.Create(key.ExportParameters()); #else -#if NET461 || NET47 +#if NET462 || NET47 _rsa = new RSACng(); #else _rsa = RSA.Create(); diff --git a/src/JsonWebToken/Cryptography/RsaObjectPoolPolicy.cs b/src/JsonWebToken/Cryptography/RsaObjectPoolPolicy.cs index e4be8fea..0f4b9343 100644 --- a/src/JsonWebToken/Cryptography/RsaObjectPoolPolicy.cs +++ b/src/JsonWebToken/Cryptography/RsaObjectPoolPolicy.cs @@ -19,7 +19,7 @@ public override RSA Create() #if SUPPORT_SPAN_CRYPTO return RSA.Create(_parameters); #else -#if NET461 || NET47 +#if NET462 || NET47 var rsa = new RSACng(); #else var rsa = RSA.Create(); diff --git a/src/JsonWebToken/Internal/DoesNotReturnAttribute.cs b/src/JsonWebToken/Internal/DoesNotReturnAttribute.cs index 330876cf..2e3f9f7e 100644 --- a/src/JsonWebToken/Internal/DoesNotReturnAttribute.cs +++ b/src/JsonWebToken/Internal/DoesNotReturnAttribute.cs @@ -1,7 +1,7 @@ // Copyright (c) 2020 Yann Crumeyrolle. All rights reserved. // Licensed under the MIT license. See LICENSE in the project root for license information. -#if NETSTANDARD2_0 || NET461 || NET47 || NETCOREAPP2_2 +#if NETSTANDARD2_0 || NET462 || NET47 || NETCOREAPP2_2 namespace System.Diagnostics.CodeAnalysis { /// Applied to a method that will never return under any circumstance. diff --git a/src/JsonWebToken/Internal/EncodingExtensions.cs b/src/JsonWebToken/Internal/EncodingExtensions.cs index e1c30ff0..c929af45 100644 --- a/src/JsonWebToken/Internal/EncodingExtensions.cs +++ b/src/JsonWebToken/Internal/EncodingExtensions.cs @@ -1,7 +1,7 @@ // Copyright (c) 2020 Yann Crumeyrolle. All rights reserved. // Licensed under the MIT license. See LICENSE in the project root for license information. -#if NETSTANDARD2_0 || NET461 || NET47 +#if NETSTANDARD2_0 || NET462 || NET47 using System; using System.ComponentModel; using System.Text; diff --git a/src/JsonWebToken/Internal/MemberNotNullAttribute.cs b/src/JsonWebToken/Internal/MemberNotNullAttribute.cs index 93a1cd33..15c4c264 100644 --- a/src/JsonWebToken/Internal/MemberNotNullAttribute.cs +++ b/src/JsonWebToken/Internal/MemberNotNullAttribute.cs @@ -1,7 +1,7 @@ // Copyright (c) 2020 Yann Crumeyrolle. All rights reserved. // Licensed under the MIT license. See LICENSE in the project root for license information. -#if NETSTANDARD2_0 || NET461 || NET47 || NETCOREAPP2_2 || NETCOREAPP3_1 +#if NETSTANDARD2_0 || NET462 || NET47 || NETCOREAPP2_2 || NETCOREAPP3_1 namespace System.Diagnostics.CodeAnalysis { /// Specifies that the method or property will ensure that the listed field and property members have values that aren't null. diff --git a/src/JsonWebToken/Internal/NotNullWhenAttribute.cs b/src/JsonWebToken/Internal/NotNullWhenAttribute.cs index 3ca257ad..d096be61 100644 --- a/src/JsonWebToken/Internal/NotNullWhenAttribute.cs +++ b/src/JsonWebToken/Internal/NotNullWhenAttribute.cs @@ -1,7 +1,7 @@ // Copyright (c) 2020 Yann Crumeyrolle. All rights reserved. // Licensed under the MIT license. See LICENSE in the project root for license information. -#if NETSTANDARD2_0 || NET461 || NET47 || NETCOREAPP2_2 +#if NETSTANDARD2_0 || NET462 || NET47 || NETCOREAPP2_2 namespace System.Diagnostics.CodeAnalysis { /// Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it. diff --git a/src/JsonWebToken/Internal/OSPlatform.cs b/src/JsonWebToken/Internal/OSPlatform.cs index e3db3630..47ac42e7 100644 --- a/src/JsonWebToken/Internal/OSPlatform.cs +++ b/src/JsonWebToken/Internal/OSPlatform.cs @@ -1,7 +1,7 @@ // Copyright (c) 2020 Yann Crumeyrolle. All rights reserved. // Licensed under the MIT license. See LICENSE in the project root for license information. -#if NET47 || NET461 +#if NET47 || NET462 namespace JsonWebToken { internal enum OSPlatform diff --git a/src/JsonWebToken/Internal/RuntimeInformation.cs b/src/JsonWebToken/Internal/RuntimeInformation.cs index 02a83a93..30e1da4b 100644 --- a/src/JsonWebToken/Internal/RuntimeInformation.cs +++ b/src/JsonWebToken/Internal/RuntimeInformation.cs @@ -1,7 +1,7 @@ // Copyright (c) 2020 Yann Crumeyrolle. All rights reserved. // Licensed under the MIT license. See LICENSE in the project root for license information. -#if NET47 || NET461 +#if NET47 || NET462 namespace JsonWebToken { internal class RuntimeInformation diff --git a/src/JsonWebToken/Internal/StreamExtensions.cs b/src/JsonWebToken/Internal/StreamExtensions.cs index 68d2b745..0c3049e0 100644 --- a/src/JsonWebToken/Internal/StreamExtensions.cs +++ b/src/JsonWebToken/Internal/StreamExtensions.cs @@ -1,7 +1,7 @@ // Copyright (c) 2020 Yann Crumeyrolle. All rights reserved. // Licensed under the MIT license. See LICENSE in the project root for license information. -#if NETSTANDARD2_0 || NET461 || NET47 +#if NETSTANDARD2_0 || NET462 || NET47 using System; using System.IO; using System.Buffers; diff --git a/src/JsonWebToken/JsonWebToken.csproj b/src/JsonWebToken/JsonWebToken.csproj index 957498f8..87a8a0fa 100644 --- a/src/JsonWebToken/JsonWebToken.csproj +++ b/src/JsonWebToken/JsonWebToken.csproj @@ -2,7 +2,7 @@ net8.0;net6.0;net7.0;netstandard2.0 - $(TargetFrameworks);net461;net47 + $(TargetFrameworks);net462;net47 12.0 enable true @@ -39,12 +39,12 @@ - + - - - + + + @@ -57,29 +57,29 @@ - + - + - - + + - + - + - - + + - + @@ -92,7 +92,7 @@ SUPPORT_JAVASCRIPT_ENCODER SUPPORT_SPAN_CRYPTO --> - + $(DefineConstants);SUPPORT_JAVASCRIPT_ENCODER CS8601;CS8602;CS8604;CS8618 diff --git a/src/JsonWebToken/RsaJwk.cs b/src/JsonWebToken/RsaJwk.cs index fa1a9109..8d6bad40 100644 --- a/src/JsonWebToken/RsaJwk.cs +++ b/src/JsonWebToken/RsaJwk.cs @@ -508,7 +508,7 @@ private static RsaJwk GenerateKey(int sizeInBits, bool withPrivateKey, bool comp #if SUPPORT_SPAN_CRYPTO using RSA rsa = RSA.Create(sizeInBits); #else -#if NET461 || NET47 +#if NET462 || NET47 using RSA rsa = new RSACng(sizeInBits); #else using RSA rsa = RSA.Create(); @@ -524,7 +524,7 @@ private static RsaJwk GenerateKey(int sizeInBits, SignatureAlgorithm algorithm, #if SUPPORT_SPAN_CRYPTO using RSA rsa = RSA.Create(sizeInBits); #else -#if NET461 || NET47 +#if NET462 || NET47 using RSA rsa = new RSACng(sizeInBits); #else using RSA rsa = RSA.Create(); @@ -542,7 +542,7 @@ private static RsaJwk GenerateKey(int sizeInBits, KeyManagementAlgorithm algorit #if SUPPORT_SPAN_CRYPTO using RSA rsa = RSA.Create(sizeInBits); #else -#if NET461 || NET47 +#if NET462 || NET47 using RSA rsa = new RSACng(sizeInBits); #else using RSA rsa = RSA.Create(); diff --git a/src/JsonWebToken/SymmetricJwk.cs b/src/JsonWebToken/SymmetricJwk.cs index 710f4ea3..bd0b066f 100644 --- a/src/JsonWebToken/SymmetricJwk.cs +++ b/src/JsonWebToken/SymmetricJwk.cs @@ -91,7 +91,7 @@ internal SymmetricJwk(ref Utf8JsonReader reader) } } - if (!(reader.TokenType is JsonTokenType.EndObject)) + if (reader.TokenType is not JsonTokenType.EndObject) { ThrowHelper.ThrowArgumentException_MalformedKey(); } @@ -434,8 +434,8 @@ private static byte[] GenerateKeyBytes(int sizeInBits) return key; } - private static ReadOnlySpan StartCanonicalizeValue => new byte[] { (byte)'{', (byte)'"', (byte)'k', (byte)'"', (byte)':', (byte)'"' }; - private static ReadOnlySpan EndCanonicalizeValue => new byte[] { (byte)'"', (byte)',', (byte)'"', (byte)'k', (byte)'t', (byte)'y', (byte)'"', (byte)':', (byte)'"', (byte)'o', (byte)'c', (byte)'t', (byte)'"', (byte)'}' }; + private static ReadOnlySpan StartCanonicalizeValue => "{\"k\":\""u8; + private static ReadOnlySpan EndCanonicalizeValue => "\",\"kty\":\"oct\"}"u8; /// protected internal override void Canonicalize(Span buffer) @@ -492,7 +492,7 @@ public override bool Equals(Jwk? other) return true; } - if (!(other is SymmetricJwk key)) + if (other is not SymmetricJwk key) { return false; } diff --git a/src/JsonWebToken/Writer/JweDescriptor`1.cs b/src/JsonWebToken/Writer/JweDescriptor`1.cs index 704d124c..47f353b5 100644 --- a/src/JsonWebToken/Writer/JweDescriptor`1.cs +++ b/src/JsonWebToken/Writer/JweDescriptor`1.cs @@ -21,7 +21,7 @@ public abstract class JweDescriptor : JwtDescriptor where TP private readonly string? _typ; private readonly string? _cty; -#if NETSTANDARD2_0 || NET461 || NET47 +#if NETSTANDARD2_0 || NET462 || NET47 private static readonly RandomNumberGenerator _randomNumberGenerator = RandomNumberGenerator.Create(); #endif @@ -224,7 +224,7 @@ protected void EncryptToken(ReadOnlySpan payload, EncodingContext context) Span tag = buffer.Slice(ciphertextSize, tagSize); Span ciphertext = buffer.Slice(0, ciphertextSize); -#if NETSTANDARD2_0 || NET461 || NET47 +#if NETSTANDARD2_0 || NET462 || NET47 var nonce = new byte[encryptor.GetNonceSize()]; _randomNumberGenerator.GetBytes(nonce); #else diff --git a/src/KeyVault/JsonWebToken.KeyVault.csproj b/src/KeyVault/JsonWebToken.KeyVault.csproj index 4a53ee27..1247e009 100644 --- a/src/KeyVault/JsonWebToken.KeyVault.csproj +++ b/src/KeyVault/JsonWebToken.KeyVault.csproj @@ -2,7 +2,7 @@ net6.0;net7.0;net8.0;netstandard2.0 - $(TargetFrameworks);net461;net47 + $(TargetFrameworks);net462;net47 9.0 enable true @@ -29,7 +29,7 @@ Provides Key Vault support. - + diff --git a/src/OAuth2/JsonWebToken.OAuth2.csproj b/src/OAuth2/JsonWebToken.OAuth2.csproj index c559085b..a4455d1f 100644 --- a/src/OAuth2/JsonWebToken.OAuth2.csproj +++ b/src/OAuth2/JsonWebToken.OAuth2.csproj @@ -2,7 +2,7 @@ net6.0;net7.0;net8.0;netstandard2.0 - $(TargetFrameworks);net461;net47 + $(TargetFrameworks);net462;net47 9.0 enable true diff --git a/src/SecurityEventTokens/JsonWebToken.SecurityEventTokens.csproj b/src/SecurityEventTokens/JsonWebToken.SecurityEventTokens.csproj index b8be47d0..7fee1427 100644 --- a/src/SecurityEventTokens/JsonWebToken.SecurityEventTokens.csproj +++ b/src/SecurityEventTokens/JsonWebToken.SecurityEventTokens.csproj @@ -2,7 +2,7 @@ net6.0;net7.0;net8.0;netstandard2.0 - $(TargetFrameworks);net461;net47 + $(TargetFrameworks);net462;net47 9.0 enable true diff --git a/test/JsonWebToken.OAuth2.Tests/JsonWebToken.OAuth2.Tests.csproj b/test/JsonWebToken.OAuth2.Tests/JsonWebToken.OAuth2.Tests.csproj index 0ed31dcd..467dd952 100644 --- a/test/JsonWebToken.OAuth2.Tests/JsonWebToken.OAuth2.Tests.csproj +++ b/test/JsonWebToken.OAuth2.Tests/JsonWebToken.OAuth2.Tests.csproj @@ -2,7 +2,7 @@ net6.0;net7.0;net8.0 - $(TargetFrameworks);net461;net47 + $(TargetFrameworks);net462;net47 9.0 false @@ -12,13 +12,13 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/JsonWebToken.SecurityEventTokens.Tests/JsonWebToken.SecurityEventTokens.Tests.csproj b/test/JsonWebToken.SecurityEventTokens.Tests/JsonWebToken.SecurityEventTokens.Tests.csproj index 075c375b..e6752235 100644 --- a/test/JsonWebToken.SecurityEventTokens.Tests/JsonWebToken.SecurityEventTokens.Tests.csproj +++ b/test/JsonWebToken.SecurityEventTokens.Tests/JsonWebToken.SecurityEventTokens.Tests.csproj @@ -2,7 +2,7 @@ net6.0;net7.0;net8.0 - $(TargetFrameworks);net461;net47 + $(TargetFrameworks);net462;net47 9.0 false @@ -12,13 +12,13 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/JsonWebToken.Tests.Common/JsonWebToken.Tests.Common.csproj b/test/JsonWebToken.Tests.Common/JsonWebToken.Tests.Common.csproj index 504a44cc..4e7081f3 100644 --- a/test/JsonWebToken.Tests.Common/JsonWebToken.Tests.Common.csproj +++ b/test/JsonWebToken.Tests.Common/JsonWebToken.Tests.Common.csproj @@ -2,7 +2,7 @@ net6.0;net7.0;net8.0 - $(TargetFrameworks);net461;net47 + $(TargetFrameworks);net462;net47 9.0 true @@ -15,13 +15,13 @@ - + - + - + diff --git a/test/JsonWebToken.Tests.Common/KeyFixture.cs b/test/JsonWebToken.Tests.Common/KeyFixture.cs index 1f457489..18ea1b6b 100644 --- a/test/JsonWebToken.Tests.Common/KeyFixture.cs +++ b/test/JsonWebToken.Tests.Common/KeyFixture.cs @@ -17,7 +17,7 @@ public KeyFixture() EncryptionKey = CreateEncryptionKey(); Jwks.Add(EncryptionKey); Jwks.Add(PrivateRsa2048Key); -#if !NET461 +#if !NET462 Jwks.Add(PrivateEcc256Key); Jwks.Add(PrivateEcc384Key); Jwks.Add(PrivateEcc512Key); @@ -67,7 +67,7 @@ public SymmetricJwk CreateEncryptionKey() n: "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw", e: "AQAB" ); -#if !NET461 +#if !NET462 public readonly ECJwk PrivateEcc256Key = ECJwk.FromBase64Url ( crv: EllipticalCurve.P256, diff --git a/test/JsonWebToken.Tests/AlgorithmCompatibilityTests.cs b/test/JsonWebToken.Tests/AlgorithmCompatibilityTests.cs index a05dddc1..077cd903 100644 --- a/test/JsonWebToken.Tests/AlgorithmCompatibilityTests.cs +++ b/test/JsonWebToken.Tests/AlgorithmCompatibilityTests.cs @@ -95,7 +95,7 @@ private IEnumerable SelectEncryptionKey(string enc, string alg) case "RSA1_5": yield return _keys.PrivateRsa2048Key; break; -#if !NET461 && !NET47 +#if !NET462 && !NET47 case "ECDH-ES+A128KW": case "ECDH-ES+A192KW": case "ECDH-ES+A256KW": diff --git a/test/JsonWebToken.Tests/ECJwkTests.cs b/test/JsonWebToken.Tests/ECJwkTests.cs index 32b50512..aaea49e7 100644 --- a/test/JsonWebToken.Tests/ECJwkTests.cs +++ b/test/JsonWebToken.Tests/ECJwkTests.cs @@ -1,4 +1,4 @@ -#if !NET461 +#if !NET462 using System; using System.Collections.Generic; using System.Linq; diff --git a/test/JsonWebToken.Tests/JsonWebToken.Tests.csproj b/test/JsonWebToken.Tests/JsonWebToken.Tests.csproj index eb457034..7c6a91d3 100644 --- a/test/JsonWebToken.Tests/JsonWebToken.Tests.csproj +++ b/test/JsonWebToken.Tests/JsonWebToken.Tests.csproj @@ -1,7 +1,7 @@  net6.0;net7.0;net8.0 - $(TargetFrameworks);net461;net47 + $(TargetFrameworks);net462;net47 false false @@ -15,14 +15,14 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -33,19 +33,19 @@ - + - + - + - + $(DefineConstants);SUPPORT_JAVASCRIPT_ENCODER diff --git a/test/JsonWebToken.Tests/JwksTests.cs b/test/JsonWebToken.Tests/JwksTests.cs index 86a86cd9..8703eda3 100644 --- a/test/JsonWebToken.Tests/JwksTests.cs +++ b/test/JsonWebToken.Tests/JwksTests.cs @@ -156,8 +156,6 @@ public void ReadJwks_Invalid(string issuer, string json) Assert.ThrowsAny(() => Jwks.FromJson(issuer, json)); } - private object _lock = new object(); - [Fact] public void OnJwksRefreshed() { @@ -181,28 +179,28 @@ public void OnJwksRefreshed() key512 }; - lock (_lock) + Jwks.OnJwksRefreshed += Jwks_OnJwksRefreshed; + try { - Jwks.OnJwksRefreshed += Jwks_OnJwksRefreshed; - try - { - Jwks.PublishJwksRefreshed(oldJwks, newJwks); - } - finally - { - Jwks.OnJwksRefreshed -= Jwks_OnJwksRefreshed; - } + Jwks.PublishJwksRefreshed(oldJwks, newJwks); + } + finally + { + Jwks.OnJwksRefreshed -= Jwks_OnJwksRefreshed; } } private void Jwks_OnJwksRefreshed(Jwks added, Jwks removed) { - Assert.Equal(2, added.Count); - Assert.Contains(added, k => k.KeySizeInBits == 384); - Assert.Contains(added, k => k.KeySizeInBits == 512); + if (removed.Issuer == "issuer1") + { + Assert.Equal(2, added.Count); + Assert.Contains(added, k => k.KeySizeInBits == 384); + Assert.Contains(added, k => k.KeySizeInBits == 512); - Assert.Equal(1, removed.Count); - Assert.Contains(removed, k => k.KeySizeInBits == 192); + Assert.Equal(1, removed.Count); + Assert.Contains(removed, k => k.KeySizeInBits == 192); + } } [Theory] @@ -233,8 +231,8 @@ public void ReadJwks_Kid(string issuer, string json) } - private static string EmptyJwks = @"{""keys"":[]}"; - private static string SalesforceJwks = @"{ + private static readonly string EmptyJwks = @"{""keys"":[]}"; + private static readonly string SalesforceJwks = @"{ ""keys"": [ { ""kty"": ""RSA"", @@ -262,8 +260,8 @@ public void ReadJwks_Kid(string issuer, string json) } ] }"; - private static string MicrosoftJwks = @"{""keys"":[{""kty"":""RSA"",""use"":""sig"",""kid"":""-sxMJMLCIDWMTPvZyJ6tx-CDxw0"",""x5t"":""-sxMJMLCIDWMTPvZyJ6tx-CDxw0"",""n"":""rxlPnqW6fNuCbdrhDEzwGJVux3iPvtt_8r-uHHIKa7C_b_ux5hewNMS91SgUPZOrsqb54uHj_7INWKqKEtFc4YP83Fhss_uO_mT97czENs4zWaSN9Eww_Fz36xq_uZ65750lHKwXQJ1A_pe-VOgNlPg8ECi7meQDJ05r838eu1jpKFjxkQrdRFTLgYtRQ7TxX-zzRyoRR8iqJc6Rvnijh19-YfWtBsCI1r127SFakUBrY_ZKsKyE9KNWUL7H65EyFRNgK80XfYvhQlGw3-Ajf28fi71wW-BypK1bTCArzwX7zgF3H6P1u8PKosSOSN_Q9-Qc9X-R_Y-3bOpOIiLOvw"",""e"":""AQAB"",""x5c"":[""MIIDBTCCAe2gAwIBAgIQKOfEJNDyDplBSXKYcM6UcjANBgkqhkiG9w0BAQsFADAtMSswKQYDVQQDEyJhY2NvdW50cy5hY2Nlc3Njb250cm9sLndpbmRvd3MubmV0MB4XDTE4MTIyMjAwMDAwMFoXDTIwMTIyMjAwMDAwMFowLTErMCkGA1UEAxMiYWNjb3VudHMuYWNjZXNzY29udHJvbC53aW5kb3dzLm5ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK8ZT56lunzbgm3a4QxM8BiVbsd4j77bf/K/rhxyCmuwv2/7seYXsDTEvdUoFD2Tq7Km+eLh4/+yDViqihLRXOGD/NxYbLP7jv5k/e3MxDbOM1mkjfRMMPxc9+sav7meue+dJRysF0CdQP6XvlToDZT4PBAou5nkAydOa/N/HrtY6ShY8ZEK3URUy4GLUUO08V/s80cqEUfIqiXOkb54o4dffmH1rQbAiNa9du0hWpFAa2P2SrCshPSjVlC+x+uRMhUTYCvNF32L4UJRsN/gI39vH4u9cFvgcqStW0wgK88F+84Bdx+j9bvDyqLEjkjf0PfkHPV/kf2Pt2zqTiIizr8CAwEAAaMhMB8wHQYDVR0OBBYEFC//HOy7pEIKtnpMj4bEMA3oJ39uMA0GCSqGSIb3DQEBCwUAA4IBAQAIYxZXIpwUX8HjSKWUMiyQEn0gRizAyqQhC5wdWOFCBIZPJs8efOkGTsBg/hA+X1fvN6htcBbJRfFfDlP/LkLIVNv2zX4clGM20YhY8FQQh9FWs5qchlnP4lSk7UmScxgT3a6FG3OcLToukNoK722Om2yQ1ayWtn9K82hvZl5L3P8zYaG1gbHPGW5VlNXds60jIpcSWLdU2hacYmwz4pPQyvNOW68aK/Y/tWrJ3DKrf1feDbmm7O5kpWVYWRpah+i6ePjELNkc2Jr+2DchBQTIh9Fxe8sz+9iOyLh9tubMJ+7RTs/ksK0sQ1NVScGFxK+o5hFOOMK7y/F5r467jHez""],""issuer"":""https://login.microsoftonline.com/{tenantid}/v2.0""},{""kty"":""RSA"",""use"":""sig"",""kid"":""N-lC0n-9DALqwhuHYnHQ63GeCXc"",""x5t"":""N-lC0n-9DALqwhuHYnHQ63GeCXc"",""n"":""t3J1hnS4aRZaZGq5JUw1iKsHynCUV9lMBe2MDArXGeQlN-w8Xw9vU6InqmPVvJsUVyUkKE0jzn4dYLcwbTuttQ0hmN-lzNfGol04KKMIVdtTs1P0wo_-VyJ88EuWM3lvDxyTw1PLim14UJ1856zdp2_kZLOSy-B46K96ENJ8b2yCP_VHRTd3GgNTrx-xeU66WJdlon6SSkxI85KIAzOR4vxrl2XZZx_DkVcsAHa8KXQRkbMw82F2SHAbgJTv8qjSHR_WXjoGs3Wgds9UUqgNDXSK6qTjoG53zj8-faRkK0Px4wRD9rVXt-pPcGaul3TEkUVhpe8SyrLWETFexJesSQ"",""e"":""AQAB"",""x5c"":[""MIIDBTCCAe2gAwIBAgIQP8sUV4hf2ZxPfw5DB0O9CjANBgkqhkiG9w0BAQsFADAtMSswKQYDVQQDEyJhY2NvdW50cy5hY2Nlc3Njb250cm9sLndpbmRvd3MubmV0MB4XDTE5MDIwMTAwMDAwMFoXDTIxMDIwMTAwMDAwMFowLTErMCkGA1UEAxMiYWNjb3VudHMuYWNjZXNzY29udHJvbC53aW5kb3dzLm5ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALdydYZ0uGkWWmRquSVMNYirB8pwlFfZTAXtjAwK1xnkJTfsPF8Pb1OiJ6pj1bybFFclJChNI85+HWC3MG07rbUNIZjfpczXxqJdOCijCFXbU7NT9MKP/lcifPBLljN5bw8ck8NTy4pteFCdfOes3adv5GSzksvgeOivehDSfG9sgj/1R0U3dxoDU68fsXlOuliXZaJ+kkpMSPOSiAMzkeL8a5dl2Wcfw5FXLAB2vCl0EZGzMPNhdkhwG4CU7/Ko0h0f1l46BrN1oHbPVFKoDQ10iuqk46Bud84/Pn2kZCtD8eMEQ/a1V7fqT3Bmrpd0xJFFYaXvEsqy1hExXsSXrEkCAwEAAaMhMB8wHQYDVR0OBBYEFH5JQzlFI3FE9VxkkUbFT9XQDxifMA0GCSqGSIb3DQEBCwUAA4IBAQCb7re2PWF5ictaUCi4Ki2AWE6fGbmVRUdf0GkI06KdHWSiOgkPdB7Oka1Fv/j4GCs/ezHa1+oAx8uU96GECBBEMnCYPqkjmNKdLYkIUrcwEe9qz12MOCKJkCuYsDdLUqv+e4wHssbAnJn2+L13UmfAb6FM1VTaKIQtPs4yZsdhnk4M+Ee2EpcvgwOl2na+m58ovspieEyI6II/TolzwP9NWbvHw5VlF0IYttQprjmQU3tQ2E6j3HpZ31B0nrnFWglUB7lEC+0mkyJUGzovNECsr+BIEMhTlCp2/rbruCCbZBppYAlbWlTFwXA8TqfE4DNATYgm90ObQANcTnHJeRV1""],""issuer"":""https://login.microsoftonline.com/{tenantid}/v2.0""},{""kty"":""RSA"",""use"":""sig"",""kid"":""M6pX7RHoraLsprfJeRCjSxuURhc"",""x5t"":""M6pX7RHoraLsprfJeRCjSxuURhc"",""n"":""xHScZMPo8FifoDcrgncWQ7mGJtiKhrsho0-uFPXg-OdnRKYudTD7-Bq1MDjcqWRf3IfDVjFJixQS61M7wm9wALDj--lLuJJ9jDUAWTA3xWvQLbiBM-gqU0sj4mc2lWm6nPfqlyYeWtQcSC0sYkLlayNgX4noKDaXivhVOp7bwGXq77MRzeL4-9qrRYKjuzHfZL7kNBCsqO185P0NI2Jtmw-EsqYsrCaHsfNRGRrTvUHUq3hWa859kK_5uNd7TeY2ZEwKVD8ezCmSfR59ZzyxTtuPpkCSHS9OtUvS3mqTYit73qcvprjl3R8hpjXLb8oftfpWr3hFRdpxrwuoQEO4QQ"",""e"":""AQAB"",""x5c"":[""MIIC8TCCAdmgAwIBAgIQfEWlTVc1uINEc9RBi6qHMjANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDExhsb2dpbi5taWNyb3NvZnRvbmxpbmUudXMwHhcNMTgxMDE0MDAwMDAwWhcNMjAxMDE0MDAwMDAwWjAjMSEwHwYDVQQDExhsb2dpbi5taWNyb3NvZnRvbmxpbmUudXMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDEdJxkw+jwWJ+gNyuCdxZDuYYm2IqGuyGjT64U9eD452dEpi51MPv4GrUwONypZF/ch8NWMUmLFBLrUzvCb3AAsOP76Uu4kn2MNQBZMDfFa9AtuIEz6CpTSyPiZzaVabqc9+qXJh5a1BxILSxiQuVrI2BfiegoNpeK+FU6ntvAZervsxHN4vj72qtFgqO7Md9kvuQ0EKyo7Xzk/Q0jYm2bD4SypiysJoex81EZGtO9QdSreFZrzn2Qr/m413tN5jZkTApUPx7MKZJ9Hn1nPLFO24+mQJIdL061S9LeapNiK3vepy+muOXdHyGmNctvyh+1+laveEVF2nGvC6hAQ7hBAgMBAAGjITAfMB0GA1UdDgQWBBQ5TKadw06O0cvXrQbXW0Nb3M3h/DANBgkqhkiG9w0BAQsFAAOCAQEAI48JaFtwOFcYS/3pfS5+7cINrafXAKTL+/+he4q+RMx4TCu/L1dl9zS5W1BeJNO2GUznfI+b5KndrxdlB6qJIDf6TRHh6EqfA18oJP5NOiKhU4pgkF2UMUw4kjxaZ5fQrSoD9omjfHAFNjradnHA7GOAoF4iotvXDWDBWx9K4XNZHWvD11Td66zTg5IaEQDIZ+f8WS6nn/98nAVMDtR9zW7Te5h9kGJGfe6WiHVaGRPpBvqC4iypGHjbRwANwofZvmp5wP08hY1CsnKY5tfP+E2k/iAQgKKa6QoxXToYvP7rsSkglak8N5g/+FJGnq4wP6cOzgZpjdPMwaVt5432GA==""],""issuer"":""https://login.microsoftonline.com/{tenantid}/v2.0""},{""kty"":""RSA"",""use"":""sig"",""kid"":""1LTMzakihiRla_8z2BEJVXeWMqo"",""x5t"":""1LTMzakihiRla_8z2BEJVXeWMqo"",""n"":""3sKcJSD4cHwTY5jYm5lNEzqk3wON1CaARO5EoWIQt5u-X-ZnW61CiRZpWpfhKwRYU153td5R8p-AJDWT-NcEJ0MHU3KiuIEPmbgJpS7qkyURuHRucDM2lO4L4XfIlvizQrlyJnJcd09uLErZEO9PcvKiDHoois2B4fGj7CsAe5UZgExJvACDlsQSku2JUyDmZUZP2_u_gCuqNJM5o0hW7FKRI3MFoYCsqSEmHnnumuJ2jF0RHDRWQpodhlAR6uKLoiWHqHO3aG7scxYMj5cMzkpe1Kq_Dm5yyHkMCSJ_JaRhwymFfV_SWkqd3n-WVZT0ADLEq0RNi9tqZ43noUnO_w"",""e"":""AQAB"",""x5c"":[""MIIDYDCCAkigAwIBAgIJAIB4jVVJ3BeuMA0GCSqGSIb3DQEBCwUAMCkxJzAlBgNVBAMTHkxpdmUgSUQgU1RTIFNpZ25pbmcgUHVibGljIEtleTAeFw0xNjA0MDUxNDQzMzVaFw0yMTA0MDQxNDQzMzVaMCkxJzAlBgNVBAMTHkxpdmUgSUQgU1RTIFNpZ25pbmcgUHVibGljIEtleTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAN7CnCUg+HB8E2OY2JuZTRM6pN8DjdQmgETuRKFiELebvl/mZ1utQokWaVqX4SsEWFNed7XeUfKfgCQ1k/jXBCdDB1NyoriBD5m4CaUu6pMlEbh0bnAzNpTuC+F3yJb4s0K5ciZyXHdPbixK2RDvT3Lyogx6KIrNgeHxo+wrAHuVGYBMSbwAg5bEEpLtiVMg5mVGT9v7v4ArqjSTOaNIVuxSkSNzBaGArKkhJh557pridoxdERw0VkKaHYZQEerii6Ilh6hzt2hu7HMWDI+XDM5KXtSqvw5ucsh5DAkifyWkYcMphX1f0lpKnd5/llWU9AAyxKtETYvbameN56FJzv8CAwEAAaOBijCBhzAdBgNVHQ4EFgQU9IdLLpbC2S8Wn1MCXsdtFac9SRYwWQYDVR0jBFIwUIAU9IdLLpbC2S8Wn1MCXsdtFac9SRahLaQrMCkxJzAlBgNVBAMTHkxpdmUgSUQgU1RTIFNpZ25pbmcgUHVibGljIEtleYIJAIB4jVVJ3BeuMAsGA1UdDwQEAwIBxjANBgkqhkiG9w0BAQsFAAOCAQEAXk0sQAib0PGqvwELTlflQEKS++vqpWYPW/2gCVCn5shbyP1J7z1nT8kE/ZDVdl3LvGgTMfdDHaRF5ie5NjkTHmVOKbbHaWpTwUFbYAFBJGnx+s/9XSdmNmW9GlUjdpd6lCZxsI6888r0ptBgKINRRrkwMlq3jD1U0kv4JlsIhafUIOqGi4+hIDXBlY0F/HJPfUU75N885/r4CCxKhmfh3PBM35XOch/NGC67fLjqLN+TIWLoxnvil9m3jRjqOA9u50JUeDGZABIYIMcAdLpI2lcfru4wXcYXuQul22nAR7yOyGKNOKULoOTE4t4AeGRqCogXSxZgaTgKSBhvhE+MGg==""],""issuer"":""https://login.microsoftonline.com/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0""},{""kty"":""RSA"",""use"":""sig"",""kid"":""xP_zn6I1YkXcUUmlBoPuXTGsaxk"",""x5t"":""xP_zn6I1YkXcUUmlBoPuXTGsaxk"",""n"":""2pWatafeb3mB0A73-Z-URwrubwDldWvivRu19GNC61MBOb3fZ4I4lyhUhNuS7aJRPJIFB6zl-HFx1nHpGg74BHe0z9skODHYZEACd2iKBIet55DdduIe1CXsZ9keyEmNaGv3XS4OW_7IDM0j5wR9OHugUifkH3PQIcFvTYanHmXojTmgjIOWoz7y0okpyN9-FbZRzdfx-ej-njaj5gR8r69muwO5wlTbIG20V40R6zYh-QODMUpayy7jDGFGw5vjFH9Ca0tLZcNQq__JKE_mp-0fODOAQobOrBUoASFkyCd95BVW7KJrndvW7ofRWaCTuZZOy5SnU4asbjMrgxFZFw"",""e"":""AQAB"",""x5c"":[""MIIDYDCCAkigAwIBAgIJAJzCyTLC+DjJMA0GCSqGSIb3DQEBCwUAMCkxJzAlBgNVBAMTHkxpdmUgSUQgU1RTIFNpZ25pbmcgUHVibGljIEtleTAeFw0xNjA3MTMyMDMyMTFaFw0yMTA3MTIyMDMyMTFaMCkxJzAlBgNVBAMTHkxpdmUgSUQgU1RTIFNpZ25pbmcgUHVibGljIEtleTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANqVmrWn3m95gdAO9/mflEcK7m8A5XVr4r0btfRjQutTATm932eCOJcoVITbku2iUTySBQes5fhxcdZx6RoO+AR3tM/bJDgx2GRAAndoigSHreeQ3XbiHtQl7GfZHshJjWhr910uDlv+yAzNI+cEfTh7oFIn5B9z0CHBb02Gpx5l6I05oIyDlqM+8tKJKcjffhW2Uc3X8fno/p42o+YEfK+vZrsDucJU2yBttFeNEes2IfkDgzFKWssu4wxhRsOb4xR/QmtLS2XDUKv/yShP5qftHzgzgEKGzqwVKAEhZMgnfeQVVuyia53b1u6H0Vmgk7mWTsuUp1OGrG4zK4MRWRcCAwEAAaOBijCBhzAdBgNVHQ4EFgQU11z579/IePwuc4WBdN4L0ljG4CUwWQYDVR0jBFIwUIAU11z579/IePwuc4WBdN4L0ljG4CWhLaQrMCkxJzAlBgNVBAMTHkxpdmUgSUQgU1RTIFNpZ25pbmcgUHVibGljIEtleYIJAJzCyTLC+DjJMAsGA1UdDwQEAwIBxjANBgkqhkiG9w0BAQsFAAOCAQEAiASLEpQseGNahE+9f9PQgmX3VgjJerNjXr1zXWXDJfFE31DxgsxddjcIgoBL9lwegOHHvwpzK1ecgH45xcJ0Z/40OgY8NITqXbQRfdgLrEGJCoyOQEbjb5PW5k2aOdn7LBxvDsH6Y8ax26v+EFMPh3G+xheh6bfoIRSK1b+44PfoDZoJ9NfJibOZ4Cq+wt/yOvpMYQDB/9CNo18wmA3RCLYjf2nAc7RO0PDYHSIq5QDWV+1awmXDKgIdRpYPpRtn9KFXQkpCeEc/lDTG+o6n7nC40wyjioyR6QmHGvNkMR4VfSoTKCTnFATyDpI1bqU2K7KNjUEsCYfwybFB8d6mjQ==""],""issuer"":""https://login.microsoftonline.com/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0""}]}"; - private static string PaypalJwks = @"{ + private static readonly string MicrosoftJwks = @"{""keys"":[{""kty"":""RSA"",""use"":""sig"",""kid"":""-sxMJMLCIDWMTPvZyJ6tx-CDxw0"",""x5t"":""-sxMJMLCIDWMTPvZyJ6tx-CDxw0"",""n"":""rxlPnqW6fNuCbdrhDEzwGJVux3iPvtt_8r-uHHIKa7C_b_ux5hewNMS91SgUPZOrsqb54uHj_7INWKqKEtFc4YP83Fhss_uO_mT97czENs4zWaSN9Eww_Fz36xq_uZ65750lHKwXQJ1A_pe-VOgNlPg8ECi7meQDJ05r838eu1jpKFjxkQrdRFTLgYtRQ7TxX-zzRyoRR8iqJc6Rvnijh19-YfWtBsCI1r127SFakUBrY_ZKsKyE9KNWUL7H65EyFRNgK80XfYvhQlGw3-Ajf28fi71wW-BypK1bTCArzwX7zgF3H6P1u8PKosSOSN_Q9-Qc9X-R_Y-3bOpOIiLOvw"",""e"":""AQAB"",""x5c"":[""MIIDBTCCAe2gAwIBAgIQKOfEJNDyDplBSXKYcM6UcjANBgkqhkiG9w0BAQsFADAtMSswKQYDVQQDEyJhY2NvdW50cy5hY2Nlc3Njb250cm9sLndpbmRvd3MubmV0MB4XDTE4MTIyMjAwMDAwMFoXDTIwMTIyMjAwMDAwMFowLTErMCkGA1UEAxMiYWNjb3VudHMuYWNjZXNzY29udHJvbC53aW5kb3dzLm5ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK8ZT56lunzbgm3a4QxM8BiVbsd4j77bf/K/rhxyCmuwv2/7seYXsDTEvdUoFD2Tq7Km+eLh4/+yDViqihLRXOGD/NxYbLP7jv5k/e3MxDbOM1mkjfRMMPxc9+sav7meue+dJRysF0CdQP6XvlToDZT4PBAou5nkAydOa/N/HrtY6ShY8ZEK3URUy4GLUUO08V/s80cqEUfIqiXOkb54o4dffmH1rQbAiNa9du0hWpFAa2P2SrCshPSjVlC+x+uRMhUTYCvNF32L4UJRsN/gI39vH4u9cFvgcqStW0wgK88F+84Bdx+j9bvDyqLEjkjf0PfkHPV/kf2Pt2zqTiIizr8CAwEAAaMhMB8wHQYDVR0OBBYEFC//HOy7pEIKtnpMj4bEMA3oJ39uMA0GCSqGSIb3DQEBCwUAA4IBAQAIYxZXIpwUX8HjSKWUMiyQEn0gRizAyqQhC5wdWOFCBIZPJs8efOkGTsBg/hA+X1fvN6htcBbJRfFfDlP/LkLIVNv2zX4clGM20YhY8FQQh9FWs5qchlnP4lSk7UmScxgT3a6FG3OcLToukNoK722Om2yQ1ayWtn9K82hvZl5L3P8zYaG1gbHPGW5VlNXds60jIpcSWLdU2hacYmwz4pPQyvNOW68aK/Y/tWrJ3DKrf1feDbmm7O5kpWVYWRpah+i6ePjELNkc2Jr+2DchBQTIh9Fxe8sz+9iOyLh9tubMJ+7RTs/ksK0sQ1NVScGFxK+o5hFOOMK7y/F5r467jHez""],""issuer"":""https://login.microsoftonline.com/{tenantid}/v2.0""},{""kty"":""RSA"",""use"":""sig"",""kid"":""N-lC0n-9DALqwhuHYnHQ63GeCXc"",""x5t"":""N-lC0n-9DALqwhuHYnHQ63GeCXc"",""n"":""t3J1hnS4aRZaZGq5JUw1iKsHynCUV9lMBe2MDArXGeQlN-w8Xw9vU6InqmPVvJsUVyUkKE0jzn4dYLcwbTuttQ0hmN-lzNfGol04KKMIVdtTs1P0wo_-VyJ88EuWM3lvDxyTw1PLim14UJ1856zdp2_kZLOSy-B46K96ENJ8b2yCP_VHRTd3GgNTrx-xeU66WJdlon6SSkxI85KIAzOR4vxrl2XZZx_DkVcsAHa8KXQRkbMw82F2SHAbgJTv8qjSHR_WXjoGs3Wgds9UUqgNDXSK6qTjoG53zj8-faRkK0Px4wRD9rVXt-pPcGaul3TEkUVhpe8SyrLWETFexJesSQ"",""e"":""AQAB"",""x5c"":[""MIIDBTCCAe2gAwIBAgIQP8sUV4hf2ZxPfw5DB0O9CjANBgkqhkiG9w0BAQsFADAtMSswKQYDVQQDEyJhY2NvdW50cy5hY2Nlc3Njb250cm9sLndpbmRvd3MubmV0MB4XDTE5MDIwMTAwMDAwMFoXDTIxMDIwMTAwMDAwMFowLTErMCkGA1UEAxMiYWNjb3VudHMuYWNjZXNzY29udHJvbC53aW5kb3dzLm5ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALdydYZ0uGkWWmRquSVMNYirB8pwlFfZTAXtjAwK1xnkJTfsPF8Pb1OiJ6pj1bybFFclJChNI85+HWC3MG07rbUNIZjfpczXxqJdOCijCFXbU7NT9MKP/lcifPBLljN5bw8ck8NTy4pteFCdfOes3adv5GSzksvgeOivehDSfG9sgj/1R0U3dxoDU68fsXlOuliXZaJ+kkpMSPOSiAMzkeL8a5dl2Wcfw5FXLAB2vCl0EZGzMPNhdkhwG4CU7/Ko0h0f1l46BrN1oHbPVFKoDQ10iuqk46Bud84/Pn2kZCtD8eMEQ/a1V7fqT3Bmrpd0xJFFYaXvEsqy1hExXsSXrEkCAwEAAaMhMB8wHQYDVR0OBBYEFH5JQzlFI3FE9VxkkUbFT9XQDxifMA0GCSqGSIb3DQEBCwUAA4IBAQCb7re2PWF5ictaUCi4Ki2AWE6fGbmVRUdf0GkI06KdHWSiOgkPdB7Oka1Fv/j4GCs/ezHa1+oAx8uU96GECBBEMnCYPqkjmNKdLYkIUrcwEe9qz12MOCKJkCuYsDdLUqv+e4wHssbAnJn2+L13UmfAb6FM1VTaKIQtPs4yZsdhnk4M+Ee2EpcvgwOl2na+m58ovspieEyI6II/TolzwP9NWbvHw5VlF0IYttQprjmQU3tQ2E6j3HpZ31B0nrnFWglUB7lEC+0mkyJUGzovNECsr+BIEMhTlCp2/rbruCCbZBppYAlbWlTFwXA8TqfE4DNATYgm90ObQANcTnHJeRV1""],""issuer"":""https://login.microsoftonline.com/{tenantid}/v2.0""},{""kty"":""RSA"",""use"":""sig"",""kid"":""M6pX7RHoraLsprfJeRCjSxuURhc"",""x5t"":""M6pX7RHoraLsprfJeRCjSxuURhc"",""n"":""xHScZMPo8FifoDcrgncWQ7mGJtiKhrsho0-uFPXg-OdnRKYudTD7-Bq1MDjcqWRf3IfDVjFJixQS61M7wm9wALDj--lLuJJ9jDUAWTA3xWvQLbiBM-gqU0sj4mc2lWm6nPfqlyYeWtQcSC0sYkLlayNgX4noKDaXivhVOp7bwGXq77MRzeL4-9qrRYKjuzHfZL7kNBCsqO185P0NI2Jtmw-EsqYsrCaHsfNRGRrTvUHUq3hWa859kK_5uNd7TeY2ZEwKVD8ezCmSfR59ZzyxTtuPpkCSHS9OtUvS3mqTYit73qcvprjl3R8hpjXLb8oftfpWr3hFRdpxrwuoQEO4QQ"",""e"":""AQAB"",""x5c"":[""MIIC8TCCAdmgAwIBAgIQfEWlTVc1uINEc9RBi6qHMjANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDExhsb2dpbi5taWNyb3NvZnRvbmxpbmUudXMwHhcNMTgxMDE0MDAwMDAwWhcNMjAxMDE0MDAwMDAwWjAjMSEwHwYDVQQDExhsb2dpbi5taWNyb3NvZnRvbmxpbmUudXMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDEdJxkw+jwWJ+gNyuCdxZDuYYm2IqGuyGjT64U9eD452dEpi51MPv4GrUwONypZF/ch8NWMUmLFBLrUzvCb3AAsOP76Uu4kn2MNQBZMDfFa9AtuIEz6CpTSyPiZzaVabqc9+qXJh5a1BxILSxiQuVrI2BfiegoNpeK+FU6ntvAZervsxHN4vj72qtFgqO7Md9kvuQ0EKyo7Xzk/Q0jYm2bD4SypiysJoex81EZGtO9QdSreFZrzn2Qr/m413tN5jZkTApUPx7MKZJ9Hn1nPLFO24+mQJIdL061S9LeapNiK3vepy+muOXdHyGmNctvyh+1+laveEVF2nGvC6hAQ7hBAgMBAAGjITAfMB0GA1UdDgQWBBQ5TKadw06O0cvXrQbXW0Nb3M3h/DANBgkqhkiG9w0BAQsFAAOCAQEAI48JaFtwOFcYS/3pfS5+7cINrafXAKTL+/+he4q+RMx4TCu/L1dl9zS5W1BeJNO2GUznfI+b5KndrxdlB6qJIDf6TRHh6EqfA18oJP5NOiKhU4pgkF2UMUw4kjxaZ5fQrSoD9omjfHAFNjradnHA7GOAoF4iotvXDWDBWx9K4XNZHWvD11Td66zTg5IaEQDIZ+f8WS6nn/98nAVMDtR9zW7Te5h9kGJGfe6WiHVaGRPpBvqC4iypGHjbRwANwofZvmp5wP08hY1CsnKY5tfP+E2k/iAQgKKa6QoxXToYvP7rsSkglak8N5g/+FJGnq4wP6cOzgZpjdPMwaVt5432GA==""],""issuer"":""https://login.microsoftonline.com/{tenantid}/v2.0""},{""kty"":""RSA"",""use"":""sig"",""kid"":""1LTMzakihiRla_8z2BEJVXeWMqo"",""x5t"":""1LTMzakihiRla_8z2BEJVXeWMqo"",""n"":""3sKcJSD4cHwTY5jYm5lNEzqk3wON1CaARO5EoWIQt5u-X-ZnW61CiRZpWpfhKwRYU153td5R8p-AJDWT-NcEJ0MHU3KiuIEPmbgJpS7qkyURuHRucDM2lO4L4XfIlvizQrlyJnJcd09uLErZEO9PcvKiDHoois2B4fGj7CsAe5UZgExJvACDlsQSku2JUyDmZUZP2_u_gCuqNJM5o0hW7FKRI3MFoYCsqSEmHnnumuJ2jF0RHDRWQpodhlAR6uKLoiWHqHO3aG7scxYMj5cMzkpe1Kq_Dm5yyHkMCSJ_JaRhwymFfV_SWkqd3n-WVZT0ADLEq0RNi9tqZ43noUnO_w"",""e"":""AQAB"",""x5c"":[""MIIDYDCCAkigAwIBAgIJAIB4jVVJ3BeuMA0GCSqGSIb3DQEBCwUAMCkxJzAlBgNVBAMTHkxpdmUgSUQgU1RTIFNpZ25pbmcgUHVibGljIEtleTAeFw0xNjA0MDUxNDQzMzVaFw0yMTA0MDQxNDQzMzVaMCkxJzAlBgNVBAMTHkxpdmUgSUQgU1RTIFNpZ25pbmcgUHVibGljIEtleTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAN7CnCUg+HB8E2OY2JuZTRM6pN8DjdQmgETuRKFiELebvl/mZ1utQokWaVqX4SsEWFNed7XeUfKfgCQ1k/jXBCdDB1NyoriBD5m4CaUu6pMlEbh0bnAzNpTuC+F3yJb4s0K5ciZyXHdPbixK2RDvT3Lyogx6KIrNgeHxo+wrAHuVGYBMSbwAg5bEEpLtiVMg5mVGT9v7v4ArqjSTOaNIVuxSkSNzBaGArKkhJh557pridoxdERw0VkKaHYZQEerii6Ilh6hzt2hu7HMWDI+XDM5KXtSqvw5ucsh5DAkifyWkYcMphX1f0lpKnd5/llWU9AAyxKtETYvbameN56FJzv8CAwEAAaOBijCBhzAdBgNVHQ4EFgQU9IdLLpbC2S8Wn1MCXsdtFac9SRYwWQYDVR0jBFIwUIAU9IdLLpbC2S8Wn1MCXsdtFac9SRahLaQrMCkxJzAlBgNVBAMTHkxpdmUgSUQgU1RTIFNpZ25pbmcgUHVibGljIEtleYIJAIB4jVVJ3BeuMAsGA1UdDwQEAwIBxjANBgkqhkiG9w0BAQsFAAOCAQEAXk0sQAib0PGqvwELTlflQEKS++vqpWYPW/2gCVCn5shbyP1J7z1nT8kE/ZDVdl3LvGgTMfdDHaRF5ie5NjkTHmVOKbbHaWpTwUFbYAFBJGnx+s/9XSdmNmW9GlUjdpd6lCZxsI6888r0ptBgKINRRrkwMlq3jD1U0kv4JlsIhafUIOqGi4+hIDXBlY0F/HJPfUU75N885/r4CCxKhmfh3PBM35XOch/NGC67fLjqLN+TIWLoxnvil9m3jRjqOA9u50JUeDGZABIYIMcAdLpI2lcfru4wXcYXuQul22nAR7yOyGKNOKULoOTE4t4AeGRqCogXSxZgaTgKSBhvhE+MGg==""],""issuer"":""https://login.microsoftonline.com/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0""},{""kty"":""RSA"",""use"":""sig"",""kid"":""xP_zn6I1YkXcUUmlBoPuXTGsaxk"",""x5t"":""xP_zn6I1YkXcUUmlBoPuXTGsaxk"",""n"":""2pWatafeb3mB0A73-Z-URwrubwDldWvivRu19GNC61MBOb3fZ4I4lyhUhNuS7aJRPJIFB6zl-HFx1nHpGg74BHe0z9skODHYZEACd2iKBIet55DdduIe1CXsZ9keyEmNaGv3XS4OW_7IDM0j5wR9OHugUifkH3PQIcFvTYanHmXojTmgjIOWoz7y0okpyN9-FbZRzdfx-ej-njaj5gR8r69muwO5wlTbIG20V40R6zYh-QODMUpayy7jDGFGw5vjFH9Ca0tLZcNQq__JKE_mp-0fODOAQobOrBUoASFkyCd95BVW7KJrndvW7ofRWaCTuZZOy5SnU4asbjMrgxFZFw"",""e"":""AQAB"",""x5c"":[""MIIDYDCCAkigAwIBAgIJAJzCyTLC+DjJMA0GCSqGSIb3DQEBCwUAMCkxJzAlBgNVBAMTHkxpdmUgSUQgU1RTIFNpZ25pbmcgUHVibGljIEtleTAeFw0xNjA3MTMyMDMyMTFaFw0yMTA3MTIyMDMyMTFaMCkxJzAlBgNVBAMTHkxpdmUgSUQgU1RTIFNpZ25pbmcgUHVibGljIEtleTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANqVmrWn3m95gdAO9/mflEcK7m8A5XVr4r0btfRjQutTATm932eCOJcoVITbku2iUTySBQes5fhxcdZx6RoO+AR3tM/bJDgx2GRAAndoigSHreeQ3XbiHtQl7GfZHshJjWhr910uDlv+yAzNI+cEfTh7oFIn5B9z0CHBb02Gpx5l6I05oIyDlqM+8tKJKcjffhW2Uc3X8fno/p42o+YEfK+vZrsDucJU2yBttFeNEes2IfkDgzFKWssu4wxhRsOb4xR/QmtLS2XDUKv/yShP5qftHzgzgEKGzqwVKAEhZMgnfeQVVuyia53b1u6H0Vmgk7mWTsuUp1OGrG4zK4MRWRcCAwEAAaOBijCBhzAdBgNVHQ4EFgQU11z579/IePwuc4WBdN4L0ljG4CUwWQYDVR0jBFIwUIAU11z579/IePwuc4WBdN4L0ljG4CWhLaQrMCkxJzAlBgNVBAMTHkxpdmUgSUQgU1RTIFNpZ25pbmcgUHVibGljIEtleYIJAJzCyTLC+DjJMAsGA1UdDwQEAwIBxjANBgkqhkiG9w0BAQsFAAOCAQEAiASLEpQseGNahE+9f9PQgmX3VgjJerNjXr1zXWXDJfFE31DxgsxddjcIgoBL9lwegOHHvwpzK1ecgH45xcJ0Z/40OgY8NITqXbQRfdgLrEGJCoyOQEbjb5PW5k2aOdn7LBxvDsH6Y8ax26v+EFMPh3G+xheh6bfoIRSK1b+44PfoDZoJ9NfJibOZ4Cq+wt/yOvpMYQDB/9CNo18wmA3RCLYjf2nAc7RO0PDYHSIq5QDWV+1awmXDKgIdRpYPpRtn9KFXQkpCeEc/lDTG+o6n7nC40wyjioyR6QmHGvNkMR4VfSoTKCTnFATyDpI1bqU2K7KNjUEsCYfwybFB8d6mjQ==""],""issuer"":""https://login.microsoftonline.com/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0""}]}"; + private static readonly string PaypalJwks = @"{ ""keys"": [ { ""kty"": ""RSA"", @@ -283,7 +281,7 @@ public void ReadJwks_Kid(string issuer, string json) } ] }"; - private static string GoogleJwks = @"{ + private static readonly string GoogleJwks = @"{ ""keys"": [ { ""kid"": ""6fb05f742366ee4cf4bcf49f984c487e45c8c83d"", @@ -303,8 +301,8 @@ public void ReadJwks_Kid(string issuer, string json) } ] }"; -#if NET461 - private static string EveOnlineJwks = @"{ +#if NET462 + private static readonly string EveOnlineJwks = @"{ ""keys"": [ { ""alg"": ""RS256"", @@ -447,7 +445,7 @@ public static IEnumerable GetJwksJson() }; // issue #427, https://login.eveonline.com/oauth/jwks -#if NET461 +#if NET462 yield return new object[] { "https://login.eveonline.com/oauth/jwks", diff --git a/test/JsonWebToken.Tests/KeyWrapper_EcdhKeyWrapperTests.cs b/test/JsonWebToken.Tests/KeyWrapper_EcdhKeyWrapperTests.cs index d7181de3..227e2ba0 100644 --- a/test/JsonWebToken.Tests/KeyWrapper_EcdhKeyWrapperTests.cs +++ b/test/JsonWebToken.Tests/KeyWrapper_EcdhKeyWrapperTests.cs @@ -1,4 +1,4 @@ -#if !NET461 +#if !NET462 using System; using System.Collections.Generic; using JsonWebToken.Cryptography; diff --git a/test/JsonWebToken.Tests/RsaJwkTests.cs b/test/JsonWebToken.Tests/RsaJwkTests.cs index 0b6726cc..3e8830e6 100644 --- a/test/JsonWebToken.Tests/RsaJwkTests.cs +++ b/test/JsonWebToken.Tests/RsaJwkTests.cs @@ -588,7 +588,7 @@ public static IEnumerable GetWrappingKeys() { yield return new object[] { PrivateRsa2048Key, EncryptionAlgorithm.A128CbcHS256, KeyManagementAlgorithm.Rsa1_5 }; yield return new object[] { PrivateRsa2048Key, EncryptionAlgorithm.A128CbcHS256, KeyManagementAlgorithm.RsaOaep }; -#if !NET461 && !NET47 +#if !NET462 && !NET47 yield return new object[] { PrivateRsa2048Key, EncryptionAlgorithm.A128CbcHS256, KeyManagementAlgorithm.RsaOaep256 }; yield return new object[] { PrivateRsa2048Key, EncryptionAlgorithm.A128CbcHS256, KeyManagementAlgorithm.RsaOaep384 }; yield return new object[] { PrivateRsa2048Key, EncryptionAlgorithm.A128CbcHS256, KeyManagementAlgorithm.RsaOaep512 }; From f90f3ee3c6d7cbed4b3daf2c86e25b771428d05f Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 22:04:45 +0200 Subject: [PATCH 22/34] Nits --- .editorconfig | 4 ++ Jwt.sln | 17 ++++--- perf/Sandbox/Dictionary_TryGetValue.cs | 2 +- samples/BinaryJwtCreationSample/Program.cs | 2 +- src/JsonWebToken/CompressionAlgorithm.cs | 4 +- .../Cryptography/EllipticalCurveNames.cs | 8 +-- src/JsonWebToken/ECJwk.cs | 30 +++++------- src/JsonWebToken/EncryptionAlgorithm.cs | 2 +- src/JsonWebToken/Internal/ObjectPool.cs | 2 +- src/JsonWebToken/Jwk.cs | 49 ++++++------------- src/JsonWebToken/Jwks.cs | 9 ++-- src/JsonWebToken/KeyManagementAlgorithm.cs | 4 +- src/JsonWebToken/PasswordBasedJwk.cs | 2 +- .../Reader/JwksHttpKeyProvider.cs | 4 +- .../Reader/JwtHeaderDocumentCache.cs | 5 +- .../Reader/SignatureValidationPolicy.cs | 2 +- src/JsonWebToken/RsaJwk.cs | 20 ++++---- src/JsonWebToken/SignatureAlgorithm.cs | 2 +- src/JsonWebToken/Writer/JwsDescriptor.cs | 2 +- src/JsonWebToken/Writer/LruJwtHeaderCache.cs | 10 +--- src/KeyVault/KeyVaultKeyProvider.cs | 2 +- .../Verifiers/CodeFixVerifier.cs | 4 +- .../JsonWebTokenWriterTests.cs | 4 +- 23 files changed, 80 insertions(+), 110 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..b38a1f27 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# IDE0090: Utiliser 'new(...)' +dotnet_diagnostic.IDE0090.severity = none diff --git a/Jwt.sln b/Jwt.sln index 765beec7..b932ddaf 100644 --- a/Jwt.sln +++ b/Jwt.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28531.58 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BD2706C5-6C57-484D-89C8-A0CF5F8E3D19}" ProjectSection(SolutionItems) = preProject @@ -24,6 +24,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JsonWebToken.KeyVault", "sr EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{81504C49-6E6B-499F-B2EE-10C5E5B69614}" ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig Benchmark.md = Benchmark.md .github\workflows\benchmarks.yml = .github\workflows\benchmarks.yml BreakingChanges.md = BreakingChanges.md @@ -93,21 +94,21 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{45F5CD67-C docs\Performance_considerations.md = docs\Performance_considerations.md docs\Security_considerations.md = docs\Security_considerations.md docs\Validate_JWE.md = docs\Validate_JWE.md - docs\validate_jwe_allocated.png = docs\validate_jwe_allocated.png - docs\validate_jwe_ops.png = docs\validate_jwe_ops.png docs\validate_jwec_allocated.png = docs\validate_jwec_allocated.png docs\validate_jwec_ops.png = docs\validate_jwec_ops.png + docs\validate_jwe_allocated.png = docs\validate_jwe_allocated.png + docs\validate_jwe_ops.png = docs\validate_jwe_ops.png + docs\validate_jwsi_allocated.png = docs\validate_jwsi_allocated.png + docs\validate_jwsi_ops.png = docs\validate_jwsi_ops.png docs\validate_jws_allocated.png = docs\validate_jws_allocated.png docs\Validate_JWS_EC.md = docs\Validate_JWS_EC.md docs\Validate_JWS_HMAC.md = docs\Validate_JWS_HMAC.md docs\validate_jws_ops.png = docs\validate_jws_ops.png docs\Validate_JWS_RSA.md = docs\Validate_JWS_RSA.md - docs\validate_jwsi_allocated.png = docs\validate_jwsi_allocated.png - docs\validate_jwsi_ops.png = docs\validate_jwsi_ops.png - docs\write_jwe_allocated.png = docs\write_jwe_allocated.png - docs\write_jwe_ops.png = docs\write_jwe_ops.png docs\write_jwec_allocated.png = docs\write_jwec_allocated.png docs\write_jwec_ops.png = docs\write_jwec_ops.png + docs\write_jwe_allocated.png = docs\write_jwe_allocated.png + docs\write_jwe_ops.png = docs\write_jwe_ops.png docs\write_jws_allocated.png = docs\write_jws_allocated.png docs\write_jws_ops.png = docs\write_jws_ops.png EndProjectSection diff --git a/perf/Sandbox/Dictionary_TryGetValue.cs b/perf/Sandbox/Dictionary_TryGetValue.cs index e0ff1b8e..024a2a7c 100644 --- a/perf/Sandbox/Dictionary_TryGetValue.cs +++ b/perf/Sandbox/Dictionary_TryGetValue.cs @@ -341,7 +341,7 @@ private void Resize(int newSize) public void Dispose() { var entries = _entries; - if (!(entries is null)) + if (entries is not null) { for (int i = 0; i < _count; i++) { diff --git a/samples/BinaryJwtCreationSample/Program.cs b/samples/BinaryJwtCreationSample/Program.cs index 701ae626..ff1ca9c2 100644 --- a/samples/BinaryJwtCreationSample/Program.cs +++ b/samples/BinaryJwtCreationSample/Program.cs @@ -11,7 +11,7 @@ static void Main() var encryptionKey = SymmetricJwk.FromBase64Url("R9MyWaEoyiMYViVWo8Fk4T"); // Creates a JWE descriptor with all its properties - var payload = new byte[] { 76, 105, 102, 101, 32, 108, 111, 110, 103, 32, 97, 110, 100, 32, 112, 114, 111, 115, 112, 101, 114, 46 }; + var payload = "Life long and prosper."u8.ToArray(); var descriptor = new BinaryJweDescriptor(encryptionKey, KeyManagementAlgorithm.A128KW, EncryptionAlgorithm.A128CbcHS256) { Payload = payload diff --git a/src/JsonWebToken/CompressionAlgorithm.cs b/src/JsonWebToken/CompressionAlgorithm.cs index fbb6237f..1845347d 100644 --- a/src/JsonWebToken/CompressionAlgorithm.cs +++ b/src/JsonWebToken/CompressionAlgorithm.cs @@ -64,7 +64,7 @@ public override bool Equals(object? obj) /// Determines whether two specified objects have the same value. public bool Equals(CompressionAlgorithm? other) - => other is null ? false : Id == other.Id; + => other is not null && Id == other.Id; /// Returns the hash code for this . public override int GetHashCode() @@ -194,7 +194,7 @@ public static bool TryParse(string? value, [NotNullWhen(true)] out CompressionAl /// Cast the into its array representation. public static explicit operator byte[]?(CompressionAlgorithm? value) - => value is null ? null : value._utf8Name.EncodedUtf8Bytes.ToArray(); + => value?._utf8Name.EncodedUtf8Bytes.ToArray(); /// public override string ToString() diff --git a/src/JsonWebToken/Cryptography/EllipticalCurveNames.cs b/src/JsonWebToken/Cryptography/EllipticalCurveNames.cs index 666456d5..b5726d30 100644 --- a/src/JsonWebToken/Cryptography/EllipticalCurveNames.cs +++ b/src/JsonWebToken/Cryptography/EllipticalCurveNames.cs @@ -11,16 +11,16 @@ namespace JsonWebToken public static class EllipticalCurveNames { /// 'P-256'. - public static readonly JsonEncodedText P256 = JsonEncodedText.Encode(new byte[] { (byte)'P', (byte)'-', (byte)'2', (byte)'5', (byte)'6' }); + public static readonly JsonEncodedText P256 = JsonEncodedText.Encode("P-256"u8); /// 'P-384'. - public static readonly JsonEncodedText P384 = JsonEncodedText.Encode(new byte[] { (byte)'P', (byte)'-', (byte)'3', (byte)'8', (byte)'4' }); + public static readonly JsonEncodedText P384 = JsonEncodedText.Encode("P-384"u8); /// 'P-521'. - public static readonly JsonEncodedText P521 = JsonEncodedText.Encode(new byte[] { (byte)'P', (byte)'-', (byte)'5', (byte)'2', (byte)'1' }); + public static readonly JsonEncodedText P521 = JsonEncodedText.Encode("P-521"u8); /// 'secp256k1'. - public static readonly JsonEncodedText Secp256k1 = JsonEncodedText.Encode(new byte[] { (byte)'s', (byte)'e', (byte)'c', (byte)'p', (byte)'2', (byte)'5', (byte)'6', (byte)'k', (byte)'1' }); + public static readonly JsonEncodedText Secp256k1 = JsonEncodedText.Encode("secp256k1"u8); /// Gets all the well-known curve names. public static JsonEncodedText[] All => new[] { P256, P384, P521, Secp256k1 }; diff --git a/src/JsonWebToken/ECJwk.cs b/src/JsonWebToken/ECJwk.cs index bcdb8c7b..a72dbd24 100644 --- a/src/JsonWebToken/ECJwk.cs +++ b/src/JsonWebToken/ECJwk.cs @@ -316,7 +316,7 @@ private void Initialize(EllipticalCurve crv, byte[] d, byte[] x, byte[] y) } /// - public override bool HasPrivateKey => !(_parameters.D is null); + public override bool HasPrivateKey => _parameters.D is not null; /// public override JsonEncodedText Kty => JwkTypeNames.EllipticCurve; @@ -505,11 +505,11 @@ public override Jwk AsPublicKey() Q = _parameters.Q }; ECJwk publicKey; - if (!(KeyManagementAlgorithm is null)) + if (KeyManagementAlgorithm is not null) { publicKey = FromParameters(publicParameters, KeyManagementAlgorithm, computeThumbprint: false); } - else if (!(SignatureAlgorithm is null)) + else if (SignatureAlgorithm is not null) { publicKey = FromParameters(publicParameters, SignatureAlgorithm, computeThumbprint: false); } @@ -522,10 +522,10 @@ public override Jwk AsPublicKey() return publicKey; } - private static ReadOnlySpan StartCanonicalizeValue => new byte[] { (byte)'{', (byte)'"', (byte)'c', (byte)'r', (byte)'v', (byte)'"', (byte)':', (byte)'"' }; - private static ReadOnlySpan Middle1CanonicalizeValue => new byte[] { (byte)'"', (byte)',', (byte)'"', (byte)'k', (byte)'t', (byte)'y', (byte)'"', (byte)':', (byte)'"', (byte)'E', (byte)'C', (byte)'"', (byte)',', (byte)'"', (byte)'x', (byte)'"', (byte)':', (byte)'"' }; - private static ReadOnlySpan Middle2CanonicalizeValue => new byte[] { (byte)'"', (byte)',', (byte)'"', (byte)'y', (byte)'"', (byte)':', (byte)'"' }; - private static ReadOnlySpan EndCanonicalizeValue => new byte[] { (byte)'"', (byte)'}' }; + private static ReadOnlySpan StartCanonicalizeValue => "{\"crv\":\""u8; + private static ReadOnlySpan Middle1CanonicalizeValue => "\",\"kty\":\"EC\",\"x\":\""u8; + private static ReadOnlySpan Middle2CanonicalizeValue => "\",\"y\":\""u8; + private static ReadOnlySpan EndCanonicalizeValue => "\"}"u8; /// protected internal override void Canonicalize(Span buffer) @@ -770,7 +770,7 @@ internal static ECJwk FromJwtElement(JwtElement json) public new static ECJwk FromPem(string pem) { Jwk jwk = Jwk.FromPem(pem); - if (!(jwk is ECJwk ecJwk)) + if (jwk is not ECJwk ecJwk) { jwk.Dispose(); ThrowHelper.ThrowInvalidOperationException_UnexpectedKeyType(jwk, JwkTypeNames.EllipticCurve.ToString()); @@ -829,7 +829,7 @@ internal static ECJwk FromJsonReaderFast(ref Utf8JsonReader reader) } } - if (!(reader.TokenType is JsonTokenType.EndObject)) + if (reader.TokenType is not JsonTokenType.EndObject) { ThrowHelper.ThrowArgumentException_MalformedKey(); } @@ -840,10 +840,7 @@ internal static ECJwk FromJsonReaderFast(ref Utf8JsonReader reader) #if !NETSTANDARD2_0 internal ECDiffieHellman CreateEcdhKey() { - if (_ecdhKey is null) - { - _ecdhKey = ECDiffieHellman.Create(_parameters); - } + _ecdhKey ??= ECDiffieHellman.Create(_parameters); return _ecdhKey; } @@ -876,7 +873,7 @@ public override bool Equals(Jwk? other) return true; } - if (!(other is ECJwk key)) + if (other is not ECJwk key) { return false; } @@ -907,10 +904,7 @@ public override void Dispose() CryptographicOperations.ZeroMemory(_parameters.Q.X); CryptographicOperations.ZeroMemory(_parameters.Q.Y); #if !NETSTANDARD2_0 - if (!(_ecdhKey is null)) - { - _ecdhKey.Dispose(); - } + _ecdhKey?.Dispose(); #endif } diff --git a/src/JsonWebToken/EncryptionAlgorithm.cs b/src/JsonWebToken/EncryptionAlgorithm.cs index 86cbc43a..3b991d2e 100644 --- a/src/JsonWebToken/EncryptionAlgorithm.cs +++ b/src/JsonWebToken/EncryptionAlgorithm.cs @@ -329,7 +329,7 @@ public override bool Equals(object? obj) /// Determines whether two specified objects have the same value. public bool Equals(EncryptionAlgorithm? other) - => !(other is null) && _id == other._id; + => other is not null && _id == other._id; /// Returns the hash code for this . public override int GetHashCode() diff --git a/src/JsonWebToken/Internal/ObjectPool.cs b/src/JsonWebToken/Internal/ObjectPool.cs index 640e5e87..608bfca6 100644 --- a/src/JsonWebToken/Internal/ObjectPool.cs +++ b/src/JsonWebToken/Internal/ObjectPool.cs @@ -68,7 +68,7 @@ public T Get() for (var i = 0; i < items.Length; i++) { item = items[i].Element; - if (!(item is null) && Interlocked.CompareExchange(ref items[i].Element, null, item) == item) + if (item is not null && Interlocked.CompareExchange(ref items[i].Element, null, item) == item) { return item; } diff --git a/src/JsonWebToken/Jwk.cs b/src/JsonWebToken/Jwk.cs index 173b44d2..fa6f1460 100644 --- a/src/JsonWebToken/Jwk.cs +++ b/src/JsonWebToken/Jwk.cs @@ -107,10 +107,7 @@ public IList KeyOps { get { - if (_keyOps == null) - { - _keyOps = new List(); - } + _keyOps ??= new List(); return _keyOps; } @@ -139,10 +136,7 @@ public List X5c { get { - if (_x5c == null) - { - _x5c = new List(); - } + _x5c ??= new List(); return _x5c; } @@ -230,7 +224,7 @@ internal SignatureAlgorithm? SignatureAlgorithm var alg = Alg; if (!alg.EncodedUtf8Bytes.IsEmpty) { - SignatureAlgorithm.TryParse(alg.EncodedUtf8Bytes, out _signatureAlgorithm); + _ = SignatureAlgorithm.TryParse(alg.EncodedUtf8Bytes, out _signatureAlgorithm); } } @@ -277,7 +271,7 @@ internal KeyManagementAlgorithm? KeyManagementAlgorithm var alg = Alg; if (!alg.EncodedUtf8Bytes.IsEmpty) { - KeyManagementAlgorithm.TryParse(alg.EncodedUtf8Bytes, out _keyManagementAlgorithm); + _ = KeyManagementAlgorithm.TryParse(alg.EncodedUtf8Bytes, out _keyManagementAlgorithm); } } @@ -431,7 +425,7 @@ public void Serialize(IBufferWriter bufferWriter) /// true if the is available for the requested ; false otherwise. public bool TryGetSigner(SignatureAlgorithm? algorithm, [NotNullWhen(true)] out Signer? signer) { - if (!(algorithm is null)) + if (algorithm is not null) { int algorithmId = (int)algorithm.Id; var signers = _signers; @@ -480,7 +474,7 @@ public bool TryGetSigner(SignatureAlgorithm? algorithm, [NotNullWhen(true)] out /// true if the is available for the requested ; false otherwise. public bool TryGetSignatureVerifier(SignatureAlgorithm? algorithm, [NotNullWhen(true)] out SignatureVerifier? signatureVerifier) { - if (!(algorithm is null)) + if (algorithm is not null) { int algorithmId = (int)algorithm.Id; var signatureVerifiers = _signatureVerifiers; @@ -529,7 +523,7 @@ public bool TryGetSignatureVerifier(SignatureAlgorithm? algorithm, [NotNullWhen( /// The provided . null if return false public bool TryGetKeyWrapper(EncryptionAlgorithm? encryptionAlgorithm, KeyManagementAlgorithm? algorithm, [NotNullWhen(true)] out KeyWrapper? keyWrapper) { - if (!(encryptionAlgorithm is null) && !(algorithm is null)) + if (encryptionAlgorithm is not null && algorithm is not null) { var keyWrappers = _keyWrappers; var algorithmKey = encryptionAlgorithm.ComputeKey(algorithm); @@ -581,7 +575,7 @@ public bool TryGetKeyWrapper(EncryptionAlgorithm? encryptionAlgorithm, KeyManage /// The provided . null if return false public bool TryGetKeyUnwrapper(EncryptionAlgorithm? encryptionAlgorithm, KeyManagementAlgorithm? algorithm, [NotNullWhen(true)] out KeyUnwrapper? keyUnwrapper) { - if (!(encryptionAlgorithm is null) && !(algorithm is null)) + if (encryptionAlgorithm is not null && algorithm is not null) { var keyUnwrappers = _keyUnwrappers; var algorithmKey = encryptionAlgorithm.ComputeKey(algorithm); @@ -769,7 +763,7 @@ public static bool TryReadPrivateKeyFromX509Certificate(X509Certificate2 certifi } using var rsa = certificate.GetRSAPrivateKey(); - if (!(rsa is null)) + if (rsa is not null) { var rsaParameters = rsa.ExportParameters(true); key = RsaJwk.FromParameters(rsaParameters, computeThumbprint: false); @@ -778,7 +772,7 @@ public static bool TryReadPrivateKeyFromX509Certificate(X509Certificate2 certifi else { using var ecdsa = certificate.GetECDsaPrivateKey(); - if (!(ecdsa is null)) + if (ecdsa is not null) { var ecParameters = ecdsa.ExportParameters(true); key = ECJwk.FromParameters(ecParameters, computeThumbprint: false); @@ -809,7 +803,7 @@ public static bool TryReadPublicKeyFromX509Certificate(X509Certificate2 certific key = null; using var rsa = certificate.GetRSAPublicKey(); - if (!(rsa is null)) + if (rsa is not null) { var rsaParameters = rsa.ExportParameters(false); key = RsaJwk.FromParameters(rsaParameters, computeThumbprint: false); @@ -818,7 +812,7 @@ public static bool TryReadPublicKeyFromX509Certificate(X509Certificate2 certific else { using var ecdsa = certificate.GetECDsaPublicKey(); - if (!(ecdsa is null)) + if (ecdsa is not null) { var ecParameters = ecdsa.ExportParameters(false); key = ECJwk.FromParameters(ecParameters, computeThumbprint: false); @@ -1605,26 +1599,15 @@ internal bool CanUseForKeyWrapping(JwtElement keyManagementAlgorithm) public virtual void Dispose() { GC.SuppressFinalize(this); - if (_signers != null) - { - _signers.Dispose(); - } - - if (_keyWrappers != null) - { - _keyWrappers.Dispose(); - } - - if (_keyUnwrappers != null) - { - _keyUnwrappers.Dispose(); - } + _signers?.Dispose(); + _keyWrappers?.Dispose(); + _keyUnwrappers?.Dispose(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void WriteOptionalBase64UrlProperty(Utf8JsonWriter writer, Span buffer, byte[]? value, JsonEncodedText propertyName) { - if (!(value is null)) + if (value is not null) { WriteBase64UrlProperty(writer, buffer, value, propertyName); } diff --git a/src/JsonWebToken/Jwks.cs b/src/JsonWebToken/Jwks.cs index 5b02f9cd..4093cc7c 100644 --- a/src/JsonWebToken/Jwks.cs +++ b/src/JsonWebToken/Jwks.cs @@ -237,10 +237,7 @@ private string DebuggerDisplay() internal KeyValuePair[] GetIdentifiedKeys() { - if (_identifiedKeys is null) - { - _identifiedKeys = InitializeIdentifiedKeys(); - } + _identifiedKeys ??= InitializeIdentifiedKeys(); return _identifiedKeys; } @@ -555,7 +552,7 @@ public static Jwks FromJson(string issuer, ReadOnlySpan json) jwks.Add(jwk); } - if (!(reader.TokenType is JsonTokenType.EndArray) || !reader.Read()) + if (reader.TokenType is not JsonTokenType.EndArray || !reader.Read()) { ThrowHelper.ThrowInvalidOperationException_MalformedJwks(); } @@ -585,7 +582,7 @@ public static Jwks FromJson(string issuer, ReadOnlySpan json) } } - if (!(reader.TokenType is JsonTokenType.EndObject)) + if (reader.TokenType is not JsonTokenType.EndObject) { ThrowHelper.ThrowInvalidOperationException_MalformedJwks(); } diff --git a/src/JsonWebToken/KeyManagementAlgorithm.cs b/src/JsonWebToken/KeyManagementAlgorithm.cs index 149fc09d..1838af37 100644 --- a/src/JsonWebToken/KeyManagementAlgorithm.cs +++ b/src/JsonWebToken/KeyManagementAlgorithm.cs @@ -259,7 +259,7 @@ public override bool Equals(object? obj) /// Determines whether two specified objects have the same value. public bool Equals(KeyManagementAlgorithm? other) - => other is null ? false : _id == other._id; + => other is not null && _id == other._id; /// Returns the hash code for this . public override int GetHashCode() @@ -337,7 +337,7 @@ public override int GetHashCode() /// Cast the into its array representation. public static explicit operator byte[]?(KeyManagementAlgorithm? value) - => value is null ? null : value._utf8Name.EncodedUtf8Bytes.ToArray(); + => value?._utf8Name.EncodedUtf8Bytes.ToArray(); /// public override string ToString() diff --git a/src/JsonWebToken/PasswordBasedJwk.cs b/src/JsonWebToken/PasswordBasedJwk.cs index 93ec5080..b7a29787 100644 --- a/src/JsonWebToken/PasswordBasedJwk.cs +++ b/src/JsonWebToken/PasswordBasedJwk.cs @@ -160,7 +160,7 @@ public override bool Equals(Jwk? other) return true; } - if (!(other is PasswordBasedJwk key)) + if (other is not PasswordBasedJwk key) { return false; } diff --git a/src/JsonWebToken/Reader/JwksHttpKeyProvider.cs b/src/JsonWebToken/Reader/JwksHttpKeyProvider.cs index 3e21c0f2..c7c9abed 100644 --- a/src/JsonWebToken/Reader/JwksHttpKeyProvider.cs +++ b/src/JsonWebToken/Reader/JwksHttpKeyProvider.cs @@ -11,8 +11,8 @@ namespace JsonWebToken /// Represents a that retrieve the key set from an HTTP resource as JWKS. public sealed class JwksHttpKeyProvider : CachedKeyProvider { - private static ReadOnlySpan IssuerName => new byte[6] { (byte)'i', (byte)'s', (byte)'s', (byte)'u', (byte)'e', (byte)'r' }; - private static ReadOnlySpan JwksUriName => new byte[8] { (byte)'j', (byte)'w', (byte)'k', (byte)'s', (byte)'_', (byte)'u', (byte)'r', (byte)'i' }; + private static ReadOnlySpan IssuerName => "issuer"u8; + private static ReadOnlySpan JwksUriName => "jwks_uri"u8; private readonly string _issuer; private readonly Func _documentRetrieverFactory; diff --git a/src/JsonWebToken/Reader/JwtHeaderDocumentCache.cs b/src/JsonWebToken/Reader/JwtHeaderDocumentCache.cs index 91221adb..094a578c 100644 --- a/src/JsonWebToken/Reader/JwtHeaderDocumentCache.cs +++ b/src/JsonWebToken/Reader/JwtHeaderDocumentCache.cs @@ -98,10 +98,7 @@ public void AddHeader(ReadOnlySpan rawHeader, JwtHeaderDocument header) } _head = node; - if (_tail is null) - { - _tail = node; - } + _tail ??= node; } finally { diff --git a/src/JsonWebToken/Reader/SignatureValidationPolicy.cs b/src/JsonWebToken/Reader/SignatureValidationPolicy.cs index dbe9478c..61f9292a 100644 --- a/src/JsonWebToken/Reader/SignatureValidationPolicy.cs +++ b/src/JsonWebToken/Reader/SignatureValidationPolicy.cs @@ -176,7 +176,7 @@ public override bool TryValidateSignature(JwtHeaderDocument header, JwtPayloadDo if (key.CanUseForSignature(algElement)) { var alg = algorithm ?? key.SignatureAlgorithm; - if (!(alg is null)) + if (alg is not null) { if (key.TryGetSignatureVerifier(alg, out var signatureVerifier)) { diff --git a/src/JsonWebToken/RsaJwk.cs b/src/JsonWebToken/RsaJwk.cs index 8d6bad40..54f42386 100644 --- a/src/JsonWebToken/RsaJwk.cs +++ b/src/JsonWebToken/RsaJwk.cs @@ -382,7 +382,7 @@ private void Initialize(byte[] n, byte[] e) } /// - public override bool HasPrivateKey => !(_parameters.D is null); + public override bool HasPrivateKey => _parameters.D is not null; /// public override JsonEncodedText Kty => JwkTypeNames.Rsa; @@ -564,11 +564,11 @@ public override Jwk AsPublicKey() }; RsaJwk publicKey; - if (!(KeyManagementAlgorithm is null)) + if (KeyManagementAlgorithm is not null) { publicKey = FromParameters(publicParameters, KeyManagementAlgorithm, computeThumbprint: false); } - else if (!(SignatureAlgorithm is null)) + else if (SignatureAlgorithm is not null) { publicKey = FromParameters(publicParameters, SignatureAlgorithm, computeThumbprint: false); } @@ -857,7 +857,7 @@ public static RsaJwk FromParameters(in RSAParameters parameters, bool computeThu public new static RsaJwk FromPem(string pem) { AsymmetricJwk jwk = PemParser.Read(pem); - if (!(jwk is RsaJwk rsaJwk)) + if (jwk is not RsaJwk rsaJwk) { jwk.Dispose(); ThrowHelper.ThrowInvalidOperationException_UnexpectedKeyType(jwk, JwkTypeNames.Rsa.ToString()); @@ -867,9 +867,9 @@ public static RsaJwk FromParameters(in RSAParameters parameters, bool computeThu return rsaJwk; } - private static ReadOnlySpan StartCanonicalizeValue => new byte[] { (byte)'{', (byte)'"', (byte)'e', (byte)'"', (byte)':', (byte)'"' }; - private static ReadOnlySpan MiddleCanonicalizeValue => new byte[] { (byte)'"', (byte)',', (byte)'"', (byte)'k', (byte)'t', (byte)'y', (byte)'"', (byte)':', (byte)'"', (byte)'R', (byte)'S', (byte)'A', (byte)'"', (byte)',', (byte)'"', (byte)'n', (byte)'"', (byte)':', (byte)'"' }; - private static ReadOnlySpan EndCanonicalizeValue => new byte[] { (byte)'"', (byte)'}' }; + private static ReadOnlySpan StartCanonicalizeValue => "{\"e\":\""u8; + private static ReadOnlySpan MiddleCanonicalizeValue => "\",\"kty\":\"RSA\",\"n\":\""u8; + private static ReadOnlySpan EndCanonicalizeValue => "\"}"u8; /// protected internal override void Canonicalize(Span buffer) @@ -905,7 +905,7 @@ internal static Jwk FromJsonReaderFast(ref Utf8JsonReader reader) while (reader.Read()) { - if (!(reader.TokenType is JsonTokenType.PropertyName)) + if (reader.TokenType is not JsonTokenType.PropertyName) { break; } @@ -945,7 +945,7 @@ internal static Jwk FromJsonReaderFast(ref Utf8JsonReader reader) } } - if (!(reader.TokenType is JsonTokenType.EndObject)) + if (reader.TokenType is not JsonTokenType.EndObject) { ThrowHelper.ThrowArgumentException_MalformedKey(); } @@ -1032,7 +1032,7 @@ public override bool Equals(Jwk? other) return true; } - if (!(other is RsaJwk key)) + if (other is not RsaJwk key) { return false; } diff --git a/src/JsonWebToken/SignatureAlgorithm.cs b/src/JsonWebToken/SignatureAlgorithm.cs index bd8caaa4..6fc7a96a 100644 --- a/src/JsonWebToken/SignatureAlgorithm.cs +++ b/src/JsonWebToken/SignatureAlgorithm.cs @@ -145,7 +145,7 @@ public override bool Equals(object? obj) /// Determines whether two specified objects have the same value. public bool Equals(SignatureAlgorithm? other) - => other is null ? false : _id == other._id; + => other is not null && _id == other._id; /// Returns the hash code for this . public override int GetHashCode() diff --git a/src/JsonWebToken/Writer/JwsDescriptor.cs b/src/JsonWebToken/Writer/JwsDescriptor.cs index ba128400..5387b581 100644 --- a/src/JsonWebToken/Writer/JwsDescriptor.cs +++ b/src/JsonWebToken/Writer/JwsDescriptor.cs @@ -94,7 +94,7 @@ public override void Encode(EncodingContext context) { var key = _signingKey; var alg = _alg; - if (!(key is null) && key.TryGetSigner(alg, out var signer)) + if (key is not null && key.TryGetSigner(alg, out var signer)) { if (context.TokenLifetimeInSeconds != 0 || context.GenerateIssuedTime) { diff --git a/src/JsonWebToken/Writer/LruJwtHeaderCache.cs b/src/JsonWebToken/Writer/LruJwtHeaderCache.cs index 5bc55a71..729df3c0 100644 --- a/src/JsonWebToken/Writer/LruJwtHeaderCache.cs +++ b/src/JsonWebToken/Writer/LruJwtHeaderCache.cs @@ -218,10 +218,7 @@ public void AddHeader(JwtHeader header, KeyManagementAlgorithm alg, EncryptionAl _head = node; } - if (_tail is null) - { - _tail = node; - } + _tail ??= node; } finally { @@ -511,10 +508,7 @@ public void AddHeader(JwtHeader header, SignatureAlgorithm alg, JsonEncodedText _head = node; } - if (_tail is null) - { - _tail = node; - } + _tail ??= node; } finally { diff --git a/src/KeyVault/KeyVaultKeyProvider.cs b/src/KeyVault/KeyVaultKeyProvider.cs index 74dac170..6b22c8f9 100644 --- a/src/KeyVault/KeyVaultKeyProvider.cs +++ b/src/KeyVault/KeyVaultKeyProvider.cs @@ -76,7 +76,7 @@ protected override Jwks GetKeysFromSource() } #endif - if (!(key is null)) + if (key is not null) { key.Kid = JsonEncodedText.Encode(kvKey.Value.Key.Id); diff --git a/test/JsonWebToken.Analyzers.Test/Verifiers/CodeFixVerifier.cs b/test/JsonWebToken.Analyzers.Test/Verifiers/CodeFixVerifier.cs index 336f1057..8778c119 100644 --- a/test/JsonWebToken.Analyzers.Test/Verifiers/CodeFixVerifier.cs +++ b/test/JsonWebToken.Analyzers.Test/Verifiers/CodeFixVerifier.cs @@ -242,7 +242,7 @@ await GetSortedDiagnosticsFromDocumentsAsync(analyzer, new[] { doc }).ConfigureA }; var fixAllProvider = codeFixProvider.GetFixAllProvider(); var fixAllDiagnosticProvider = new FixAllDiagnosticProvider(codeFixProvider.FixableDiagnosticIds.ToImmutableHashSet(), getDocumentDiagnosticsAsync, getProjectDiagnosticsAsync); - if (equivalenceKey == null) equivalenceKey = codeFixProvider.GetType().Name; + equivalenceKey ??= codeFixProvider.GetType().Name; var fixAllContext = new FixAllContext(document, codeFixProvider, FixAllScope.Document, equivalenceKey, codeFixProvider.FixableDiagnosticIds, @@ -269,7 +269,7 @@ private async static Task VerifyFixAllAsync(string language, DiagnosticAnalyzer var project = CreateProject(oldSources, language, languageVersionCSharp, languageVersionVB); var compilerDiagnostics = (await Task.WhenAll(project.Documents.Select(d => GetCompilerDiagnosticsAsync(d))).ConfigureAwait(true)).SelectMany(d => d); var fixAllProvider = codeFixProvider.GetFixAllProvider(); - if (equivalenceKey == null) equivalenceKey = codeFixProvider.GetType().Name; + equivalenceKey ??= codeFixProvider.GetType().Name; FixAllContext fixAllContext; if (analyzer != null) { diff --git a/test/JsonWebToken.Tests/JsonWebTokenWriterTests.cs b/test/JsonWebToken.Tests/JsonWebTokenWriterTests.cs index f08b82c0..094e63c5 100644 --- a/test/JsonWebToken.Tests/JsonWebTokenWriterTests.cs +++ b/test/JsonWebToken.Tests/JsonWebTokenWriterTests.cs @@ -47,9 +47,9 @@ public void Write_Valid(string token) var result = Jwt.TryParse(value, policy, out var jwt); Assert.True(result); - if (!(descriptor is JwsDescriptor jwsPayload)) + if (descriptor is not JwsDescriptor jwsPayload) { - if (!(descriptor is JweDescriptor jwePayload)) + if (descriptor is not JweDescriptor jwePayload) { throw new Xunit.Sdk.IsNotTypeException(typeof(JwtDescriptor), descriptor); } From cd1e22835893e3bd62ddb49e1d61484f752c3fb2 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 22:37:58 +0200 Subject: [PATCH 23/34] update benchmark workflow --- .github/workflows/benchmarks.yml | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index da9b8de3..0dc5854c 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -19,27 +19,22 @@ jobs: NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages steps: - - uses: actions/checkout@master - - name: Setup dotnet '1.1.x' - uses: actions/setup-dotnet@v1 + - uses: actions/checkout@v4 + - name: Setup dotnet + uses: actions/setup-dotnet@v4 with: - dotnet-version: '2.1.x' - - name: Setup dotnet '3.1.x' - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '3.1.x' - - name: Setup dotnet '5.x' - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '5.0.100' + dotnet-version: | + 6.x + 7.x + 8.x - name: Install dependencies run: dotnet restore - name: Build run: dotnet build --configuration Release --no-restore - name: Validate Benchmark - run: dotnet run -c Release -f net5 -p ./perf/Benchmarks -- --filter JsonWebToken.Performance.Validate* --join + run: dotnet run -c Release -f net8 -p ./perf/Benchmarks -- --filter JsonWebToken.Performance.Validate* --join - name: Write Benchmark - run: dotnet run -c Release -f net5 -p ./perf/Benchmarks -- --filter JsonWebToken.Performance.Write* --join + run: dotnet run -c Release -f net8 -p ./perf/Benchmarks -- --filter JsonWebToken.Performance.Write* --join - name: Upload results uses: actions/upload-artifact@v2 with: From 62e6bb491de4f602d03df9299a0c3691e94bd017 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 22:45:41 +0200 Subject: [PATCH 24/34] fix warning --- .github/workflows/dotnetcore.yml | 2 +- perf/Benchmarks/WriteToken.cs | 18 +++++++++--------- test/JsonWebToken.Tests/SymmetricJwkTests.cs | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 1d4b167d..136ab5df 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -74,7 +74,7 @@ jobs: run: dotnet pack -c ${{ matrix.configuration }} --output=nuget_packed --no-build - name: Upload NuGet packages to Artifacts if: matrix.is-main - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: nuget-packages path: | diff --git a/perf/Benchmarks/WriteToken.cs b/perf/Benchmarks/WriteToken.cs index ecfe5ae7..94e4b729 100644 --- a/perf/Benchmarks/WriteToken.cs +++ b/perf/Benchmarks/WriteToken.cs @@ -163,7 +163,7 @@ public BenchmarkPayload(string name) JwtDescriptor = JwtPayloads[name]; JoseDescriptor = DictionaryPayloads[name]; WilsonDescriptor = WilsonPayloads[name]; - WilsonJwtDescriptor = Tokens.Payloads[name.Substring(name.LastIndexOf('6') - 1).Trim().Substring(0, 1)].ToString(); + WilsonJwtDescriptor = Tokens.Payloads[name.Substring(name.LastIndexOf('6') - 1).Trim()[..1]].ToString(); } public string Name { get; } @@ -198,7 +198,7 @@ private static Dictionary CreateJwtDescriptors() descriptor.Payload!.Add(property.Name, (long)property.Value); break; default: - descriptor.Payload!.Add(property.Name, (string)property.Value); + descriptor.Payload!.Add(property.Name, (string)property.Value!); break; } } @@ -220,7 +220,7 @@ private static Dictionary CreateJwtDescriptors() descriptor.Payload!.Add(property.Name, (long)property.Value); break; default: - descriptor.Payload!.Add(property.Name, (string)property.Value); + descriptor.Payload!.Add(property.Name, (string)property.Value!); break; } } @@ -242,7 +242,7 @@ private static Dictionary CreateJwtDescriptors() descriptor.Payload!.Add(property.Name, (long)property.Value); break; default: - descriptor.Payload!.Add(property.Name, (string)property.Value); + descriptor.Payload!.Add(property.Name, (string)property.Value!); break; } } @@ -285,7 +285,7 @@ private static Dictionary CreateWilsonDescripto case "exp": break; default: - descriptor.Subject.AddClaim(new Claim(property.Name, (string)property.Value)); + descriptor.Subject.AddClaim(new Claim(property.Name, (string)property.Value!)); break; } } @@ -312,7 +312,7 @@ private static Dictionary CreateWilsonDescripto case "exp": break; default: - descriptor.Subject.AddClaim(new Claim(property.Name, (string)property.Value)); + descriptor.Subject.AddClaim(new Claim(property.Name, (string)property.Value!)); break; } } @@ -340,7 +340,7 @@ private static Dictionary CreateWilsonDescripto case "exp": break; default: - descriptor.Subject.AddClaim(new Claim(property.Name, (string)property.Value)); + descriptor.Subject.AddClaim(new Claim(property.Name, (string)property.Value!)); break; } } @@ -369,7 +369,7 @@ private static Dictionary CreateWilsonDescripto case "exp": break; default: - descriptor.Subject.AddClaim(new Claim(property.Name, (string)property.Value)); + descriptor.Subject.AddClaim(new Claim(property.Name, (string)property.Value!)); break; } } @@ -400,7 +400,7 @@ private static Dictionary> CreateDictionaryDe descriptor.Add(property.Name, (long)property.Value); break; default: - descriptor.Add(property.Name, (string)property.Value); + descriptor.Add(property.Name, (string)property.Value!); break; } } diff --git a/test/JsonWebToken.Tests/SymmetricJwkTests.cs b/test/JsonWebToken.Tests/SymmetricJwkTests.cs index 99c61925..c5f1af97 100644 --- a/test/JsonWebToken.Tests/SymmetricJwkTests.cs +++ b/test/JsonWebToken.Tests/SymmetricJwkTests.cs @@ -28,7 +28,7 @@ public void Equal() key.Kid = JsonEncodedText.Encode("X"); copiedKey.Kid = JsonEncodedText.Encode("Y"); Assert.NotEqual(key, copiedKey); - + Assert.NotEqual(key, Jwk.None); } @@ -52,7 +52,7 @@ public override Signer CreateSigner_Succeed(Jwk key, SignatureAlgorithm alg) [InlineData("HS512")] public override void Canonicalize(string alg) { - var jwk = SymmetricJwk.GenerateKey(SignatureAlgorithm.HS256); + var jwk = SymmetricJwk.GenerateKey((SignatureAlgorithm)alg); var canonicalizedKey = (SymmetricJwk)CanonicalizeKey(jwk); Assert.NotEqual(0, canonicalizedKey.K.Length); } From 64f3f5bca13f528ed9fdf7f534619983fa627462 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 22:56:09 +0200 Subject: [PATCH 25/34] Fix warnings --- perf/Benchmarks/Internal/Tokens.cs | 16 +++++++++------- perf/Benchmarks/ValidateCompressedToken.cs | 7 ++++--- perf/Benchmarks/ValidateEncryptedToken.cs | 7 ++++--- perf/Benchmarks/ValidateInlnvalidToken.cs | 7 ++++--- perf/Benchmarks/ValidateSignedToken.cs | 7 ++++--- perf/Benchmarks/ValidateToken.cs | 7 ++++--- perf/Benchmarks/ValidateUnsignedToken.cs | 7 ++++--- 7 files changed, 33 insertions(+), 25 deletions(-) diff --git a/perf/Benchmarks/Internal/Tokens.cs b/perf/Benchmarks/Internal/Tokens.cs index 27050c7d..3a235082 100644 --- a/perf/Benchmarks/Internal/Tokens.cs +++ b/perf/Benchmarks/Internal/Tokens.cs @@ -108,7 +108,7 @@ private static IDictionary CreateDescriptors(IDictionary< descriptor.Payload!.Add(property.Name, (long)property.Value); break; default: - descriptor.Payload!.Add(property.Name, (string)property.Value); + descriptor.Payload!.Add(property.Name, (string)property.Value!); break; } } @@ -130,7 +130,7 @@ private static IDictionary CreateDescriptors(IDictionary< descriptor.Payload!.Add(property.Name, (long)property.Value); break; default: - descriptor.Payload!.Add(property.Name, (string)property.Value); + descriptor.Payload!.Add(property.Name, (string)property.Value!); break; } } @@ -152,7 +152,7 @@ private static IDictionary CreateDescriptors(IDictionary< descriptor.Payload!.Add(property.Name, (long)property.Value); break; default: - descriptor.Payload!.Add(property.Name, (string)property.Value); + descriptor.Payload!.Add(property.Name, (string)property.Value!); break; } } @@ -179,7 +179,7 @@ private static IDictionary CreateDescriptors(IDictionary< descriptor.Payload!.Add(property.Name, (long)property.Value); break; default: - descriptor.Payload!.Add(property.Name, (string)property.Value); + descriptor.Payload!.Add(property.Name, (string)property.Value!); break; } } @@ -312,10 +312,10 @@ private static JwsDescriptor CreateJws(Jwk signingKey, JObject descriptor, Token } - switch (kvp.Value.Type) + switch (kvp.Value?.Type) { case JTokenType.Object: - payload.Add(kvp.Key, (object)kvp.Value); + payload.Add(kvp.Key, kvp.Value); break; case JTokenType.Array: payload.Add(kvp.Key, (object[])(object)kvp.Value); @@ -327,7 +327,7 @@ private static JwsDescriptor CreateJws(Jwk signingKey, JObject descriptor, Token payload.Add(kvp.Key, (double)kvp.Value); break; case JTokenType.String: - payload.Add(kvp.Key, (string)kvp.Value); + payload.Add(kvp.Key, (string)kvp.Value!); break; case JTokenType.Boolean: payload.Add(kvp.Key, (bool)kvp.Value); @@ -335,6 +335,8 @@ private static JwsDescriptor CreateJws(Jwk signingKey, JObject descriptor, Token case JTokenType.Null: payload.Add(kvp.Key, (object)kvp.Value); break; + default: + break; } } diff --git a/perf/Benchmarks/ValidateCompressedToken.cs b/perf/Benchmarks/ValidateCompressedToken.cs index 42ce0aac..ee4b01be 100644 --- a/perf/Benchmarks/ValidateCompressedToken.cs +++ b/perf/Benchmarks/ValidateCompressedToken.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Security.Claims; +using System.Threading.Tasks; using BenchmarkDotNet.Attributes; namespace JsonWebToken.Performance @@ -18,7 +19,7 @@ public void Setup() var token = GetTokenValues().First(); JsonWebToken(token); Wilson(token); - WilsonJwt(token); + WilsonJwtAsync(token).Wait(); } [Benchmark(Baseline = true)] @@ -39,9 +40,9 @@ public override ClaimsPrincipal Wilson(BenchmarkToken token) [Benchmark] [ArgumentsSource(nameof(GetTokenValues))] - public override Microsoft.IdentityModel.Tokens.TokenValidationResult WilsonJwt(BenchmarkToken token) + public override async Task WilsonJwtAsync(BenchmarkToken token) { - return WilsonJwtCore(token.TokenString, wilsonParameters); + return await WilsonJwtCoreAsync(token.TokenString, wilsonParameters); } public override Dictionary jose_jwt(BenchmarkToken token) diff --git a/perf/Benchmarks/ValidateEncryptedToken.cs b/perf/Benchmarks/ValidateEncryptedToken.cs index eae3dcf9..331e8913 100644 --- a/perf/Benchmarks/ValidateEncryptedToken.cs +++ b/perf/Benchmarks/ValidateEncryptedToken.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Security.Claims; +using System.Threading.Tasks; using BenchmarkDotNet.Attributes; namespace JsonWebToken.Performance @@ -17,7 +18,7 @@ public void Setup() var token = GetTokenValues().First(); JsonWebToken(token); Wilson(token); - WilsonJwt(token); + WilsonJwtAsync(token).Wait(); //jose_jwt(token); // jose_jwt seems to not works } @@ -39,9 +40,9 @@ public override ClaimsPrincipal Wilson(BenchmarkToken token) [Benchmark] [ArgumentsSource(nameof(GetTokenValues))] - public override Microsoft.IdentityModel.Tokens.TokenValidationResult WilsonJwt(BenchmarkToken token) + public override async Task WilsonJwtAsync(BenchmarkToken token) { - return WilsonJwtCore(token.TokenString, wilsonParameters); + return await WilsonJwtCoreAsync(token.TokenString, wilsonParameters); } [Benchmark] diff --git a/perf/Benchmarks/ValidateInlnvalidToken.cs b/perf/Benchmarks/ValidateInlnvalidToken.cs index 8ecab7c4..50bbaf9c 100644 --- a/perf/Benchmarks/ValidateInlnvalidToken.cs +++ b/perf/Benchmarks/ValidateInlnvalidToken.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Security.Claims; +using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using Microsoft.IdentityModel.Tokens; @@ -18,7 +19,7 @@ public void Setup() var token = GetTokenValues().First(); JsonWebToken(token); Wilson(token); - WilsonJwt(token); + WilsonJwtAsync(token).Wait(); jose_jwt(token); Jwt_Net(token); } @@ -55,9 +56,9 @@ public override ClaimsPrincipal Wilson(BenchmarkToken token) [Benchmark] [ArgumentsSource(nameof(GetTokenValues))] - public override Microsoft.IdentityModel.Tokens.TokenValidationResult WilsonJwt(BenchmarkToken token) + public override async Task WilsonJwtAsync(BenchmarkToken token) { - return WilsonJwtCore(token.InvalidTokenString, wilsonParameters); + return await WilsonJwtCoreAsync(token.InvalidTokenString, wilsonParameters); } [Benchmark] diff --git a/perf/Benchmarks/ValidateSignedToken.cs b/perf/Benchmarks/ValidateSignedToken.cs index 0a81ba99..0162492a 100644 --- a/perf/Benchmarks/ValidateSignedToken.cs +++ b/perf/Benchmarks/ValidateSignedToken.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Security.Claims; +using System.Threading.Tasks; using BenchmarkDotNet.Attributes; namespace JsonWebToken.Performance @@ -16,7 +17,7 @@ public void Setup() var token = GetTokenValues().First(); JsonWebToken(token); Wilson(token); - WilsonJwt(token); + WilsonJwtAsync(token).Wait(); jose_jwt(token); Jwt_Net(token); } @@ -39,9 +40,9 @@ public override ClaimsPrincipal Wilson(BenchmarkToken token) [Benchmark] [ArgumentsSource(nameof(GetTokenValues))] - public override Microsoft.IdentityModel.Tokens.TokenValidationResult WilsonJwt(BenchmarkToken token) + public override async Task WilsonJwtAsync(BenchmarkToken token) { - return WilsonJwtCore(token.TokenString, wilsonParameters); + return await WilsonJwtCoreAsync(token.TokenString, wilsonParameters); } [Benchmark] diff --git a/perf/Benchmarks/ValidateToken.cs b/perf/Benchmarks/ValidateToken.cs index 597c63de..0883cca4 100644 --- a/perf/Benchmarks/ValidateToken.cs +++ b/perf/Benchmarks/ValidateToken.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Security.Claims; using System.Text; +using System.Threading.Tasks; using Jose; using JWT; using JWT.Algorithms; @@ -97,11 +98,11 @@ protected ClaimsPrincipal WilsonCore(string token, TokenValidationParameters par return Handler.ValidateToken(token, parameters, out var securityToken); } - public abstract Microsoft.IdentityModel.Tokens.TokenValidationResult WilsonJwt(BenchmarkToken token); + public abstract Task WilsonJwtAsync(BenchmarkToken token); - protected Microsoft.IdentityModel.Tokens.TokenValidationResult WilsonJwtCore(string token, TokenValidationParameters parameters) + protected async Task WilsonJwtCoreAsync(string token, TokenValidationParameters parameters) { - return Handler2.ValidateToken(token, parameters); + return await Handler2.ValidateTokenAsync(token, parameters); } public abstract Dictionary jose_jwt(BenchmarkToken token); diff --git a/perf/Benchmarks/ValidateUnsignedToken.cs b/perf/Benchmarks/ValidateUnsignedToken.cs index b2daf687..7aadc850 100644 --- a/perf/Benchmarks/ValidateUnsignedToken.cs +++ b/perf/Benchmarks/ValidateUnsignedToken.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Security.Claims; +using System.Threading.Tasks; using BenchmarkDotNet.Attributes; namespace JsonWebToken.Performance @@ -17,7 +18,7 @@ public void Setup() var token = GetTokenValues().First(); JsonWebToken(token); Wilson(token); - WilsonJwt(token); + WilsonJwtAsync(token).Wait(); jose_jwt(token); } @@ -39,9 +40,9 @@ public override ClaimsPrincipal Wilson(BenchmarkToken token) [Benchmark] [ArgumentsSource(nameof(GetTokenValues))] - public override Microsoft.IdentityModel.Tokens.TokenValidationResult WilsonJwt(BenchmarkToken token) + public override async Task WilsonJwtAsync(BenchmarkToken token) { - return WilsonJwtCore(token.TokenString, wilsonParametersWithoutSignature); + return await WilsonJwtCoreAsync(token.TokenString, wilsonParametersWithoutSignature); } [Benchmark] From de30c6c3e66305c58a0c122ab2d672e23b5e2d2d Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 23:15:40 +0200 Subject: [PATCH 26/34] update codecov --- .github/workflows/dotnetcore.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 136ab5df..cae5cd43 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -64,8 +64,8 @@ jobs: run: dotnet test -c ${{ matrix.configuration }} --no-build --collect:"XPlat Code Coverage" --settings coverlet.runsettings - name: Upload coverage to Codecov - if: matrix.is-netfx - uses: codecov/codecov-action@v1 + if: matrix.is-main + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} @@ -93,7 +93,7 @@ jobs: NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages steps: - name: Download generated NuGet packages - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: name: nuget-packages - name: Push packages to api.nuget.org From 5b82bc7a946a3b4a6b03e9f485a8eeec30b87e56 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 23:24:03 +0200 Subject: [PATCH 27/34] update gh workflow --- .github/workflows/dotnetcore.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index cae5cd43..26880af8 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -21,13 +21,12 @@ jobs: matrix: os: [ ubuntu-latest, windows-latest, macos-latest ] configuration: [ Debug, Release ] + dotnet-version: [ '6.x', '7.x', '8.x' ] include: - os: ubuntu-latest configuration: Release + dotnet-version: 8.x is-main: true - - os: windows-latest - configuration: Release - is-netfx: true env: DOTNET_CLI_TELEMETRY_OPTOUT: 1 DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 @@ -47,10 +46,7 @@ jobs: - name: Setup dotnet uses: actions/setup-dotnet@v4 with: - dotnet-version: | - 6.x - 7.x - 8.x + dotnet-version: ${{ matrix.dotnet-version }} - name: Restore dependencies run: dotnet restore @@ -61,7 +57,14 @@ jobs: - name: Test # disable macOS tests if: matrix.os != 'macos-latest' - run: dotnet test -c ${{ matrix.configuration }} --no-build --collect:"XPlat Code Coverage" --settings coverlet.runsettings + run: dotnet test -c ${{ matrix.configuration }} --no-build --collect:"XPlat Code Coverage" --settings coverlet.runsettings --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}" + + - name: Upload dotnet test results + uses: actions/upload-artifact@v4 + with: + name: dotnet-results-${{ matrix.dotnet-version }} + path: TestResults-${{ matrix.dotnet-version }} + if: ${{ always() }} - name: Upload coverage to Codecov if: matrix.is-main From e1329fa6b628df5d56ada76f373fa1c1dfda3c2d Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 23:25:16 +0200 Subject: [PATCH 28/34] fix --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 26880af8..4a213add 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -60,11 +60,11 @@ jobs: run: dotnet test -c ${{ matrix.configuration }} --no-build --collect:"XPlat Code Coverage" --settings coverlet.runsettings --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}" - name: Upload dotnet test results + if: ${{ always() }} uses: actions/upload-artifact@v4 with: name: dotnet-results-${{ matrix.dotnet-version }} path: TestResults-${{ matrix.dotnet-version }} - if: ${{ always() }} - name: Upload coverage to Codecov if: matrix.is-main From bf3a7f7577b7ce793738bff3ee6ba3a9dc4800ee Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 23:30:43 +0200 Subject: [PATCH 29/34] renable macos tests --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 4a213add..8747cac0 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -56,7 +56,7 @@ jobs: - name: Test # disable macOS tests - if: matrix.os != 'macos-latest' + # if: matrix.os != 'macos-latest' run: dotnet test -c ${{ matrix.configuration }} --no-build --collect:"XPlat Code Coverage" --settings coverlet.runsettings --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}" - name: Upload dotnet test results From dfebe105f851ee83f1833ca9b1b040322e04cc0c Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 23:33:47 +0200 Subject: [PATCH 30/34] fix --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 8747cac0..83b498d1 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -63,7 +63,7 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@v4 with: - name: dotnet-results-${{ matrix.dotnet-version }} + name: dotnet-results-${{ matrix.dotnet-version }}-${{ matrix.configuration }}-${{ matrix.os }} path: TestResults-${{ matrix.dotnet-version }} - name: Upload coverage to Codecov From dbe63dbda310c92b898ebebceb9b35993f612296 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 23:39:31 +0200 Subject: [PATCH 31/34] fix --- .github/workflows/dotnetcore.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 83b498d1..0c422c80 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -21,11 +21,9 @@ jobs: matrix: os: [ ubuntu-latest, windows-latest, macos-latest ] configuration: [ Debug, Release ] - dotnet-version: [ '6.x', '7.x', '8.x' ] include: - os: ubuntu-latest configuration: Release - dotnet-version: 8.x is-main: true env: DOTNET_CLI_TELEMETRY_OPTOUT: 1 @@ -46,7 +44,10 @@ jobs: - name: Setup dotnet uses: actions/setup-dotnet@v4 with: - dotnet-version: ${{ matrix.dotnet-version }} + dotnet-version: | + '6.x' + '7.x' + '8.x' - name: Restore dependencies run: dotnet restore @@ -57,14 +58,14 @@ jobs: - name: Test # disable macOS tests # if: matrix.os != 'macos-latest' - run: dotnet test -c ${{ matrix.configuration }} --no-build --collect:"XPlat Code Coverage" --settings coverlet.runsettings --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}" + run: dotnet test -c ${{ matrix.configuration }} --no-build --collect:"XPlat Code Coverage" --settings coverlet.runsettings --logger trx --results-directory "TestResults" - name: Upload dotnet test results if: ${{ always() }} uses: actions/upload-artifact@v4 with: - name: dotnet-results-${{ matrix.dotnet-version }}-${{ matrix.configuration }}-${{ matrix.os }} - path: TestResults-${{ matrix.dotnet-version }} + name: dotnet-results-${{ matrix.configuration }}-${{ matrix.os }} + path: TestResults - name: Upload coverage to Codecov if: matrix.is-main From 7333dd1fb7e4277e4d4514ebde98eb6e4d64a4c0 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 23:40:59 +0200 Subject: [PATCH 32/34] fix --- .github/workflows/dotnetcore.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 0c422c80..257c8fc4 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -45,9 +45,9 @@ jobs: uses: actions/setup-dotnet@v4 with: dotnet-version: | - '6.x' - '7.x' - '8.x' + 6.x + 7.x + 8.x - name: Restore dependencies run: dotnet restore From 4031fbdba8741b4bfe7b069fd1aefb987acd8b65 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 23:44:54 +0200 Subject: [PATCH 33/34] nits --- .github/workflows/dotnetcore.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 257c8fc4..a7bbb4de 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -35,7 +35,8 @@ jobs: DYLD_FALLBACK_LIBRARY_PATH: /usr/local/Cellar/openssl@1.1/ steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 # - name: Setup OpenSSL (macOS) # if: matrix.os == 'macos-latest' # run: | From bac5aa2ecce4054b813d22e939834577df619e50 Mon Sep 17 00:00:00 2001 From: ycrumeyrolle Date: Sun, 21 Jul 2024 23:53:21 +0200 Subject: [PATCH 34/34] fix macos --- test/JsonWebToken.Tests/ECJwkTests.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/JsonWebToken.Tests/ECJwkTests.cs b/test/JsonWebToken.Tests/ECJwkTests.cs index 9194c1d0..c6ad228b 100644 --- a/test/JsonWebToken.Tests/ECJwkTests.cs +++ b/test/JsonWebToken.Tests/ECJwkTests.cs @@ -156,8 +156,10 @@ public void GenerateKey(EllipticalCurve crv) var key2 = ECJwk.GeneratePrivateKey(crv.SupportedSignatureAlgorithm); Assert.NotNull(key2); } - - public static IEnumerable SupportedCurves => EllipticalCurve.SupportedCurves.Select(c => new object[] { c }).ToArray(); + public static IEnumerable SupportedCurves + => EllipticalCurve + .SupportedCurves + .Select(c => new object[] { c }).ToArray(); [Theory] [MemberData(nameof(GetWrappingKeys))] @@ -184,7 +186,9 @@ public override Signer CreateSigner_Failed(Jwk key, SignatureAlgorithm alg) [InlineData("ES256")] [InlineData("ES384")] [InlineData("ES512")] +#if !TARGET_MACOS [InlineData("ES256K")] +#endif public override void Canonicalize(string alg) { var jwk = ECJwk.GeneratePrivateKey((SignatureAlgorithm)alg);