diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-06-04 20:49:14 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-06-04 20:49:14 +0700 |
commit | 114cc8223deeadd0047d966d517ac11fbc63893d (patch) | |
tree | 775f73ea5b051ed1673a9805f1665cd4bef60bbf /crypto | |
parent | Refactoring in Asn1.BC (diff) | |
download | BouncyCastle.NET-ed25519-114cc8223deeadd0047d966d517ac11fbc63893d.tar.xz |
Refactor GetInstance methods
Diffstat (limited to 'crypto')
27 files changed, 29 insertions, 27 deletions
diff --git a/crypto/src/asn1/Asn1GeneralizedTime.cs b/crypto/src/asn1/Asn1GeneralizedTime.cs index affad50e2..704b6a8bc 100644 --- a/crypto/src/asn1/Asn1GeneralizedTime.cs +++ b/crypto/src/asn1/Asn1GeneralizedTime.cs @@ -31,7 +31,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is Asn1GeneralizedTime asn1GeneralizedTime) return asn1GeneralizedTime; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is Asn1GeneralizedTime converted) diff --git a/crypto/src/asn1/Asn1Null.cs b/crypto/src/asn1/Asn1Null.cs index 77304c0fb..99f5a530c 100644 --- a/crypto/src/asn1/Asn1Null.cs +++ b/crypto/src/asn1/Asn1Null.cs @@ -31,7 +31,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is Asn1Null asn1Null) return asn1Null; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is Asn1Null converted) diff --git a/crypto/src/asn1/Asn1ObjectDescriptor.cs b/crypto/src/asn1/Asn1ObjectDescriptor.cs index 0d478a46d..c4b27ca8c 100644 --- a/crypto/src/asn1/Asn1ObjectDescriptor.cs +++ b/crypto/src/asn1/Asn1ObjectDescriptor.cs @@ -42,7 +42,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is Asn1ObjectDescriptor asn1ObjectDescriptor) return asn1ObjectDescriptor; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is Asn1ObjectDescriptor converted) diff --git a/crypto/src/asn1/Asn1OctetString.cs b/crypto/src/asn1/Asn1OctetString.cs index d68d093e2..02f27cd9b 100644 --- a/crypto/src/asn1/Asn1OctetString.cs +++ b/crypto/src/asn1/Asn1OctetString.cs @@ -42,7 +42,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is Asn1OctetString asn1OctetString) return asn1OctetString; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is Asn1OctetString converted) diff --git a/crypto/src/asn1/Asn1RelativeOid.cs b/crypto/src/asn1/Asn1RelativeOid.cs index 587d41d2c..9aa57b650 100644 --- a/crypto/src/asn1/Asn1RelativeOid.cs +++ b/crypto/src/asn1/Asn1RelativeOid.cs @@ -49,7 +49,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is Asn1RelativeOid asn1RelativeOid) return asn1RelativeOid; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is Asn1RelativeOid converted) diff --git a/crypto/src/asn1/Asn1Sequence.cs b/crypto/src/asn1/Asn1Sequence.cs index 83e881728..4012e0c08 100644 --- a/crypto/src/asn1/Asn1Sequence.cs +++ b/crypto/src/asn1/Asn1Sequence.cs @@ -37,7 +37,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is Asn1Sequence asn1Sequence) return asn1Sequence; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is Asn1Sequence converted) diff --git a/crypto/src/asn1/Asn1Set.cs b/crypto/src/asn1/Asn1Set.cs index 22e24c297..1b593a9e3 100644 --- a/crypto/src/asn1/Asn1Set.cs +++ b/crypto/src/asn1/Asn1Set.cs @@ -37,7 +37,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is Asn1Set asn1Set) return asn1Set; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is Asn1Set converted) diff --git a/crypto/src/asn1/Asn1TaggedObject.cs b/crypto/src/asn1/Asn1TaggedObject.cs index 01d10cbb2..3a53d7852 100644 --- a/crypto/src/asn1/Asn1TaggedObject.cs +++ b/crypto/src/asn1/Asn1TaggedObject.cs @@ -27,7 +27,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is Asn1TaggedObject asn1TaggedObject) return asn1TaggedObject; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is Asn1TaggedObject converted) diff --git a/crypto/src/asn1/Asn1UtcTime.cs b/crypto/src/asn1/Asn1UtcTime.cs index bb9b6de8b..836481833 100644 --- a/crypto/src/asn1/Asn1UtcTime.cs +++ b/crypto/src/asn1/Asn1UtcTime.cs @@ -37,7 +37,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is Asn1UtcTime asn1UtcTime) return asn1UtcTime; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is Asn1UtcTime converted) diff --git a/crypto/src/asn1/DERExternal.cs b/crypto/src/asn1/DERExternal.cs index be1223f98..b36bf9623 100644 --- a/crypto/src/asn1/DERExternal.cs +++ b/crypto/src/asn1/DERExternal.cs @@ -31,7 +31,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerExternal derExternal) return derExternal; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerExternal converted) diff --git a/crypto/src/asn1/DerBMPString.cs b/crypto/src/asn1/DerBMPString.cs index 71a3f132e..5712dde6d 100644 --- a/crypto/src/asn1/DerBMPString.cs +++ b/crypto/src/asn1/DerBMPString.cs @@ -40,7 +40,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerBmpString derBmpString) return derBmpString; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerBmpString converted) diff --git a/crypto/src/asn1/DerBitString.cs b/crypto/src/asn1/DerBitString.cs index f543a968d..13955f4d5 100644 --- a/crypto/src/asn1/DerBitString.cs +++ b/crypto/src/asn1/DerBitString.cs @@ -39,7 +39,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerBitString derBitString) return derBitString; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerBitString converted) diff --git a/crypto/src/asn1/DerBoolean.cs b/crypto/src/asn1/DerBoolean.cs index 61a4dddb2..a92346044 100644 --- a/crypto/src/asn1/DerBoolean.cs +++ b/crypto/src/asn1/DerBoolean.cs @@ -36,7 +36,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerBoolean derBoolean) return derBoolean; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerBoolean converted) diff --git a/crypto/src/asn1/DerEnumerated.cs b/crypto/src/asn1/DerEnumerated.cs index f4725513e..02f3fdd47 100644 --- a/crypto/src/asn1/DerEnumerated.cs +++ b/crypto/src/asn1/DerEnumerated.cs @@ -34,7 +34,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerEnumerated derEnumerated) return derEnumerated; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerEnumerated converted) diff --git a/crypto/src/asn1/DerGeneralString.cs b/crypto/src/asn1/DerGeneralString.cs index bfc6f6fd5..146703b81 100644 --- a/crypto/src/asn1/DerGeneralString.cs +++ b/crypto/src/asn1/DerGeneralString.cs @@ -28,7 +28,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerGeneralString derGeneralString) return derGeneralString; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerGeneralString converted) diff --git a/crypto/src/asn1/DerGraphicString.cs b/crypto/src/asn1/DerGraphicString.cs index 7c3d1edb2..e741c2ad2 100644 --- a/crypto/src/asn1/DerGraphicString.cs +++ b/crypto/src/asn1/DerGraphicString.cs @@ -35,7 +35,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerGraphicString derGraphicString) return derGraphicString; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerGraphicString converted) diff --git a/crypto/src/asn1/DerIA5String.cs b/crypto/src/asn1/DerIA5String.cs index 337cf2c2e..176ea061a 100644 --- a/crypto/src/asn1/DerIA5String.cs +++ b/crypto/src/asn1/DerIA5String.cs @@ -36,7 +36,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerIA5String derIA5String) return derIA5String; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerIA5String converted) diff --git a/crypto/src/asn1/DerInteger.cs b/crypto/src/asn1/DerInteger.cs index 85585bea3..337e73ff6 100644 --- a/crypto/src/asn1/DerInteger.cs +++ b/crypto/src/asn1/DerInteger.cs @@ -48,7 +48,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerInteger derInteger) return derInteger; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerInteger converted) diff --git a/crypto/src/asn1/DerNumericString.cs b/crypto/src/asn1/DerNumericString.cs index 2daca8b66..ecfa08b73 100644 --- a/crypto/src/asn1/DerNumericString.cs +++ b/crypto/src/asn1/DerNumericString.cs @@ -36,7 +36,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerNumericString derNumericString) return derNumericString; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerNumericString converted) diff --git a/crypto/src/asn1/DerObjectIdentifier.cs b/crypto/src/asn1/DerObjectIdentifier.cs index 7e1d5c2ff..7c76173f4 100644 --- a/crypto/src/asn1/DerObjectIdentifier.cs +++ b/crypto/src/asn1/DerObjectIdentifier.cs @@ -54,7 +54,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerObjectIdentifier derObjectIdentifier) return derObjectIdentifier; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerObjectIdentifier converted) diff --git a/crypto/src/asn1/DerPrintableString.cs b/crypto/src/asn1/DerPrintableString.cs index 563e6fb58..5e9c99bdc 100644 --- a/crypto/src/asn1/DerPrintableString.cs +++ b/crypto/src/asn1/DerPrintableString.cs @@ -36,7 +36,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerPrintableString derPrintableString) return derPrintableString; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerPrintableString converted) diff --git a/crypto/src/asn1/DerT61String.cs b/crypto/src/asn1/DerT61String.cs index 998a43bc2..05b0c62f5 100644 --- a/crypto/src/asn1/DerT61String.cs +++ b/crypto/src/asn1/DerT61String.cs @@ -36,7 +36,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerT61String derT61String) return derT61String; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerT61String converted) diff --git a/crypto/src/asn1/DerUTF8String.cs b/crypto/src/asn1/DerUTF8String.cs index 9bee962e7..a9f35abda 100644 --- a/crypto/src/asn1/DerUTF8String.cs +++ b/crypto/src/asn1/DerUTF8String.cs @@ -36,7 +36,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerUtf8String derUtf8String) return derUtf8String; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerUtf8String converted) diff --git a/crypto/src/asn1/DerUniversalString.cs b/crypto/src/asn1/DerUniversalString.cs index d65121ab0..fc031ecf5 100644 --- a/crypto/src/asn1/DerUniversalString.cs +++ b/crypto/src/asn1/DerUniversalString.cs @@ -40,7 +40,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerUniversalString derUniversalString) return derUniversalString; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerUniversalString converted) diff --git a/crypto/src/asn1/DerVideotexString.cs b/crypto/src/asn1/DerVideotexString.cs index 5019a6668..3b65861f0 100644 --- a/crypto/src/asn1/DerVideotexString.cs +++ b/crypto/src/asn1/DerVideotexString.cs @@ -35,7 +35,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerVideotexString derVideotexString) return derVideotexString; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerVideotexString converted) diff --git a/crypto/src/asn1/DerVisibleString.cs b/crypto/src/asn1/DerVisibleString.cs index 4c939988e..0d8131d65 100644 --- a/crypto/src/asn1/DerVisibleString.cs +++ b/crypto/src/asn1/DerVisibleString.cs @@ -36,7 +36,7 @@ namespace Org.BouncyCastle.Asn1 if (obj is DerVisibleString derVisibleString) return derVisibleString; - if (obj is IAsn1Convertible asn1Convertible) + if (obj is IAsn1Convertible asn1Convertible && !(obj is Asn1Object)) { Asn1Object asn1Object = asn1Convertible.ToAsn1Object(); if (asn1Object is DerVisibleString converted) diff --git a/crypto/src/asn1/IAsn1Convertible.cs b/crypto/src/asn1/IAsn1Convertible.cs index d3f83afc9..77b12c310 100644 --- a/crypto/src/asn1/IAsn1Convertible.cs +++ b/crypto/src/asn1/IAsn1Convertible.cs @@ -1,6 +1,8 @@ namespace Org.BouncyCastle.Asn1 { - public interface IAsn1Convertible + // TODO[api] Make generic on the return type of ToAsn1Object() + // TODO[api] Have a different interface that is only for custom ASN.1 types + public interface IAsn1Convertible { Asn1Object ToAsn1Object(); } |