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