diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-06-25 21:18:38 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-06-25 21:18:38 +0700 |
commit | 499bafdd45b0f8c14f74023b38b29fc3ebb5611d (patch) | |
tree | 87153088006b67c2ef36d743c361d1bf22da3675 /crypto/src/asn1/x509/X509CertificateStructure.cs | |
parent | RSA: Use input range check from fips (diff) | |
download | BouncyCastle.NET-ed25519-499bafdd45b0f8c14f74023b38b29fc3ebb5611d.tar.xz |
Refactoring in Asn1.IsisMtt
Diffstat (limited to '')
-rw-r--r-- | crypto/src/asn1/x509/X509CertificateStructure.cs | 128 |
1 files changed, 48 insertions, 80 deletions
diff --git a/crypto/src/asn1/x509/X509CertificateStructure.cs b/crypto/src/asn1/x509/X509CertificateStructure.cs index 5394b2be3..aed326d44 100644 --- a/crypto/src/asn1/x509/X509CertificateStructure.cs +++ b/crypto/src/asn1/x509/X509CertificateStructure.cs @@ -1,7 +1,5 @@ using System; -using Org.BouncyCastle.Asn1.Pkcs; - namespace Org.BouncyCastle.Asn1.X509 { /** @@ -17,15 +15,6 @@ namespace Org.BouncyCastle.Asn1.X509 public class X509CertificateStructure : Asn1Encodable { - private readonly TbsCertificateStructure tbsCert; - private readonly AlgorithmIdentifier sigAlgID; - private readonly DerBitString sig; - - public static X509CertificateStructure GetInstance(Asn1TaggedObject obj, bool explicitly) - { - return GetInstance(Asn1Sequence.GetInstance(obj, explicitly)); - } - public static X509CertificateStructure GetInstance(object obj) { if (obj == null) @@ -35,95 +24,74 @@ namespace Org.BouncyCastle.Asn1.X509 return new X509CertificateStructure(Asn1Sequence.GetInstance(obj)); } - public X509CertificateStructure( - TbsCertificateStructure tbsCert, - AlgorithmIdentifier sigAlgID, - DerBitString sig) + public static X509CertificateStructure GetInstance(Asn1TaggedObject obj, bool explicitly) => + new X509CertificateStructure(Asn1Sequence.GetInstance(obj, explicitly)); + + public static X509CertificateStructure GetOptional(Asn1Encodable element) + { + if (element == null) + throw new ArgumentNullException(nameof(element)); + + if (element is X509CertificateStructure x509CertificateStructure) + return x509CertificateStructure; + + Asn1Sequence asn1Sequence = Asn1Sequence.GetOptional(element); + if (asn1Sequence != null) + return new X509CertificateStructure(asn1Sequence); + + return null; + } + + public static X509CertificateStructure GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) => + new X509CertificateStructure(Asn1Sequence.GetTagged(taggedObject, declaredExplicit)); + + private readonly TbsCertificateStructure m_tbsCert; + private readonly AlgorithmIdentifier m_sigAlgID; + private readonly DerBitString m_sig; + + public X509CertificateStructure(TbsCertificateStructure tbsCert, AlgorithmIdentifier sigAlgID, DerBitString sig) { - if (tbsCert == null) - throw new ArgumentNullException("tbsCert"); - if (sigAlgID == null) - throw new ArgumentNullException("sigAlgID"); - if (sig == null) - throw new ArgumentNullException("sig"); - - this.tbsCert = tbsCert; - this.sigAlgID = sigAlgID; - this.sig = sig; + m_tbsCert = tbsCert ?? throw new ArgumentNullException(nameof(tbsCert)); + m_sigAlgID = sigAlgID ?? throw new ArgumentNullException(nameof(sigAlgID)); + m_sig = sig ?? throw new ArgumentNullException(nameof(sig)); } - private X509CertificateStructure( - Asn1Sequence seq) + private X509CertificateStructure(Asn1Sequence seq) { - if (seq.Count != 3) - throw new ArgumentException("sequence wrong size for a certificate", "seq"); + int count = seq.Count; + if (count != 3) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); // // correct x509 certficate // - tbsCert = TbsCertificateStructure.GetInstance(seq[0]); - sigAlgID = AlgorithmIdentifier.GetInstance(seq[1]); - sig = DerBitString.GetInstance(seq[2]); + m_tbsCert = TbsCertificateStructure.GetInstance(seq[0]); + m_sigAlgID = AlgorithmIdentifier.GetInstance(seq[1]); + m_sig = DerBitString.GetInstance(seq[2]); } - public TbsCertificateStructure TbsCertificate - { - get { return tbsCert; } - } + public TbsCertificateStructure TbsCertificate => m_tbsCert; - public int Version - { - get { return tbsCert.Version; } - } + public int Version => m_tbsCert.Version; - public DerInteger SerialNumber - { - get { return tbsCert.SerialNumber; } - } + public DerInteger SerialNumber => m_tbsCert.SerialNumber; - public X509Name Issuer - { - get { return tbsCert.Issuer; } - } + public X509Name Issuer => m_tbsCert.Issuer; - public Time StartDate - { - get { return tbsCert.StartDate; } - } + public Time StartDate => m_tbsCert.StartDate; - public Time EndDate - { - get { return tbsCert.EndDate; } - } + public Time EndDate => m_tbsCert.EndDate; - public X509Name Subject - { - get { return tbsCert.Subject; } - } + public X509Name Subject => m_tbsCert.Subject; - public SubjectPublicKeyInfo SubjectPublicKeyInfo - { - get { return tbsCert.SubjectPublicKeyInfo; } - } + public SubjectPublicKeyInfo SubjectPublicKeyInfo => m_tbsCert.SubjectPublicKeyInfo; - public AlgorithmIdentifier SignatureAlgorithm - { - get { return sigAlgID; } - } + public AlgorithmIdentifier SignatureAlgorithm => m_sigAlgID; - public DerBitString Signature - { - get { return sig; } - } + public DerBitString Signature => m_sig; - public byte[] GetSignatureOctets() - { - return sig.GetOctets(); - } + public byte[] GetSignatureOctets() => m_sig.GetOctets(); - public override Asn1Object ToAsn1Object() - { - return new DerSequence(tbsCert, sigAlgID, sig); - } + public override Asn1Object ToAsn1Object() => new DerSequence(m_tbsCert, m_sigAlgID, m_sig); } } |