diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-11-06 14:48:05 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-11-06 14:48:05 +0700 |
commit | 58af12ad76e7bb6ac68278d45109da4472a3aae8 (patch) | |
tree | 22f979ee438b7995c86904a4f189b11d037db495 /crypto/src/asn1/DerEnumerated.cs | |
parent | Mark class static (diff) | |
download | BouncyCastle.NET-ed25519-58af12ad76e7bb6ac68278d45109da4472a3aae8.tar.xz |
Asn1 GetInstance refactoring
Diffstat (limited to 'crypto/src/asn1/DerEnumerated.cs')
-rw-r--r-- | crypto/src/asn1/DerEnumerated.cs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/crypto/src/asn1/DerEnumerated.cs b/crypto/src/asn1/DerEnumerated.cs index 920b3dc8e..b85c5a43e 100644 --- a/crypto/src/asn1/DerEnumerated.cs +++ b/crypto/src/asn1/DerEnumerated.cs @@ -28,21 +28,23 @@ namespace Org.BouncyCastle.Asn1 */ public static DerEnumerated GetInstance(object obj) { - if (obj == null || obj is DerEnumerated) - { - return (DerEnumerated)obj; - } - else if (obj is IAsn1Convertible) + if (obj == null) + return null; + + if (obj is DerEnumerated derEnumerated) + return derEnumerated; + + if (obj is IAsn1Convertible asn1Convertible) { - Asn1Object asn1Object = ((IAsn1Convertible)obj).ToAsn1Object(); - if (asn1Object is DerEnumerated) - return (DerEnumerated)asn1Object; + Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); + if (asn1Object is DerEnumerated converted) + return converted; } - else if (obj is byte[]) + else if (obj is byte[] bytes) { try { - return (DerEnumerated)Meta.Instance.FromByteArray((byte[])obj); + return (DerEnumerated)Meta.Instance.FromByteArray(bytes); } catch (IOException e) { |