Skip to content

Commit

Permalink
Use FrozenSet in two appropriate places (#2640)
Browse files Browse the repository at this point in the history
* Use FrozenSet in two appropriate places

* Use FrozenSet only for .NET 8 and above

---------

Co-authored-by: joegoldman2 <147369450+joegoldman@users.noreply.github.com>
  • Loading branch information
joegoldman2 and joegoldman2 authored Jun 17, 2024
1 parent d0131d5 commit bf18516
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@

namespace Microsoft.IdentityModel.Protocols.OpenIdConnect
{

/// <summary>
/// Retrieves a populated <see cref="OpenIdConnectConfiguration"/> given an address.
/// </summary>
public class OpenIdConnectConfigurationRetriever : IConfigurationRetriever<OpenIdConnectConfiguration>
{

/// <summary>
/// Retrieves a populated <see cref="OpenIdConnectConfiguration"/> given an address.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace Microsoft.IdentityModel.Protocols.OpenIdConnect
{

/// <summary>
/// This exception is thrown when an OpenIdConnect protocol handler encounters a protocol error.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// See the LICENSE file in the project root for more information.

using System;
#if NET8_0_OR_GREATER
using System.Collections.Frozen;
#endif
using System.Collections.Generic;
using System.IO;
using System.Text;
Expand All @@ -26,7 +29,13 @@ internal static class OpenIdConnectConfigurationSerializer
// If not found, then we assume we should put the value into AdditionalData.
// If we didn't do that, we would pay a performance penalty for those cases where there is AdditionalData
// but otherwise the JSON properties are all lower case.
public static HashSet<string> OpenIdProviderMetadataNamesUpperCase = new HashSet<string>
public static readonly
#if NET8_0_OR_GREATER
FrozenSet<string>
#else
HashSet<string>
#endif
OpenIdProviderMetadataNamesUpperCase = new HashSet<string>
{
"ACR_VALUES_SUPPORTED",
"AUTHORIZATION_ENDPOINT",
Expand Down Expand Up @@ -87,7 +96,11 @@ internal static class OpenIdConnectConfigurationSerializer
"USERINFO_ENCRYPTION_ALG_VALUES_SUPPORTED",
"USERINFO_ENCRYPTION_ENC_VALUES_SUPPORTED",
"USERINFO_SIGNING_ALG_VALUES_SUPPORTED",
};
}
#if NET8_0_OR_GREATER
.ToFrozenSet()
#endif
;

#region Read
public static OpenIdConnectConfiguration Read(string json)
Expand Down
18 changes: 15 additions & 3 deletions src/Microsoft.IdentityModel.Tokens/Json/JsonWebKeySerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// See the LICENSE file in the project root for more information.

using System;
#if NET8_0_OR_GREATER
using System.Collections.Frozen;
#endif
using System.Collections.Generic;
using System.IO;
using System.Text;
Expand All @@ -21,7 +24,13 @@ internal static class JsonWebKeySerializer
// If not found, then we assume we should put the value into AdditionalData.
// If we didn't do that, we would pay a performance penalty for those cases where there is AdditionalData
// but otherwise the JSON properties are all lower case.
public static HashSet<string> JsonWebKeyParameterNamesUpperCase = new HashSet<string>
public static readonly
#if NET8_0_OR_GREATER
FrozenSet<string>
#else
HashSet<string>
# endif
JsonWebKeyParameterNamesUpperCase = new HashSet<string>
{
"ALG",
"CRV",
Expand All @@ -46,7 +55,11 @@ internal static class JsonWebKeySerializer
"X5T#S256",
"X5U",
"Y"
};
}
#if NET8_0_OR_GREATER
.ToFrozenSet()
#endif
;

#region Read
public static JsonWebKey Read(string json)
Expand Down Expand Up @@ -399,4 +412,3 @@ public static void Write(ref Utf8JsonWriter writer, JsonWebKey jsonWebKey)
#endregion
}
}

0 comments on commit bf18516

Please sign in to comment.