diff options
Diffstat (limited to 'crypto/src/asn1/DerEnumerated.cs')
-rw-r--r-- | crypto/src/asn1/DerEnumerated.cs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/crypto/src/asn1/DerEnumerated.cs b/crypto/src/asn1/DerEnumerated.cs index d46e1153d..9ec1d1919 100644 --- a/crypto/src/asn1/DerEnumerated.cs +++ b/crypto/src/asn1/DerEnumerated.cs @@ -66,6 +66,23 @@ namespace Org.BouncyCastle.Asn1 return (DerEnumerated)Meta.Instance.GetContextInstance(taggedObject, declaredExplicit); } + public static DerEnumerated GetOptional(Asn1Encodable element) + { + if (element == null) + throw new ArgumentNullException(nameof(element)); + + if (element is DerEnumerated existing) + return existing; + + if (element is IAsn1Convertible asn1Convertible && !(element is Asn1Object) && + asn1Convertible.ToAsn1Object() is DerEnumerated converted) + { + return converted; + } + + return null; + } + private readonly byte[] contents; private readonly int start; |