diff options
Diffstat (limited to 'crypto/src/asn1/pkcs/IssuerAndSerialNumber.cs')
-rw-r--r-- | crypto/src/asn1/pkcs/IssuerAndSerialNumber.cs | 72 |
1 files changed, 28 insertions, 44 deletions
diff --git a/crypto/src/asn1/pkcs/IssuerAndSerialNumber.cs b/crypto/src/asn1/pkcs/IssuerAndSerialNumber.cs index da863cb62..0a2c05d41 100644 --- a/crypto/src/asn1/pkcs/IssuerAndSerialNumber.cs +++ b/crypto/src/asn1/pkcs/IssuerAndSerialNumber.cs @@ -2,71 +2,55 @@ using System; using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Math; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.Pkcs { public class IssuerAndSerialNumber : Asn1Encodable { - private readonly X509Name name; - private readonly DerInteger certSerialNumber; - - public static IssuerAndSerialNumber GetInstance( - object obj) + public static IssuerAndSerialNumber GetInstance(object obj) { - if (obj is IssuerAndSerialNumber) - { - return (IssuerAndSerialNumber) obj; - } + if (obj == null) + return null; + if (obj is IssuerAndSerialNumber issuerAndSerialNumber) + return issuerAndSerialNumber; + return new IssuerAndSerialNumber(Asn1Sequence.GetInstance(obj)); + } - if (obj is Asn1Sequence) - { - return new IssuerAndSerialNumber((Asn1Sequence) obj); - } + public static IssuerAndSerialNumber GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) + { + return new IssuerAndSerialNumber(Asn1Sequence.GetInstance(taggedObject, declaredExplicit)); + } - throw new ArgumentException("Unknown object in factory: " + Platform.GetTypeName(obj), "obj"); - } + private readonly X509Name m_name; + private readonly DerInteger m_certSerialNumber; - private IssuerAndSerialNumber( - Asn1Sequence seq) + private IssuerAndSerialNumber(Asn1Sequence seq) { - if (seq.Count != 2) - throw new ArgumentException("Wrong number of elements in sequence", "seq"); + int count = seq.Count; + if (count != 2) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); - this.name = X509Name.GetInstance(seq[0]); - this.certSerialNumber = DerInteger.GetInstance(seq[1]); + m_name = X509Name.GetInstance(seq[0]); + m_certSerialNumber = DerInteger.GetInstance(seq[1]); } - public IssuerAndSerialNumber( - X509Name name, - BigInteger certSerialNumber) + public IssuerAndSerialNumber(X509Name name, BigInteger certSerialNumber) { - this.name = name; - this.certSerialNumber = new DerInteger(certSerialNumber); + m_name = name ?? throw new ArgumentNullException(nameof(name)); + m_certSerialNumber = new DerInteger(certSerialNumber); } - public IssuerAndSerialNumber( - X509Name name, - DerInteger certSerialNumber) + public IssuerAndSerialNumber(X509Name name, DerInteger certSerialNumber) { - this.name = name; - this.certSerialNumber = certSerialNumber; + m_name = name ?? throw new ArgumentNullException(nameof(name)); + m_certSerialNumber = certSerialNumber ?? throw new ArgumentNullException(nameof(certSerialNumber)); } - public X509Name Name - { - get { return name; } - } + public X509Name Name => m_name; - public DerInteger CertificateSerialNumber - { - get { return certSerialNumber; } - } + public DerInteger CertificateSerialNumber => m_certSerialNumber; - public override Asn1Object ToAsn1Object() - { - return new DerSequence(name, certSerialNumber); - } + public override Asn1Object ToAsn1Object() => new DerSequence(m_name, m_certSerialNumber); } } |