diff options
Diffstat (limited to 'crypto/src/asn1/ocsp/CertID.cs')
-rw-r--r-- | crypto/src/asn1/ocsp/CertID.cs | 72 |
1 files changed, 29 insertions, 43 deletions
diff --git a/crypto/src/asn1/ocsp/CertID.cs b/crypto/src/asn1/ocsp/CertID.cs index 12a111ec9..46e210032 100644 --- a/crypto/src/asn1/ocsp/CertID.cs +++ b/crypto/src/asn1/ocsp/CertID.cs @@ -4,19 +4,9 @@ using Org.BouncyCastle.Asn1.X509; namespace Org.BouncyCastle.Asn1.Ocsp { - public class CertID + public class CertID : Asn1Encodable { - private readonly AlgorithmIdentifier hashAlgorithm; - private readonly Asn1OctetString issuerNameHash; - private readonly Asn1OctetString issuerKeyHash; - private readonly DerInteger serialNumber; - - public static CertID GetInstance(Asn1TaggedObject obj, bool explicitly) - { - return GetInstance(Asn1Sequence.GetInstance(obj, explicitly)); - } - public static CertID GetInstance(object obj) { if (obj == null) @@ -26,48 +16,44 @@ namespace Org.BouncyCastle.Asn1.Ocsp return new CertID(Asn1Sequence.GetInstance(obj)); } - public CertID( - AlgorithmIdentifier hashAlgorithm, - Asn1OctetString issuerNameHash, - Asn1OctetString issuerKeyHash, - DerInteger serialNumber) + public static CertID GetInstance(Asn1TaggedObject obj, bool explicitly) + { + return new CertID(Asn1Sequence.GetInstance(obj, explicitly)); + } + + private readonly AlgorithmIdentifier m_hashAlgorithm; + private readonly Asn1OctetString m_issuerNameHash; + private readonly Asn1OctetString m_issuerKeyHash; + private readonly DerInteger m_serialNumber; + + public CertID(AlgorithmIdentifier hashAlgorithm, Asn1OctetString issuerNameHash, Asn1OctetString issuerKeyHash, + DerInteger serialNumber) { - this.hashAlgorithm = hashAlgorithm; - this.issuerNameHash = issuerNameHash; - this.issuerKeyHash = issuerKeyHash; - this.serialNumber = serialNumber; + m_hashAlgorithm = hashAlgorithm ?? throw new ArgumentNullException(nameof(hashAlgorithm)); + m_issuerNameHash = issuerNameHash ?? throw new ArgumentNullException(nameof(issuerNameHash)); + m_issuerKeyHash = issuerKeyHash ?? throw new ArgumentNullException(nameof(issuerKeyHash)); + m_serialNumber = serialNumber ?? throw new ArgumentNullException(nameof(serialNumber)); } private CertID(Asn1Sequence seq) { - if (seq.Count != 4) - throw new ArgumentException("Wrong number of elements in sequence", "seq"); + int count = seq.Count; + if (count != 4) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); - this.hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[0]); - this.issuerNameHash = Asn1OctetString.GetInstance(seq[1]); - this.issuerKeyHash = Asn1OctetString.GetInstance(seq[2]); - this.serialNumber = DerInteger.GetInstance(seq[3]); + m_hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[0]); + m_issuerNameHash = Asn1OctetString.GetInstance(seq[1]); + m_issuerKeyHash = Asn1OctetString.GetInstance(seq[2]); + m_serialNumber = DerInteger.GetInstance(seq[3]); } - public AlgorithmIdentifier HashAlgorithm - { - get { return hashAlgorithm; } - } + public AlgorithmIdentifier HashAlgorithm => m_hashAlgorithm; - public Asn1OctetString IssuerNameHash - { - get { return issuerNameHash; } - } + public Asn1OctetString IssuerNameHash => m_issuerNameHash; - public Asn1OctetString IssuerKeyHash - { - get { return issuerKeyHash; } - } + public Asn1OctetString IssuerKeyHash => m_issuerKeyHash; - public DerInteger SerialNumber - { - get { return serialNumber; } - } + public DerInteger SerialNumber => m_serialNumber; /** * Produce an object suitable for an Asn1OutputStream. @@ -81,7 +67,7 @@ namespace Org.BouncyCastle.Asn1.Ocsp */ public override Asn1Object ToAsn1Object() { - return new DerSequence(hashAlgorithm, issuerNameHash, issuerKeyHash, serialNumber); + return new DerSequence(m_hashAlgorithm, m_issuerNameHash, m_issuerKeyHash, m_serialNumber); } } } |