-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds JsonWebToken Constructor that accepts Memory<char> (#2458)
* Add JWT ctor that accepts a span * Update YAML to build previews * Add ReadOnlySpan overloads * Add benchmark * Add ValidateAndGetOutputSize for spans * Remove duplication * Update benchmark * Remove duplicates * Update * Add benchmarks * Update * Replace ReadyOnlySpan with ReadOnlyMemory * Update test * Update benchmark naming * Move ArrayPool to JsonWebToken level * Update CreateHeaderClaimSet * Update benchmark for JWE to resolve error * Reduce duplication * Fix comment * Set _encodedTokenMemory as readonly * Remove unnecessary private method * Use Base64UrlEncoding.Decode with action * Use ValidateAndGetOutputSize(ReadOnlySpan<char> strSpan..) thoughout * Add tests * Revert change * Temporarily allow publishing to NuGet * use just `1` for preview * up version to 7.4.0 for preview * Separate JWS and JWE benchmarks * Re-add variable * Update test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenTests.cs Co-authored-by: Peter <[email protected]> * Update src/Microsoft.IdentityModel.JsonWebTokens/JsonWebToken.cs Co-authored-by: Peter <[email protected]> * Update test/Microsoft.IdentityModel.Tokens.Tests/Base64UrlEncodingTests.cs Co-authored-by: Peter <[email protected]> * Removed private method * Store ReadOnlySpan is a variable * Update benchmark * Cleanup * Fix CreateHeaderClaimSet and CreatePayloadClaimSet to avoid reading the end of the span * Add comment * Update benchmark --------- Co-authored-by: Sruthi Keerthi Rangavajhula <[email protected]> Co-authored-by: jennyf19 <[email protected]> Co-authored-by: Peter <[email protected]>
- Loading branch information
1 parent
d28f795
commit d5dc77e
Showing
13 changed files
with
374 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
benchmark/Microsoft.IdentityModel.Benchmarks/ReadJWETokenTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.IdentityModel.JsonWebTokens; | ||
using Microsoft.IdentityModel.Tokens; | ||
|
||
namespace Microsoft.IdentityModel.Benchmarks | ||
{ | ||
// dotnet run -c release -f net8.0 --filter Microsoft.IdentityModel.Benchmarks.ReadTokenTests* | ||
|
||
public class ReadJWETokenTests | ||
{ | ||
string _encryptedJWE; | ||
ReadOnlyMemory<char> _encryptedJWEAsMemory; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
var jsonWebTokenHandler = new JsonWebTokenHandler(); | ||
var jweTokenDescriptor = new SecurityTokenDescriptor | ||
{ | ||
SigningCredentials = BenchmarkUtils.SigningCredentialsRsaSha256, | ||
EncryptingCredentials = BenchmarkUtils.EncryptingCredentialsAes256Sha512, | ||
TokenType = JwtHeaderParameterNames.Jwk, | ||
Claims = BenchmarkUtils.Claims | ||
}; | ||
|
||
_encryptedJWE = jsonWebTokenHandler.CreateToken(jweTokenDescriptor); | ||
_encryptedJWEAsMemory = _encryptedJWE.AsMemory(); | ||
} | ||
|
||
[Benchmark] | ||
public JsonWebToken ReadJWE_FromString() | ||
{ | ||
return new JsonWebToken(_encryptedJWE); | ||
} | ||
|
||
[Benchmark] | ||
public JsonWebToken ReadJWE_FromMemory() | ||
{ | ||
return new JsonWebToken(_encryptedJWEAsMemory); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
benchmark/Microsoft.IdentityModel.Benchmarks/ReadJWSTokenTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.IdentityModel.JsonWebTokens; | ||
using Microsoft.IdentityModel.Tokens; | ||
|
||
namespace Microsoft.IdentityModel.Benchmarks | ||
{ | ||
// dotnet run -c release -f net8.0 --filter Microsoft.IdentityModel.Benchmarks.ReadJWSTokenTests* | ||
|
||
public class ReadJWSTokenTests | ||
{ | ||
string _encodedJWS; | ||
ReadOnlyMemory<char> _encodedJWSAsMemory; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
var jsonWebTokenHandler = new JsonWebTokenHandler(); | ||
var jwsTokenDescriptor = new SecurityTokenDescriptor | ||
{ | ||
SigningCredentials = BenchmarkUtils.SigningCredentialsRsaSha256, | ||
TokenType = JwtHeaderParameterNames.Jwk, | ||
Claims = BenchmarkUtils.Claims | ||
}; | ||
|
||
_encodedJWS = jsonWebTokenHandler.CreateToken(jwsTokenDescriptor); | ||
_encodedJWSAsMemory = _encodedJWS.AsMemory(); | ||
} | ||
|
||
[Benchmark] | ||
public JsonWebToken ReadJWS_FromString() | ||
{ | ||
return new JsonWebToken(_encodedJWS); | ||
} | ||
|
||
[Benchmark] | ||
public JsonWebToken ReadJWS_FromMemory() | ||
{ | ||
return new JsonWebToken(_encodedJWSAsMemory); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.