File tree Expand file tree Collapse file tree 3 files changed +39
-5
lines changed Expand file tree Collapse file tree 3 files changed +39
-5
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Text . Json . Serialization ;
3
+ using System . Text . Json ;
4
+
5
+ namespace Certstream
6
+ {
7
+ public class UnixDateTimeOffsetConverter : JsonConverter < DateTimeOffset >
8
+ {
9
+ public override DateTimeOffset Read ( ref Utf8JsonReader reader , Type typeToConvert , JsonSerializerOptions options )
10
+ {
11
+ if ( reader . TokenType == JsonTokenType . Number )
12
+ {
13
+ if ( reader . TryGetInt64 ( out long longTime ) )
14
+ return DateTimeOffset . FromUnixTimeSeconds ( longTime ) ;
15
+
16
+ if ( reader . TryGetDouble ( out double doubleTime ) )
17
+ return DateTimeOffset . FromUnixTimeSeconds ( ( long ) doubleTime ) ;
18
+ }
19
+
20
+ throw new JsonException ( "Expected a number representing Unix time." ) ;
21
+ }
22
+
23
+ public override void Write ( Utf8JsonWriter writer , DateTimeOffset value , JsonSerializerOptions options )
24
+ {
25
+ long unixTime = ( long ) value . ToUnixTimeSeconds ( ) ;
26
+ writer . WriteNumberValue ( unixTime ) ;
27
+ }
28
+ }
29
+ }
Original file line number Diff line number Diff line change 1
- using System . Text . Json . Serialization ;
1
+ using System ;
2
+ using System . Text . Json . Serialization ;
2
3
3
4
namespace Certstream . Models
4
5
{
@@ -16,11 +17,13 @@ public struct LeafCertificate
16
17
[ JsonPropertyName ( "issuer" ) ]
17
18
public Issuer Issuer { get ; set ; }
18
19
20
+ [ JsonConverter ( typeof ( UnixDateTimeOffsetConverter ) ) ]
19
21
[ JsonPropertyName ( "not_after" ) ]
20
- public int NotAfter { get ; set ; }
22
+ public DateTimeOffset NotAfter { get ; set ; }
21
23
24
+ [ JsonConverter ( typeof ( UnixDateTimeOffsetConverter ) ) ]
22
25
[ JsonPropertyName ( "not_before" ) ]
23
- public int NotBefore { get ; set ; }
26
+ public DateTimeOffset NotBefore { get ; set ; }
24
27
25
28
[ JsonPropertyName ( "serial_number" ) ]
26
29
public string SerialNumber { get ; set ; }
Original file line number Diff line number Diff line change 1
- using System . Text . Json . Serialization ;
1
+ using System ;
2
+ using System . Text . Json . Serialization ;
2
3
3
4
namespace Certstream . Models
4
5
{
@@ -13,8 +14,9 @@ public struct MessageData
13
14
[ JsonPropertyName ( "leaf_cert" ) ]
14
15
public LeafCertificate Leaf { get ; set ; }
15
16
17
+ [ JsonConverter ( typeof ( UnixDateTimeOffsetConverter ) ) ]
16
18
[ JsonPropertyName ( "seen" ) ]
17
- public double Seen { get ; set ; }
19
+ public DateTimeOffset Seen { get ; set ; }
18
20
19
21
[ JsonPropertyName ( "source" ) ]
20
22
public Source Source { get ; set ; }
You can’t perform that action at this time.
0 commit comments