diff options
Diffstat (limited to 'crypto/src/asn1/DerUTF8String.cs')
-rw-r--r-- | crypto/src/asn1/DerUTF8String.cs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/crypto/src/asn1/DerUTF8String.cs b/crypto/src/asn1/DerUTF8String.cs index a9f35abda..965a8ebf8 100644 --- a/crypto/src/asn1/DerUTF8String.cs +++ b/crypto/src/asn1/DerUTF8String.cs @@ -69,6 +69,21 @@ namespace Org.BouncyCastle.Asn1 return (DerUtf8String)Meta.Instance.GetContextInstance(taggedObject, declaredExplicit); } + public static DerUtf8String GetOptional(Asn1Encodable element) + { + if (element == null) + throw new ArgumentNullException(nameof(element)); + if (element is DerUtf8String derUtf8String) + return derUtf8String; + if (element is IAsn1Convertible asn1Convertible && !(element is Asn1Object)) + { + Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); + if (asn1Object is DerUtf8String converted) + return converted; + } + return null; + } + private readonly byte[] m_contents; public DerUtf8String(string str) |