diff options
Diffstat (limited to '')
29 files changed, 118 insertions, 146 deletions
diff --git a/crypto/src/asn1/cms/AuthEnvelopedData.cs b/crypto/src/asn1/cms/AuthEnvelopedData.cs index 4ca86e9df..8f980e6ec 100644 --- a/crypto/src/asn1/cms/AuthEnvelopedData.cs +++ b/crypto/src/asn1/cms/AuthEnvelopedData.cs @@ -49,8 +49,7 @@ namespace Org.BouncyCastle.Asn1.Cms this.unauthAttrs = unauthAttrs; } - private AuthEnvelopedData( - Asn1Sequence seq) + private AuthEnvelopedData(Asn1Sequence seq) { int index = 0; @@ -61,9 +60,9 @@ namespace Org.BouncyCastle.Asn1.Cms throw new ArgumentException("AuthEnvelopedData version number must be 0"); tmp = seq[index++].ToAsn1Object(); - if (tmp is Asn1TaggedObject) + if (tmp is Asn1TaggedObject taggedObject1) { - originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false); + originatorInfo = OriginatorInfo.GetInstance(taggedObject1, false); tmp = seq[index++].ToAsn1Object(); } @@ -76,9 +75,9 @@ namespace Org.BouncyCastle.Asn1.Cms authEncryptedContentInfo = EncryptedContentInfo.GetInstance(tmp); tmp = seq[index++].ToAsn1Object(); - if (tmp is Asn1TaggedObject) + if (tmp is Asn1TaggedObject taggedObject2) { - authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false); + authAttrs = Asn1Set.GetInstance(taggedObject2, false); tmp = seq[index++].ToAsn1Object(); } else diff --git a/crypto/src/asn1/cms/AuthenticatedData.cs b/crypto/src/asn1/cms/AuthenticatedData.cs index eb9f82031..6ec8061e2 100644 --- a/crypto/src/asn1/cms/AuthenticatedData.cs +++ b/crypto/src/asn1/cms/AuthenticatedData.cs @@ -48,17 +48,16 @@ namespace Org.BouncyCastle.Asn1.Cms this.unauthAttrs = unauthAttrs; } - private AuthenticatedData( - Asn1Sequence seq) + private AuthenticatedData(Asn1Sequence seq) { int index = 0; version = (DerInteger)seq[index++]; Asn1Encodable tmp = seq[index++]; - if (tmp is Asn1TaggedObject) + if (tmp is Asn1TaggedObject taggedObject1) { - originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false); + originatorInfo = OriginatorInfo.GetInstance(taggedObject1, false); tmp = seq[index++]; } @@ -66,18 +65,18 @@ namespace Org.BouncyCastle.Asn1.Cms macAlgorithm = AlgorithmIdentifier.GetInstance(seq[index++]); tmp = seq[index++]; - if (tmp is Asn1TaggedObject) + if (tmp is Asn1TaggedObject taggedObject2) { - digestAlgorithm = AlgorithmIdentifier.GetInstance((Asn1TaggedObject)tmp, false); + digestAlgorithm = AlgorithmIdentifier.GetInstance(taggedObject2, false); tmp = seq[index++]; } encapsulatedContentInfo = ContentInfo.GetInstance(tmp); tmp = seq[index++]; - if (tmp is Asn1TaggedObject) + if (tmp is Asn1TaggedObject taggedObject3) { - authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false); + authAttrs = Asn1Set.GetInstance(taggedObject3, false); tmp = seq[index++]; } diff --git a/crypto/src/asn1/cms/EnvelopedData.cs b/crypto/src/asn1/cms/EnvelopedData.cs index 45e9c5c76..85216a2e8 100644 --- a/crypto/src/asn1/cms/EnvelopedData.cs +++ b/crypto/src/asn1/cms/EnvelopedData.cs @@ -45,9 +45,9 @@ namespace Org.BouncyCastle.Asn1.Cms object tmp = seq[index++]; - if (tmp is Asn1TaggedObject) + if (tmp is Asn1TaggedObject taggedObject) { - originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject) tmp, false); + originatorInfo = OriginatorInfo.GetInstance(taggedObject, false); tmp = seq[index++]; } @@ -56,7 +56,7 @@ namespace Org.BouncyCastle.Asn1.Cms if (seq.Count > index) { - unprotectedAttrs = Asn1Set.GetInstance((Asn1TaggedObject) seq[index], false); + unprotectedAttrs = Asn1Set.GetInstance((Asn1TaggedObject)seq[index], false); } } diff --git a/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs b/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs index 52eb7d4d3..be2d76e2c 100644 --- a/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs +++ b/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs @@ -27,25 +27,22 @@ namespace Org.BouncyCastle.Asn1.Cms this.recipientEncryptedKeys = recipientEncryptedKeys; } - public KeyAgreeRecipientInfo( - Asn1Sequence seq) + public KeyAgreeRecipientInfo(Asn1Sequence seq) { int index = 0; version = (DerInteger) seq[index++]; - originator = OriginatorIdentifierOrKey.GetInstance( - (Asn1TaggedObject) seq[index++], true); + originator = OriginatorIdentifierOrKey.GetInstance((Asn1TaggedObject)seq[index++], true); - if (seq[index] is Asn1TaggedObject) + if (seq[index] is Asn1TaggedObject taggedObject) { - ukm = Asn1OctetString.GetInstance( - (Asn1TaggedObject) seq[index++], true); + ukm = Asn1OctetString.GetInstance(taggedObject, true); + ++index; } - keyEncryptionAlgorithm = AlgorithmIdentifier.GetInstance( - seq[index++]); + keyEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[index++]); - recipientEncryptedKeys = (Asn1Sequence) seq[index++]; + recipientEncryptedKeys = (Asn1Sequence)seq[index++]; } /** diff --git a/crypto/src/asn1/cms/MetaData.cs b/crypto/src/asn1/cms/MetaData.cs index ad2b5c426..6435d4d2e 100644 --- a/crypto/src/asn1/cms/MetaData.cs +++ b/crypto/src/asn1/cms/MetaData.cs @@ -28,15 +28,17 @@ namespace Org.BouncyCastle.Asn1.Cms int index = 1; - if (index < seq.Count && seq[index] is DerUtf8String) + if (index < seq.Count && seq[index] is DerUtf8String utf8) { - this.fileName = DerUtf8String.GetInstance(seq[index++]); + this.fileName = utf8; + ++index; } - if (index < seq.Count && seq[index] is DerIA5String) + if (index < seq.Count && seq[index] is DerIA5String ia5) { - this.mediaType = DerIA5String.GetInstance(seq[index++]); - } - if (index < seq.Count) + this.mediaType = ia5; + ++index; + } + if (index < seq.Count) { this.otherMetaData = Attributes.GetInstance(seq[index++]); } diff --git a/crypto/src/asn1/cms/PasswordRecipientInfo.cs b/crypto/src/asn1/cms/PasswordRecipientInfo.cs index 596dd9537..9fb639bf3 100644 --- a/crypto/src/asn1/cms/PasswordRecipientInfo.cs +++ b/crypto/src/asn1/cms/PasswordRecipientInfo.cs @@ -33,21 +33,20 @@ namespace Org.BouncyCastle.Asn1.Cms this.encryptedKey = encryptedKey; } - public PasswordRecipientInfo( - Asn1Sequence seq) + public PasswordRecipientInfo(Asn1Sequence seq) { - version = (DerInteger) seq[0]; + version = (DerInteger)seq[0]; - if (seq[1] is Asn1TaggedObject) + if (seq[1] is Asn1TaggedObject taggedObject) { - keyDerivationAlgorithm = AlgorithmIdentifier.GetInstance((Asn1TaggedObject) seq[1], false); + keyDerivationAlgorithm = AlgorithmIdentifier.GetInstance(taggedObject, false); keyEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[2]); - encryptedKey = (Asn1OctetString) seq[3]; + encryptedKey = (Asn1OctetString)seq[3]; } else { keyEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[1]); - encryptedKey = (Asn1OctetString) seq[2]; + encryptedKey = (Asn1OctetString)seq[2]; } } diff --git a/crypto/src/asn1/cms/RecipientKeyIdentifier.cs b/crypto/src/asn1/cms/RecipientKeyIdentifier.cs index 512025808..60a6151bf 100644 --- a/crypto/src/asn1/cms/RecipientKeyIdentifier.cs +++ b/crypto/src/asn1/cms/RecipientKeyIdentifier.cs @@ -43,24 +43,24 @@ namespace Org.BouncyCastle.Asn1.Cms switch(seq.Count) { - case 1: - break; - case 2: - if (seq[1] is Asn1GeneralizedTime asn1GeneralizedTime) - { - date = asn1GeneralizedTime; - } - else - { - other = OtherKeyAttribute.GetInstance(seq[2]); - } - break; - case 3: - date = (Asn1GeneralizedTime)seq[1]; + case 1: + break; + case 2: + if (seq[1] is Asn1GeneralizedTime asn1GeneralizedTime) + { + date = asn1GeneralizedTime; + } + else + { other = OtherKeyAttribute.GetInstance(seq[2]); - break; - default: - throw new ArgumentException("Invalid RecipientKeyIdentifier"); + } + break; + case 3: + date = (Asn1GeneralizedTime)seq[1]; + other = OtherKeyAttribute.GetInstance(seq[2]); + break; + default: + throw new ArgumentException("Invalid RecipientKeyIdentifier"); } } diff --git a/crypto/src/asn1/cms/SCVPReqRes.cs b/crypto/src/asn1/cms/SCVPReqRes.cs index 6544c852b..8b5f858a6 100644 --- a/crypto/src/asn1/cms/SCVPReqRes.cs +++ b/crypto/src/asn1/cms/SCVPReqRes.cs @@ -19,9 +19,9 @@ namespace Org.BouncyCastle.Asn1.Cms private ScvpReqRes(Asn1Sequence seq) { - if (seq[0] is Asn1TaggedObject) + if (seq[0] is Asn1TaggedObject taggedObject) { - this.request = ContentInfo.GetInstance(Asn1TaggedObject.GetInstance(seq[0]), true); + this.request = ContentInfo.GetInstance(taggedObject, true); this.response = ContentInfo.GetInstance(seq[1]); } else diff --git a/crypto/src/asn1/cms/TimeStampedData.cs b/crypto/src/asn1/cms/TimeStampedData.cs index 15448a923..f90e5b086 100644 --- a/crypto/src/asn1/cms/TimeStampedData.cs +++ b/crypto/src/asn1/cms/TimeStampedData.cs @@ -26,17 +26,19 @@ namespace Org.BouncyCastle.Asn1.Cms this.version = DerInteger.GetInstance(seq[0]); int index = 1; - if (seq[index] is DerIA5String) + if (seq[index] is DerIA5String ia5) { - this.dataUri = DerIA5String.GetInstance(seq[index++]); + this.dataUri = ia5; + ++index; } if (seq[index] is MetaData || seq[index] is Asn1Sequence) { this.metaData = MetaData.GetInstance(seq[index++]); } - if (seq[index] is Asn1OctetString) + if (seq[index] is Asn1OctetString octets) { - this.content = Asn1OctetString.GetInstance(seq[index++]); + this.content = octets; + ++index; } this.temporalEvidence = Evidence.GetInstance(seq[index]); } diff --git a/crypto/src/asn1/crmf/EncKeyWithID.cs b/crypto/src/asn1/crmf/EncKeyWithID.cs index 6de56fa0b..67c16605a 100644 --- a/crypto/src/asn1/crmf/EncKeyWithID.cs +++ b/crypto/src/asn1/crmf/EncKeyWithID.cs @@ -34,7 +34,7 @@ namespace Org.BouncyCastle.Asn1.Crmf } else { - this.identifier = (Asn1Encodable)seq[1]; + this.identifier = seq[1]; } } else diff --git a/crypto/src/asn1/esf/SignerAttribute.cs b/crypto/src/asn1/esf/SignerAttribute.cs index f90968cf8..03cdd4ba8 100644 --- a/crypto/src/asn1/esf/SignerAttribute.cs +++ b/crypto/src/asn1/esf/SignerAttribute.cs @@ -26,11 +26,10 @@ namespace Org.BouncyCastle.Asn1.Esf "obj"); } - private SignerAttribute( - object obj) + private SignerAttribute(object obj) { - Asn1Sequence seq = (Asn1Sequence) obj; - DerTaggedObject taggedObject = (DerTaggedObject) seq[0]; + Asn1Sequence seq = (Asn1Sequence)obj; + Asn1TaggedObject taggedObject = (Asn1TaggedObject)seq[0]; if (taggedObject.TagNo == 0) { claimedAttributes = Asn1Sequence.GetInstance(taggedObject, true); diff --git a/crypto/src/asn1/isismtt/x509/AdmissionSyntax.cs b/crypto/src/asn1/isismtt/x509/AdmissionSyntax.cs index eac5d9a1a..424d73c69 100644 --- a/crypto/src/asn1/isismtt/x509/AdmissionSyntax.cs +++ b/crypto/src/asn1/isismtt/x509/AdmissionSyntax.cs @@ -172,20 +172,19 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 * * @param seq The ASN.1 sequence. */ - private AdmissionSyntax( - Asn1Sequence seq) + private AdmissionSyntax(Asn1Sequence seq) { switch (seq.Count) { - case 1: - this.contentsOfAdmissions = DerSequence.GetInstance(seq[0]); - break; - case 2: - admissionAuthority = GeneralName.GetInstance(seq[0]); - contentsOfAdmissions = DerSequence.GetInstance(seq[1]); - break; - default: - throw new ArgumentException("Bad sequence size: " + seq.Count); + case 1: + this.contentsOfAdmissions = Asn1Sequence.GetInstance(seq[0]); + break; + case 2: + admissionAuthority = GeneralName.GetInstance(seq[0]); + contentsOfAdmissions = Asn1Sequence.GetInstance(seq[1]); + break; + default: + throw new ArgumentException("Bad sequence size: " + seq.Count); } } diff --git a/crypto/src/asn1/nist/KMACwithSHAKE128_params.cs b/crypto/src/asn1/nist/KMACwithSHAKE128_params.cs index df2bf0173..ca94b5bfe 100644 --- a/crypto/src/asn1/nist/KMACwithSHAKE128_params.cs +++ b/crypto/src/asn1/nist/KMACwithSHAKE128_params.cs @@ -56,9 +56,9 @@ public class KMacWithShake128Params : Asn1Encodable } else if (seq.Count == 1) { - if (seq[0] is DerInteger) + if (seq[0] is DerInteger derInteger) { - this.outputLength = DerInteger.GetInstance(seq[0]).IntValueExact; + this.outputLength = derInteger.IntValueExact; this.customizationString = EMPTY_STRING; } else diff --git a/crypto/src/asn1/nist/KMACwithSHAKE256_params.cs b/crypto/src/asn1/nist/KMACwithSHAKE256_params.cs index dfdfb2c36..99f444e7f 100644 --- a/crypto/src/asn1/nist/KMACwithSHAKE256_params.cs +++ b/crypto/src/asn1/nist/KMACwithSHAKE256_params.cs @@ -55,9 +55,9 @@ public class KMacWithShake256Params : Asn1Encodable } else if (seq.Count == 1) { - if (seq[0] is DerInteger) + if (seq[0] is DerInteger derInteger) { - this.outputLength = DerInteger.GetInstance(seq[0]).IntValueExact; + this.outputLength = derInteger.IntValueExact; this.customizationString = EMPTY_STRING; } else diff --git a/crypto/src/asn1/ocsp/ResponderID.cs b/crypto/src/asn1/ocsp/ResponderID.cs index 143b17339..bc8b7f731 100644 --- a/crypto/src/asn1/ocsp/ResponderID.cs +++ b/crypto/src/asn1/ocsp/ResponderID.cs @@ -10,27 +10,22 @@ namespace Org.BouncyCastle.Asn1.Ocsp { private readonly Asn1Encodable id; - public static ResponderID GetInstance( - object obj) + public static ResponderID GetInstance(object obj) { if (obj == null || obj is ResponderID) { return (ResponderID)obj; } - if (obj is DerOctetString) + if (obj is Asn1OctetString octets) { - return new ResponderID((DerOctetString)obj); + return new ResponderID(octets); } - if (obj is Asn1TaggedObject) + if (obj is Asn1TaggedObject o) { - Asn1TaggedObject o = (Asn1TaggedObject)obj; - if (o.TagNo == 1) - { return new ResponderID(X509Name.GetInstance(o, true)); - } return new ResponderID(Asn1OctetString.GetInstance(o, true)); } diff --git a/crypto/src/asn1/ocsp/ResponseData.cs b/crypto/src/asn1/ocsp/ResponseData.cs index b18e1d623..b79301997 100644 --- a/crypto/src/asn1/ocsp/ResponseData.cs +++ b/crypto/src/asn1/ocsp/ResponseData.cs @@ -63,16 +63,13 @@ namespace Org.BouncyCastle.Asn1.Ocsp { } - private ResponseData( - Asn1Sequence seq) + private ResponseData(Asn1Sequence seq) { int index = 0; Asn1Encodable enc = seq[0]; - if (enc is Asn1TaggedObject) + if (enc is Asn1TaggedObject o) { - Asn1TaggedObject o = (Asn1TaggedObject)enc; - if (o.TagNo == 0) { this.versionPresent = true; diff --git a/crypto/src/asn1/pkcs/CertificationRequestInfo.cs b/crypto/src/asn1/pkcs/CertificationRequestInfo.cs index b775014b2..795757533 100644 --- a/crypto/src/asn1/pkcs/CertificationRequestInfo.cs +++ b/crypto/src/asn1/pkcs/CertificationRequestInfo.cs @@ -71,7 +71,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs // if (seq.Count > 3) { - DerTaggedObject tagobj = (DerTaggedObject) seq[3]; + Asn1TaggedObject tagobj = (Asn1TaggedObject)seq[3]; attributes = Asn1Set.GetInstance(tagobj, false); } diff --git a/crypto/src/asn1/pkcs/EncryptedData.cs b/crypto/src/asn1/pkcs/EncryptedData.cs index cb04f343c..fdee60405 100644 --- a/crypto/src/asn1/pkcs/EncryptedData.cs +++ b/crypto/src/asn1/pkcs/EncryptedData.cs @@ -86,7 +86,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs { if (data.Count == 3) { - DerTaggedObject o = (DerTaggedObject) data[2]; + Asn1TaggedObject o = (Asn1TaggedObject)data[2]; return Asn1OctetString.GetInstance(o, false); } diff --git a/crypto/src/asn1/pkcs/SafeBag.cs b/crypto/src/asn1/pkcs/SafeBag.cs index 0ec9fa4ad..0c4f3972b 100644 --- a/crypto/src/asn1/pkcs/SafeBag.cs +++ b/crypto/src/asn1/pkcs/SafeBag.cs @@ -42,7 +42,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs private SafeBag(Asn1Sequence seq) { this.bagID = (DerObjectIdentifier)seq[0]; - this.bagValue = ((DerTaggedObject)seq[1]).GetObject(); + this.bagValue = ((Asn1TaggedObject)seq[1]).GetObject(); if (seq.Count == 3) { this.bagAttributes = (Asn1Set)seq[2]; diff --git a/crypto/src/asn1/tsp/Accuracy.cs b/crypto/src/asn1/tsp/Accuracy.cs index 0d64e2dd4..f9cd88014 100644 --- a/crypto/src/asn1/tsp/Accuracy.cs +++ b/crypto/src/asn1/tsp/Accuracy.cs @@ -40,20 +40,17 @@ namespace Org.BouncyCastle.Asn1.Tsp this.micros = micros; } - private Accuracy( - Asn1Sequence seq) + private Accuracy(Asn1Sequence seq) { for (int i = 0; i < seq.Count; ++i) { // seconds - if (seq[i] is DerInteger) + if (seq[i] is DerInteger derInteger) { - seconds = (DerInteger) seq[i]; + seconds = derInteger; } - else if (seq[i] is Asn1TaggedObject) + else if (seq[i] is Asn1TaggedObject extra) { - Asn1TaggedObject extra = (Asn1TaggedObject)seq[i]; - switch (extra.TagNo) { case 0: diff --git a/crypto/src/asn1/tsp/TSTInfo.cs b/crypto/src/asn1/tsp/TSTInfo.cs index c37208d3c..a8e166cbc 100644 --- a/crypto/src/asn1/tsp/TSTInfo.cs +++ b/crypto/src/asn1/tsp/TSTInfo.cs @@ -58,10 +58,8 @@ namespace Org.BouncyCastle.Asn1.Tsp { Asn1Object o = (Asn1Object) e.Current; - if (o is Asn1TaggedObject) + if (o is Asn1TaggedObject tagged) { - DerTaggedObject tagged = (DerTaggedObject) o; - switch (tagged.TagNo) { case 0: @@ -75,7 +73,7 @@ namespace Org.BouncyCastle.Asn1.Tsp } } - if (o is DerSequence) + if (o is Asn1Sequence) { accuracy = Accuracy.GetInstance(o); } diff --git a/crypto/src/asn1/tsp/TimeStampReq.cs b/crypto/src/asn1/tsp/TimeStampReq.cs index 7173172c4..027c0a45b 100644 --- a/crypto/src/asn1/tsp/TimeStampReq.cs +++ b/crypto/src/asn1/tsp/TimeStampReq.cs @@ -24,8 +24,7 @@ namespace Org.BouncyCastle.Asn1.Tsp return new TimeStampReq(Asn1Sequence.GetInstance(obj)); } - private TimeStampReq( - Asn1Sequence seq) + private TimeStampReq(Asn1Sequence seq) { int nbObjects = seq.Count; int seqStart = 0; @@ -39,24 +38,23 @@ namespace Org.BouncyCastle.Asn1.Tsp for (int opt = seqStart; opt < nbObjects; opt++) { // tsaPolicy - if (seq[opt] is DerObjectIdentifier) + if (seq[opt] is DerObjectIdentifier oid) { - tsaPolicy = DerObjectIdentifier.GetInstance(seq[opt]); + tsaPolicy = oid; } // nonce - else if (seq[opt] is DerInteger) + else if (seq[opt] is DerInteger derInteger) { - nonce = DerInteger.GetInstance(seq[opt]); + nonce = derInteger; } // certReq - else if (seq[opt] is DerBoolean) + else if (seq[opt] is DerBoolean derBoolean) { - certReq = DerBoolean.GetInstance(seq[opt]); + certReq = derBoolean; } // extensions - else if (seq[opt] is Asn1TaggedObject) + else if (seq[opt] is Asn1TaggedObject tagged) { - Asn1TaggedObject tagged = (Asn1TaggedObject) seq[opt]; if (tagged.TagNo == 0) { extensions = X509Extensions.GetInstance(tagged, false); diff --git a/crypto/src/asn1/x509/AttributeCertificateInfo.cs b/crypto/src/asn1/x509/AttributeCertificateInfo.cs index d466bbd14..dde432ee6 100644 --- a/crypto/src/asn1/x509/AttributeCertificateInfo.cs +++ b/crypto/src/asn1/x509/AttributeCertificateInfo.cs @@ -69,11 +69,11 @@ namespace Org.BouncyCastle.Asn1.X509 for (int i = start + 6; i < seq.Count; i++) { - Asn1Encodable obj = (Asn1Encodable) seq[i]; + Asn1Encodable obj = seq[i]; - if (obj is DerBitString) + if (obj is DerBitString bitString) { - this.issuerUniqueID = DerBitString.GetInstance(seq[i]); + this.issuerUniqueID = bitString; } else if (obj is Asn1Sequence || obj is X509Extensions) { diff --git a/crypto/src/asn1/x509/BasicConstraints.cs b/crypto/src/asn1/x509/BasicConstraints.cs index deecae241..acc8766a7 100644 --- a/crypto/src/asn1/x509/BasicConstraints.cs +++ b/crypto/src/asn1/x509/BasicConstraints.cs @@ -37,9 +37,9 @@ namespace Org.BouncyCastle.Asn1.X509 { if (seq.Count > 0) { - if (seq[0] is DerBoolean) + if (seq[0] is DerBoolean derBoolean) { - this.cA = DerBoolean.GetInstance(seq[0]); + this.cA = derBoolean; } else { diff --git a/crypto/src/asn1/x509/NoticeReference.cs b/crypto/src/asn1/x509/NoticeReference.cs index 2fb275d8f..22bb35b71 100644 --- a/crypto/src/asn1/x509/NoticeReference.cs +++ b/crypto/src/asn1/x509/NoticeReference.cs @@ -120,14 +120,7 @@ namespace Org.BouncyCastle.Asn1.X509 public virtual DerInteger[] GetNoticeNumbers() { - DerInteger[] tmp = new DerInteger[noticeNumbers.Count]; - - for (int i = 0; i != noticeNumbers.Count; ++i) - { - tmp[i] = DerInteger.GetInstance(noticeNumbers[i]); - } - - return tmp; + return noticeNumbers.MapElements(DerInteger.GetInstance); } /** diff --git a/crypto/src/asn1/x509/TBSCertList.cs b/crypto/src/asn1/x509/TBSCertList.cs index 009773e79..4cfb44c90 100644 --- a/crypto/src/asn1/x509/TBSCertList.cs +++ b/crypto/src/asn1/x509/TBSCertList.cs @@ -169,21 +169,19 @@ namespace Org.BouncyCastle.Asn1.X509 throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj"); } - internal TbsCertificateList( - Asn1Sequence seq) + internal TbsCertificateList(Asn1Sequence seq) { if (seq.Count < 3 || seq.Count > 7) - { throw new ArgumentException("Bad sequence size: " + seq.Count); - } int seqPos = 0; this.seq = seq; - if (seq[seqPos] is DerInteger) + if (seq[seqPos] is DerInteger derInteger) { - version = DerInteger.GetInstance(seq[seqPos++]); + version = derInteger; + ++seqPos; } else { diff --git a/crypto/src/asn1/x509/TBSCertificateStructure.cs b/crypto/src/asn1/x509/TBSCertificateStructure.cs index 5e3bf2601..e1fba2488 100644 --- a/crypto/src/asn1/x509/TBSCertificateStructure.cs +++ b/crypto/src/asn1/x509/TBSCertificateStructure.cs @@ -66,11 +66,11 @@ namespace Org.BouncyCastle.Asn1.X509 this.seq = seq; // - // some certficates don't include a version number - we assume v1 + // some certificates don't include a version number - we assume v1 // - if (seq[0] is Asn1TaggedObject) + if (seq[0] is Asn1TaggedObject taggedObject) { - version = DerInteger.GetInstance((Asn1TaggedObject)seq[0], true); + version = DerInteger.GetInstance(taggedObject, true); } else { diff --git a/crypto/src/asn1/x9/X9ECParameters.cs b/crypto/src/asn1/x9/X9ECParameters.cs index 077f74ce4..0f6d85765 100644 --- a/crypto/src/asn1/x9/X9ECParameters.cs +++ b/crypto/src/asn1/x9/X9ECParameters.cs @@ -54,9 +54,9 @@ namespace Org.BouncyCastle.Asn1.X9 this.curve = x9c.Curve; object p = seq[3]; - if (p is X9ECPoint) + if (p is X9ECPoint x9) { - this.g = (X9ECPoint)p; + this.g = x9; } else { diff --git a/crypto/src/pqc/crypto/utils/PqcPublicKeyFactory.cs b/crypto/src/pqc/crypto/utils/PqcPublicKeyFactory.cs index 7f863820e..3c9849799 100644 --- a/crypto/src/pqc/crypto/utils/PqcPublicKeyFactory.cs +++ b/crypto/src/pqc/crypto/utils/PqcPublicKeyFactory.cs @@ -225,7 +225,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Utilities internal override AsymmetricKeyParameter GetPublicKeyParameters(SubjectPublicKeyInfo keyInfo, object defaultParams) { byte[] keyEnc = Asn1OctetString.GetInstance( - DerSequence.GetInstance(keyInfo.ParsePublicKey())[0]).GetOctets(); + Asn1Sequence.GetInstance(keyInfo.ParsePublicKey())[0]).GetOctets(); SaberParameters saberParams = PqcUtilities.SaberParamsLookup(keyInfo.AlgorithmID.Algorithm); |