Skip to content

Commit

Permalink
Add JWT ctor that accepts a span
Browse files Browse the repository at this point in the history
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

Fix a typo (#2479)

* update comment for azp in jsonwebtoken

* removed extra words

Link to breaking change announcement in IDX10506 (#2478)

When an IDX10506 exception is thrown from JsonWebTokenHandler, there's a
good chance this is due to a breaking change to ASP.NET Core 8.

This adds a link to the breaking change announcement at
https://learn.microsoft.com/en-us/dotnet/core/compatibility/aspnet-core/8.0/securitytoken-events

7.3.1 changelog (#2476)

* 7.3.1 changelog

* two additions

* add space

fix log message dup (#2481)

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
  • Loading branch information
Sruthi Keerthi Rangavajhula committed Feb 24, 2024
1 parent 703639d commit 13f4e77
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 119 deletions.
4 changes: 4 additions & 0 deletions benchmark/Microsoft.IdentityModel.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public static void Main(string[] args)
}
private static void DebugThroughTests()
{
ReadJWETokenTests readTokenTests = new ReadJWETokenTests();
readTokenTests.Setup();
readTokenTests.ReadJWE_FromMemory();

AsymmetricAdapterSignatures asymmetricAdapter = new AsymmetricAdapterSignatures();
asymmetricAdapter.Setup();
asymmetricAdapter.SignDotnetCreatingBufferRSA();
Expand Down
47 changes: 47 additions & 0 deletions benchmark/Microsoft.IdentityModel.Benchmarks/ReadJWETokenTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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*

[Config(typeof(BenchmarkConfig))]
[HideColumns("Type", "Job", "WarmupCount", "LaunchCount")]
[MemoryDiagnoser]
public class ReadJWETokenTests
{
string _encryptedJWE;

[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);
}

[Benchmark]
public JsonWebToken ReadJWE_FromString()
{
return new JsonWebToken(_encryptedJWE);
}

[Benchmark]
public JsonWebToken ReadJWE_FromMemory()
{
return new JsonWebToken(_encryptedJWE.AsMemory());
}
}
}
47 changes: 47 additions & 0 deletions benchmark/Microsoft.IdentityModel.Benchmarks/ReadJWSTokenTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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*

[Config(typeof(BenchmarkConfig))]
[HideColumns("Type", "Job", "WarmupCount", "LaunchCount")]
[MemoryDiagnoser]
[RankColumn]
public class ReadJWSTokenTests
{
string _encodedJWS;

[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);
}

[Benchmark]
public JsonWebToken ReadJWS_FromString()
{
return new JsonWebToken(_encodedJWS);
}

[Benchmark]
public JsonWebToken ReadJWS_FromMemory()
{
return new JsonWebToken(_encodedJWS.AsMemory());
}
}
}
8 changes: 8 additions & 0 deletions build/releaseBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ jobs:
BuildDropPath: '$(Build.SourcesDirectory)\src'
ManifestDirPath: '$(Build.SourcesDirectory)\artifacts'

- task: NuGetCommand@2
displayName: 'Upload NuGet Package to VSTS NuGet'
inputs:
command: push
packagesToPush: '$(Build.Repository.LocalPath)\artifacts\*.nupkg'
publishVstsFeed: '46419298-b96c-437f-bd4c-12c8df7f868d'
allowPackageConflicts: true

- task: PublishBuildArtifacts@1
displayName: 'Publish NuGet Package Artifact'
inputs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class JsonWebToken
{
internal JsonClaimSet CreateHeaderClaimSet(byte[] bytes)
{
return CreateHeaderClaimSet(bytes, bytes.Length);
return CreateHeaderClaimSet(bytes.AsSpan());
}

internal JsonClaimSet CreateHeaderClaimSet(byte[] bytes, int length)
Expand Down
Loading

0 comments on commit 13f4e77

Please sign in to comment.