diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-02-01 21:07:46 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-02-01 21:07:46 +0700 |
commit | db9b19e3f17a2aee8afcd673ef9327bb8646b87a (patch) | |
tree | a16cf94d902be26f7f00a5218cafa15fe28cf233 /crypto/src/asn1/cmp/OobCert.cs | |
parent | Add GetInstanceFromChoice helper (diff) | |
download | BouncyCastle.NET-ed25519-db9b19e3f17a2aee8afcd673ef9327bb8646b87a.tar.xz |
Overhaul Asn1.Cmp
Diffstat (limited to 'crypto/src/asn1/cmp/OobCert.cs')
-rw-r--r-- | crypto/src/asn1/cmp/OobCert.cs | 46 |
1 files changed, 15 insertions, 31 deletions
diff --git a/crypto/src/asn1/cmp/OobCert.cs b/crypto/src/asn1/cmp/OobCert.cs index 82d5afe55..6d60f6bb6 100644 --- a/crypto/src/asn1/cmp/OobCert.cs +++ b/crypto/src/asn1/cmp/OobCert.cs @@ -1,8 +1,6 @@ using System; -using System.IO; using Org.BouncyCastle.Asn1.X509; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.Cmp { @@ -16,50 +14,36 @@ namespace Org.BouncyCastle.Asn1.Cmp { if (obj == null) return null; - if (obj is OobCert oobCert) return oobCert; - if (obj is CmpCertificate cmpCertificate) - return GetInstance(cmpCertificate.GetEncoded()); - - if (obj is byte[] bs) - { - try - { - obj = Asn1Object.FromByteArray(bs); - } - catch (IOException) - { - throw new ArgumentException("Invalid encoding in OobCert"); - } - } - - if (obj is Asn1Sequence seq) - return new OobCert(X509CertificateStructure.GetInstance(obj)); - + return new OobCert(cmpCertificate); if (obj is Asn1TaggedObject taggedObject) - return new OobCert(taggedObject.TagNo, taggedObject.GetObject()); - - throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), nameof(obj)); + return new OobCert(taggedObject); + return new OobCert(X509CertificateStructure.GetInstance(obj)); } public static new OobCert GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) { - if (taggedObject == null) - return null; - - if (!declaredExplicit) - throw new ArgumentException("tag must be explicit"); - - return GetInstance(taggedObject.GetObject()); + return Asn1Utilities.GetInstanceFromChoice(taggedObject, declaredExplicit, GetInstance); } + [Obsolete("Use constructor from Asn1TaggedObject instead")] public OobCert(int type, Asn1Encodable otherCert) : base(type, otherCert) { } + internal OobCert(Asn1TaggedObject taggedObject) + : base(taggedObject) + { + } + + internal OobCert(CmpCertificate other) + : base(other) + { + } + public OobCert(X509CertificateStructure x509v3PKCert) : base(x509v3PKCert) { |