-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRfc3161TimestampTokenJsonConverter.cs
More file actions
36 lines (32 loc) · 1.07 KB
/
Copy pathRfc3161TimestampTokenJsonConverter.cs
File metadata and controls
36 lines (32 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Security.Cryptography.Pkcs;
using System.Text.Json;
using System.Text.Json.Serialization;
/// <summary>
/// A <c>JsonConverter</c> for serializing <c>Rfc3161TimestampToken</c> to and from JSON.
/// </summary>
public class Rfc3161TimestampTokenJsonConverter : JsonConverter<Rfc3161TimestampToken>
{
public override Rfc3161TimestampToken? Read(ref Utf8JsonReader reader, Type typeToConvert,
JsonSerializerOptions options)
{
Rfc3161TimestampToken? timestampToken;
int bytesConsumed;
Rfc3161TimestampToken.TryDecode(
reader.GetBytesFromBase64(),
out timestampToken,
out bytesConsumed
);
if(timestampToken is null)
throw new Exception("Timestamp token converted as null.");
return timestampToken;
}
public override void Write(Utf8JsonWriter writer, Rfc3161TimestampToken value, JsonSerializerOptions options)
{
writer.WriteBase64StringValue(
value
.AsSignedCms()
.Encode()
);
}
}