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