summary refs log tree commit diff
path: root/crypto/src/asn1/Asn1Null.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/Asn1Null.cs')
-rw-r--r--crypto/src/asn1/Asn1Null.cs17
1 files changed, 17 insertions, 0 deletions
diff --git a/crypto/src/asn1/Asn1Null.cs b/crypto/src/asn1/Asn1Null.cs
index 992cd09aa..fa0adf71f 100644
--- a/crypto/src/asn1/Asn1Null.cs
+++ b/crypto/src/asn1/Asn1Null.cs
@@ -56,6 +56,23 @@ namespace Org.BouncyCastle.Asn1
             return (Asn1Null)Meta.Instance.GetContextInstance(taggedObject, declaredExplicit);
         }
 
+        public static Asn1Null GetOptional(Asn1Encodable element)
+        {
+            if (element == null)
+                throw new ArgumentNullException(nameof(element));
+
+            if (element is Asn1Null existing)
+                return existing;
+
+            if (element is IAsn1Convertible asn1Convertible && !(element is Asn1Object) &&
+                asn1Convertible.ToAsn1Object() is Asn1Null converted)
+            {
+                return converted;
+            }
+
+            return null;
+        }
+
         internal Asn1Null()
         {
         }