diff options
Diffstat (limited to 'crypto/src/asn1/DerNumericString.cs')
-rw-r--r-- | crypto/src/asn1/DerNumericString.cs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/crypto/src/asn1/DerNumericString.cs b/crypto/src/asn1/DerNumericString.cs index 693ff7d6e..819d946b1 100644 --- a/crypto/src/asn1/DerNumericString.cs +++ b/crypto/src/asn1/DerNumericString.cs @@ -30,21 +30,23 @@ namespace Org.BouncyCastle.Asn1 */ public static DerNumericString GetInstance(object obj) { - if (obj == null || obj is DerNumericString) - { - return (DerNumericString)obj; - } - else if (obj is IAsn1Convertible) + if (obj == null) + return null; + + if (obj is DerNumericString derNumericString) + return derNumericString; + + if (obj is IAsn1Convertible asn1Convertible) { - Asn1Object asn1Object = ((IAsn1Convertible)obj).ToAsn1Object(); - if (asn1Object is DerNumericString) - return (DerNumericString)asn1Object; + Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); + if (asn1Object is DerNumericString converted) + return converted; } - else if (obj is byte[]) + else if (obj is byte[] bytes) { try { - return (DerNumericString)Meta.Instance.FromByteArray((byte[])obj); + return (DerNumericString)Meta.Instance.FromByteArray(bytes); } catch (IOException e) { |