diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-09-20 14:07:11 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-09-20 14:07:11 +0700 |
commit | c17e29d769cf8a87402ff4d819d334389a7faca4 (patch) | |
tree | e60811ecfc45b6c229ce2e87d8b4a6db6d9f2da9 /crypto/src/asn1/cmp/CertAnnContent.cs | |
parent | added randomized signing (diff) | |
download | BouncyCastle.NET-ed25519-c17e29d769cf8a87402ff4d819d334389a7faca4.tar.xz |
Update Asn1.Cmp from bc-java
Diffstat (limited to 'crypto/src/asn1/cmp/CertAnnContent.cs')
-rw-r--r-- | crypto/src/asn1/cmp/CertAnnContent.cs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/crypto/src/asn1/cmp/CertAnnContent.cs b/crypto/src/asn1/cmp/CertAnnContent.cs new file mode 100644 index 000000000..df0188746 --- /dev/null +++ b/crypto/src/asn1/cmp/CertAnnContent.cs @@ -0,0 +1,72 @@ +using System; +using System.IO; + +using Org.BouncyCastle.Asn1.X509; +using Org.BouncyCastle.Utilities; + +namespace Org.BouncyCastle.Asn1.Cmp +{ + /** + * CertAnnContent ::= CMPCertificate + */ + public class CertAnnContent + : CmpCertificate + { + public static CertAnnContent GetInstance(object obj) + { + // TODO[cmp] + if (obj == null) + return null; + + if (obj is CertAnnContent content) + return content; + + 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 CertAnnContent"); + } + } + + if (obj is Asn1Sequence) + return new CertAnnContent(X509CertificateStructure.GetInstance(obj)); + + // TODO[cmp] + if (obj is Asn1TaggedObject taggedObject) + return new CertAnnContent(taggedObject.TagNo, taggedObject.GetObject()); + + throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), nameof(obj)); + } + + public static CertAnnContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) + { + // TODO[cmp] + if (taggedObject == null) + return null; + + if (!declaredExplicit) + throw new ArgumentException("tag must be explicit"); + + // TODO[cmp] + return GetInstance(taggedObject.GetObject()); + } + + public CertAnnContent(int type, Asn1Object otherCert) + : base(type, otherCert) + { + } + + public CertAnnContent(X509CertificateStructure x509v3PKCert) + : base(x509v3PKCert) + { + } + } +} |