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