diff options
Diffstat (limited to 'crypto/src/asn1/Asn1ObjectDescriptor.cs')
-rw-r--r-- | crypto/src/asn1/Asn1ObjectDescriptor.cs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/crypto/src/asn1/Asn1ObjectDescriptor.cs b/crypto/src/asn1/Asn1ObjectDescriptor.cs index 8d41fa4e4..1f33eeac8 100644 --- a/crypto/src/asn1/Asn1ObjectDescriptor.cs +++ b/crypto/src/asn1/Asn1ObjectDescriptor.cs @@ -75,6 +75,23 @@ namespace Org.BouncyCastle.Asn1 return (Asn1ObjectDescriptor)Meta.Instance.GetContextInstance(taggedObject, declaredExplicit); } + public static Asn1ObjectDescriptor GetOptional(Asn1Encodable element) + { + if (element == null) + throw new ArgumentNullException(nameof(element)); + + if (element is Asn1ObjectDescriptor existing) + return existing; + + if (element is IAsn1Convertible asn1Convertible && !(element is Asn1Object) && + asn1Convertible.ToAsn1Object() is Asn1ObjectDescriptor converted) + { + return converted; + } + + return null; + } + private readonly DerGraphicString m_baseGraphicString; public Asn1ObjectDescriptor(DerGraphicString baseGraphicString) |