Skip to content

Commit 960dbed

Browse files
committed
added useful method to decode any date/time
1 parent 2d390b3 commit 960dbed

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Asn1Parser/Universal/Asn1DateTime.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,23 @@ public static Asn1DateTime CreateRfcDateTime(DateTime time, TimeZoneInfo zone =
5858

5959
return new Asn1GeneralizedTime(time, zone);
6060
}
61+
/// <summary>
62+
/// Gets an ASN.1 date/time instance from current position in ASN.1 reader.
63+
/// </summary>
64+
/// <param name="reader">ASN.1 reader that points to either, UTC time or generalized time.</param>
65+
/// <returns>An instance of <see cref="Asn1UtcTime"/> or <see cref="Asn1GeneralizedTime"/>.</returns>
66+
/// <exception cref="Asn1InvalidTagException">
67+
/// ASN.1 reader points to non-date/time field.
68+
/// </exception>
69+
public static Asn1DateTime DecodeAnyDateTime(Asn1Reader reader) {
70+
switch (reader.Tag) {
71+
case (Byte)Asn1Type.UTCTime:
72+
return new Asn1UtcTime(reader);
73+
case (Byte)Asn1Type.GeneralizedTime:
74+
return new Asn1GeneralizedTime(reader);
75+
default:
76+
throw new Asn1InvalidTagException("Specified data is not valid ASN.1 date/time type.");
77+
}
78+
}
6179
}
6280
}

0 commit comments

Comments
 (0)