Skip to content

Commit

Permalink
Add Base64UrlConverter.EnableRelaxedDecoding feature
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcarbon committed Nov 12, 2024
1 parent 0f0dc64 commit 6b3bf89
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Src/Fido2.Models/Converters/Base64UrlConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Fido2NetLib;
/// </summary>
public sealed class Base64UrlConverter : JsonConverter<byte[]>
{
public static bool EnableRelaxedDecoding { get; set; }

public override byte[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
byte[]? rentedBuffer = null;
Expand Down Expand Up @@ -39,7 +41,14 @@ public override byte[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonS
{
if (Base64.IsValid(source))
{
throw new JsonException("Expected data to be in Base64Url format, but received Base64 encoding instead");
if (EnableRelaxedDecoding)
{
return Base64Url.DecodeFromUtf8(source);
}
else
{
throw new JsonException("Expected data to be in Base64Url format, but received Base64 encoding instead.");
}
}
else
{
Expand Down

0 comments on commit 6b3bf89

Please sign in to comment.