File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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 ;
23
34namespace Certstream . Models
45{
@@ -16,11 +17,13 @@ public struct LeafCertificate
1617 [ JsonPropertyName ( "issuer" ) ]
1718 public Issuer Issuer { get ; set ; }
1819
20+ [ JsonConverter ( typeof ( UnixDateTimeOffsetConverter ) ) ]
1921 [ JsonPropertyName ( "not_after" ) ]
20- public int NotAfter { get ; set ; }
22+ public DateTimeOffset NotAfter { get ; set ; }
2123
24+ [ JsonConverter ( typeof ( UnixDateTimeOffsetConverter ) ) ]
2225 [ JsonPropertyName ( "not_before" ) ]
23- public int NotBefore { get ; set ; }
26+ public DateTimeOffset NotBefore { get ; set ; }
2427
2528 [ JsonPropertyName ( "serial_number" ) ]
2629 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 ;
23
34namespace Certstream . Models
45{
@@ -13,8 +14,9 @@ public struct MessageData
1314 [ JsonPropertyName ( "leaf_cert" ) ]
1415 public LeafCertificate Leaf { get ; set ; }
1516
17+ [ JsonConverter ( typeof ( UnixDateTimeOffsetConverter ) ) ]
1618 [ JsonPropertyName ( "seen" ) ]
17- public double Seen { get ; set ; }
19+ public DateTimeOffset Seen { get ; set ; }
1820
1921 [ JsonPropertyName ( "source" ) ]
2022 public Source Source { get ; set ; }
You can’t perform that action at this time.
0 commit comments