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