diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-02-07 15:20:51 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-02-07 15:20:51 +0700 |
commit | da57816ac47b92b0000ae8efb23bd4db2f305471 (patch) | |
tree | 8a8b4486327cf09f36d9d7fdf1b7c9efc4e0f295 | |
parent | Obsolete/rename property (diff) | |
download | BouncyCastle.NET-ed25519-da57816ac47b92b0000ae8efb23bd4db2f305471.tar.xz |
Improve CmpCertificate.GetInstance
-rw-r--r-- | crypto/src/asn1/cmp/CmpCertificate.cs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/crypto/src/asn1/cmp/CmpCertificate.cs b/crypto/src/asn1/cmp/CmpCertificate.cs index bc9844911..e30eccca4 100644 --- a/crypto/src/asn1/cmp/CmpCertificate.cs +++ b/crypto/src/asn1/cmp/CmpCertificate.cs @@ -13,9 +13,25 @@ namespace Org.BouncyCastle.Asn1.Cmp return null; if (obj is CmpCertificate cmpCertificate) return cmpCertificate; + if (obj is X509CertificateStructure certificate) + return new CmpCertificate(certificate); if (obj is Asn1TaggedObject taggedObject) return new CmpCertificate(taggedObject); - return new CmpCertificate(X509CertificateStructure.GetInstance(obj)); + + Asn1Object asn1Object = null; + if (obj is IAsn1Convertible asn1Convertible) + { + asn1Object = asn1Convertible.ToAsn1Object(); + } + else if (obj is byte[] bytes) + { + asn1Object = Asn1Object.FromByteArray(bytes); + } + + if (asn1Object is Asn1TaggedObject asn1TaggedObject) + return new CmpCertificate(asn1TaggedObject); + + return new CmpCertificate(X509CertificateStructure.GetInstance(asn1Object ?? obj)); } public static CmpCertificate GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) |