diff options
Diffstat (limited to 'crypto/src/asn1/Asn1TaggedObject.cs')
-rw-r--r-- | crypto/src/asn1/Asn1TaggedObject.cs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/crypto/src/asn1/Asn1TaggedObject.cs b/crypto/src/asn1/Asn1TaggedObject.cs index 0045ad448..f817a1343 100644 --- a/crypto/src/asn1/Asn1TaggedObject.cs +++ b/crypto/src/asn1/Asn1TaggedObject.cs @@ -73,6 +73,23 @@ namespace Org.BouncyCastle.Asn1 return Asn1Utilities.GetExplicitBaseTagged(CheckInstance(taggedObject, declaredExplicit), tagClass, tagNo); } + public static Asn1TaggedObject GetOptional(Asn1Encodable element) + { + if (element == null) + throw new ArgumentNullException(nameof(element)); + + if (element is Asn1TaggedObject existing) + return existing; + + if (element is IAsn1Convertible asn1Convertible && !(element is Asn1Object) && + asn1Convertible.ToAsn1Object() is Asn1TaggedObject converted) + { + return converted; + } + + return null; + } + private static Asn1TaggedObject CheckInstance(object obj) { return GetInstance(obj ?? throw new ArgumentNullException(nameof(obj))); |