diff options
Diffstat (limited to 'crypto/src/asn1/cms/Time.cs')
-rw-r--r-- | crypto/src/asn1/cms/Time.cs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/crypto/src/asn1/cms/Time.cs b/crypto/src/asn1/cms/Time.cs index 66fa578af..8dbca7a27 100644 --- a/crypto/src/asn1/cms/Time.cs +++ b/crypto/src/asn1/cms/Time.cs @@ -28,6 +28,25 @@ namespace Org.BouncyCastle.Asn1.Cms return Asn1Utilities.GetInstanceFromChoice(taggedObject, declaredExplicit, GetInstance); } + public static Time GetOptional(Asn1Encodable element) + { + if (element == null) + throw new ArgumentNullException(nameof(element)); + + if (element is Time time) + return time; + + Asn1UtcTime utcTime = Asn1UtcTime.GetOptional(element); + if (utcTime != null) + return new Time(utcTime); + + Asn1GeneralizedTime generalizedTime = Asn1GeneralizedTime.GetOptional(element); + if (generalizedTime != null) + return new Time(generalizedTime); + + return null; + } + private readonly Asn1Object m_timeObject; public Time(Asn1GeneralizedTime generalizedTime) |