diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-01-17 20:32:13 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-01-17 20:32:13 +0700 |
commit | 2e1dc7df1b47554ed229b65b9574973b43541a10 (patch) | |
tree | fd8b51ede5fe64ef823d8eb60c5db17e40f31544 /crypto/src/asn1/esf/SignaturePolicyId.cs | |
parent | FIx fetching of DateOfCertGen extension (diff) | |
download | BouncyCastle.NET-ed25519-2e1dc7df1b47554ed229b65b9574973b43541a10.tar.xz |
Refactoring in Asn1
Diffstat (limited to 'crypto/src/asn1/esf/SignaturePolicyId.cs')
-rw-r--r-- | crypto/src/asn1/esf/SignaturePolicyId.cs | 96 |
1 files changed, 40 insertions, 56 deletions
diff --git a/crypto/src/asn1/esf/SignaturePolicyId.cs b/crypto/src/asn1/esf/SignaturePolicyId.cs index 21bb40560..84e9f8c62 100644 --- a/crypto/src/asn1/esf/SignaturePolicyId.cs +++ b/crypto/src/asn1/esf/SignaturePolicyId.cs @@ -21,119 +21,103 @@ namespace Org.BouncyCastle.Asn1.Esf public class SignaturePolicyId : Asn1Encodable { - private readonly DerObjectIdentifier sigPolicyIdentifier; - private readonly OtherHashAlgAndValue sigPolicyHash; - private readonly Asn1Sequence sigPolicyQualifiers; + private readonly DerObjectIdentifier m_sigPolicyIdentifier; + private readonly OtherHashAlgAndValue m_sigPolicyHash; + private readonly Asn1Sequence m_sigPolicyQualifiers; - public static SignaturePolicyId GetInstance( - object obj) + public static SignaturePolicyId GetInstance(object obj) { - if (obj == null || obj is SignaturePolicyId) - return (SignaturePolicyId) obj; + if (obj == null) + return null; + + if (obj is SignaturePolicyId signaturePolicyId) + return signaturePolicyId; - if (obj is Asn1Sequence) - return new SignaturePolicyId((Asn1Sequence) obj); + if (obj is Asn1Sequence asn1Sequence) + return new SignaturePolicyId(asn1Sequence); - throw new ArgumentException( - "Unknown object in 'SignaturePolicyId' factory: " - + Platform.GetTypeName(obj), - "obj"); + throw new ArgumentException("Unknown object in 'SignaturePolicyId' factory: " + Platform.GetTypeName(obj), + nameof(obj)); } - private SignaturePolicyId( - Asn1Sequence seq) + private SignaturePolicyId(Asn1Sequence seq) { if (seq == null) - throw new ArgumentNullException("seq"); + throw new ArgumentNullException(nameof(seq)); if (seq.Count < 2 || seq.Count > 3) - throw new ArgumentException("Bad sequence size: " + seq.Count, "seq"); + throw new ArgumentException("Bad sequence size: " + seq.Count, nameof(seq)); - this.sigPolicyIdentifier = (DerObjectIdentifier) seq[0].ToAsn1Object(); - this.sigPolicyHash = OtherHashAlgAndValue.GetInstance(seq[1].ToAsn1Object()); + m_sigPolicyIdentifier = (DerObjectIdentifier)seq[0].ToAsn1Object(); + m_sigPolicyHash = OtherHashAlgAndValue.GetInstance(seq[1].ToAsn1Object()); if (seq.Count > 2) { - this.sigPolicyQualifiers = (Asn1Sequence) seq[2].ToAsn1Object(); + m_sigPolicyQualifiers = (Asn1Sequence)seq[2].ToAsn1Object(); } } - public SignaturePolicyId( - DerObjectIdentifier sigPolicyIdentifier, - OtherHashAlgAndValue sigPolicyHash) + public SignaturePolicyId(DerObjectIdentifier sigPolicyIdentifier, OtherHashAlgAndValue sigPolicyHash) : this(sigPolicyIdentifier, sigPolicyHash, null) { } - public SignaturePolicyId( - DerObjectIdentifier sigPolicyIdentifier, - OtherHashAlgAndValue sigPolicyHash, + public SignaturePolicyId(DerObjectIdentifier sigPolicyIdentifier, OtherHashAlgAndValue sigPolicyHash, params SigPolicyQualifierInfo[] sigPolicyQualifiers) { if (sigPolicyIdentifier == null) - throw new ArgumentNullException("sigPolicyIdentifier"); + throw new ArgumentNullException(nameof(sigPolicyIdentifier)); if (sigPolicyHash == null) - throw new ArgumentNullException("sigPolicyHash"); + throw new ArgumentNullException(nameof(sigPolicyHash)); - this.sigPolicyIdentifier = sigPolicyIdentifier; - this.sigPolicyHash = sigPolicyHash; + m_sigPolicyIdentifier = sigPolicyIdentifier; + m_sigPolicyHash = sigPolicyHash; if (sigPolicyQualifiers != null) { - this.sigPolicyQualifiers = new DerSequence(sigPolicyQualifiers); + m_sigPolicyQualifiers = new DerSequence(sigPolicyQualifiers); } } - public SignaturePolicyId( - DerObjectIdentifier sigPolicyIdentifier, - OtherHashAlgAndValue sigPolicyHash, + public SignaturePolicyId(DerObjectIdentifier sigPolicyIdentifier, OtherHashAlgAndValue sigPolicyHash, IEnumerable<SigPolicyQualifierInfo> sigPolicyQualifiers) { - if (sigPolicyIdentifier == null) - throw new ArgumentNullException("sigPolicyIdentifier"); - if (sigPolicyHash == null) - throw new ArgumentNullException("sigPolicyHash"); + if (sigPolicyIdentifier == null) + throw new ArgumentNullException(nameof(sigPolicyIdentifier)); + if (sigPolicyHash == null) + throw new ArgumentNullException(nameof(sigPolicyHash)); - this.sigPolicyIdentifier = sigPolicyIdentifier; - this.sigPolicyHash = sigPolicyHash; + m_sigPolicyIdentifier = sigPolicyIdentifier; + m_sigPolicyHash = sigPolicyHash; if (sigPolicyQualifiers != null) { - this.sigPolicyQualifiers = new DerSequence( - Asn1EncodableVector.FromEnumerable(sigPolicyQualifiers)); + m_sigPolicyQualifiers = new DerSequence(Asn1EncodableVector.FromEnumerable(sigPolicyQualifiers)); } } public DerObjectIdentifier SigPolicyIdentifier { - get { return sigPolicyIdentifier; } + get { return m_sigPolicyIdentifier; } } public OtherHashAlgAndValue SigPolicyHash { - get { return sigPolicyHash; } + get { return m_sigPolicyHash; } } public SigPolicyQualifierInfo[] GetSigPolicyQualifiers() { - if (sigPolicyQualifiers == null) - return null; - - SigPolicyQualifierInfo[] infos = new SigPolicyQualifierInfo[sigPolicyQualifiers.Count]; - for (int i = 0; i < sigPolicyQualifiers.Count; ++i) - { - infos[i] = SigPolicyQualifierInfo.GetInstance(sigPolicyQualifiers[i]); - } - return infos; + return m_sigPolicyQualifiers?.MapElements(SigPolicyQualifierInfo.GetInstance); } public override Asn1Object ToAsn1Object() { Asn1EncodableVector v = new Asn1EncodableVector( - sigPolicyIdentifier, sigPolicyHash.ToAsn1Object()); + m_sigPolicyIdentifier, m_sigPolicyHash.ToAsn1Object()); - if (sigPolicyQualifiers != null) + if (m_sigPolicyQualifiers != null) { - v.Add(sigPolicyQualifiers.ToAsn1Object()); + v.Add(m_sigPolicyQualifiers.ToAsn1Object()); } return new DerSequence(v); |