2using System.Diagnostics.CodeAnalysis;
3using System.Formats.Asn1;
14 private DateTimeOffset? notBefore =
null;
15 private DateTimeOffset? notAfter =
null;
16 protected bool configured =
false;
21 public override string Oid =>
"2.5.29.16";
35 if (SecurityInfo.LastElementNested is not Vector UsagePeriod)
38 int c = UsagePeriod.Length;
42 if (!TryParseGeneralizedTime(UsagePeriod[0], out DateTimeOffset?
NotBefore))
49 if (!TryParseGeneralizedTime(UsagePeriod[1], out DateTimeOffset?
NotAfter))
56 this.configured =
true;
61 public static bool TryParseGeneralizedTime(
object? Data,
62 [NotNullWhen(
true)] out DateTimeOffset? Result)
64 if (Data is DateTimeOffset Timestamp)
70 if (Data is
byte[] Bin && Bin.Length > 0 && (Bin[0] & 0x80) != 0 &&
71 Bin.Length == Bin[1] + 2)
73 Bin = (
byte[])Bin.Clone();
74 Bin[0] = (byte)UniversalTagNumber.IA5String;
75 AsnReader Reader =
new(Bin, AsnEncodingRules.DER);
76 string s = Reader.ReadCharacterString((UniversalTagNumber)Bin[0]);
80 StringBuilder sb =
new();
84 sb.Append(s.AsSpan(4, 2));
86 sb.Append(s.AsSpan(6, 2));
88 sb.Append(s.AsSpan(8, 2));
90 sb.Append(s.AsSpan(10, 2));
DateTimeOffset? NotBefore
Not Before
override bool Configure(Vector SecurityInfo)
If the object can be configured by the security information provided.
DateTimeOffset? NotAfter
Not After
override bool IsConfigured
If the object has been configured.
override string Oid
OID identifying the type of object.
Abstract base class for security objects.
Helps with common XML-related tasks.
static bool TryParse(string s, out DateTime Value)
Tries to decode a string encoded DateTime.