summary refs log tree commit diff
path: root/crypto/src/asn1/x509/X509Extensions.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-06-05 18:33:27 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-06-05 18:33:27 +0700
commit215f7bad529b793fc0369fec0dad541d1f93ca7e (patch)
treeb56e5bf37b9124b1a1ff2e6bd8c21e246d508638 /crypto/src/asn1/x509/X509Extensions.cs
parentASN.1: GetOptional method for all universal types (diff)
downloadBouncyCastle.NET-ed25519-215f7bad529b793fc0369fec0dad541d1f93ca7e.tar.xz
Refactoring in Asn1.Cmp
Diffstat (limited to '')
-rw-r--r--crypto/src/asn1/x509/X509Extensions.cs15
1 files changed, 15 insertions, 0 deletions
diff --git a/crypto/src/asn1/x509/X509Extensions.cs b/crypto/src/asn1/x509/X509Extensions.cs
index 2893f8b79..193ac8188 100644
--- a/crypto/src/asn1/x509/X509Extensions.cs
+++ b/crypto/src/asn1/x509/X509Extensions.cs
@@ -220,6 +220,21 @@ namespace Org.BouncyCastle.Asn1.X509
             throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), nameof(obj));
         }
 
+        public static X509Extensions GetOptional(Asn1Encodable element)
+        {
+            if (element == null)
+                throw new ArgumentNullException(nameof(element));
+
+            if (element is X509Extensions existing)
+                return existing;
+
+            Asn1Sequence asn1Sequence = Asn1Sequence.GetOptional(element);
+            if (asn1Sequence != null)
+                return new X509Extensions(asn1Sequence);
+
+            return null;
+        }
+
         /**
          * Constructor from Asn1Sequence.
          *