Improve test coverage
This commit is contained in:
parent
ccc00d8e80
commit
1cd7fb659a
5 changed files with 130 additions and 26 deletions
|
|
@ -1,7 +1,5 @@
|
|||
using System.Buffers;
|
||||
using System.Buffers.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using IdentityShroud.Core.Helpers;
|
||||
|
||||
namespace IdentityShroud.Core.Messages;
|
||||
|
||||
|
|
@ -48,26 +46,4 @@ public class JsonWebKey
|
|||
// [JsonPropertyName("x5t")]
|
||||
// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
// public string? X509CertificateThumbprint { get; set; }
|
||||
}
|
||||
|
||||
public class Base64UrlConverter : JsonConverter<byte[]>
|
||||
{
|
||||
public override byte[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
// GetValueSpan gives you the raw UTF-8 bytes of the JSON string value
|
||||
if (reader.HasValueSequence)
|
||||
{
|
||||
var valueSequence = reader.ValueSequence.ToArray();
|
||||
return Base64Url.DecodeFromUtf8(valueSequence);
|
||||
}
|
||||
return Base64Url.DecodeFromUtf8(reader.ValueSpan);
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, byte[] value, JsonSerializerOptions options)
|
||||
{
|
||||
int encodedLength = Base64Url.GetEncodedLength(value.Length);
|
||||
Span<byte> buffer = encodedLength <= 256 ? stackalloc byte[encodedLength] : new byte[encodedLength];
|
||||
Base64Url.EncodeToUtf8(value, buffer);
|
||||
writer.WriteStringValue(buffer);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue