diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-06-05 17:09:26 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-06-05 17:09:26 +0700 |
commit | fc860ec52e9f8eac943c92e7d8cfd812c7a7f1d9 (patch) | |
tree | 0baac94ba9a3dad934f081bdeb190d485cc4ec0d /crypto/src/asn1/DerNumericString.cs | |
parent | Refactoring in Asn1 (diff) | |
download | BouncyCastle.NET-ed25519-fc860ec52e9f8eac943c92e7d8cfd812c7a7f1d9.tar.xz |
ASN.1: GetOptional method for all universal types
Diffstat (limited to 'crypto/src/asn1/DerNumericString.cs')
-rw-r--r-- | crypto/src/asn1/DerNumericString.cs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/crypto/src/asn1/DerNumericString.cs b/crypto/src/asn1/DerNumericString.cs index 44adceb6b..81871f3c9 100644 --- a/crypto/src/asn1/DerNumericString.cs +++ b/crypto/src/asn1/DerNumericString.cs @@ -68,6 +68,23 @@ namespace Org.BouncyCastle.Asn1 return (DerNumericString)Meta.Instance.GetContextInstance(taggedObject, declaredExplicit); } + public static DerNumericString GetOptional(Asn1Encodable element) + { + if (element == null) + throw new ArgumentNullException(nameof(element)); + + if (element is DerNumericString existing) + return existing; + + if (element is IAsn1Convertible asn1Convertible && !(element is Asn1Object) && + asn1Convertible.ToAsn1Object() is DerNumericString converted) + { + return converted; + } + + return null; + } + private readonly byte[] m_contents; public DerNumericString(string str) |