diff options
Diffstat (limited to 'crypto/src/asn1')
-rw-r--r-- | crypto/src/asn1/cms/SignedData.cs | 4 | ||||
-rw-r--r-- | crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs | 4 | ||||
-rw-r--r-- | crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs | 9 | ||||
-rw-r--r-- | crypto/src/asn1/esf/SignerLocation.cs | 16 | ||||
-rw-r--r-- | crypto/src/asn1/isismtt/x509/Admissions.cs | 10 | ||||
-rw-r--r-- | crypto/src/asn1/ocsp/CertID.cs | 30 | ||||
-rw-r--r-- | crypto/src/asn1/pkcs/CertBag.cs | 4 | ||||
-rw-r--r-- | crypto/src/asn1/pkcs/ContentInfo.cs | 7 | ||||
-rw-r--r-- | crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs | 20 | ||||
-rw-r--r-- | crypto/src/asn1/pkcs/PBEParameter.cs | 23 | ||||
-rw-r--r-- | crypto/src/asn1/pkcs/SignerInfo.cs | 24 | ||||
-rw-r--r-- | crypto/src/asn1/x509/AuthorityInformationAccess.cs | 6 | ||||
-rw-r--r-- | crypto/src/asn1/x509/ExtendedKeyUsage.cs | 4 | ||||
-rw-r--r-- | crypto/src/asn1/x509/NameConstraints.cs | 10 | ||||
-rw-r--r-- | crypto/src/asn1/x509/SubjectDirectoryAttributes.cs | 34 | ||||
-rw-r--r-- | crypto/src/asn1/x509/SubjectPublicKeyInfo.cs | 1 | ||||
-rw-r--r-- | crypto/src/asn1/x509/V2TBSCertListGenerator.cs | 2 | ||||
-rw-r--r-- | crypto/src/asn1/x509/X509ExtensionsGenerator.cs | 2 |
18 files changed, 66 insertions, 144 deletions
diff --git a/crypto/src/asn1/cms/SignedData.cs b/crypto/src/asn1/cms/SignedData.cs index 789f8bd72..6b07e5128 100644 --- a/crypto/src/asn1/cms/SignedData.cs +++ b/crypto/src/asn1/cms/SignedData.cs @@ -24,8 +24,8 @@ namespace Org.BouncyCastle.Asn1.Cms public static SignedData GetInstance(object obj) { - if (obj is SignedData) - return (SignedData)obj; + if (obj is SignedData signedData) + return signedData; if (obj == null) return null; return new SignedData(Asn1Sequence.GetInstance(obj)); diff --git a/crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs b/crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs index 87df3c4a9..2c494c526 100644 --- a/crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs +++ b/crypto/src/asn1/cryptopro/ECGOST3410ParamSetParameters.cs @@ -18,9 +18,7 @@ namespace Org.BouncyCastle.Asn1.CryptoPro public static ECGost3410ParamSetParameters GetInstance(object obj) { if (obj == null || obj is ECGost3410ParamSetParameters) - { - return (ECGost3410ParamSetParameters) obj; - } + return (ECGost3410ParamSetParameters)obj; if (obj is Asn1Sequence seq) return new ECGost3410ParamSetParameters(seq); diff --git a/crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs b/crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs index c82e4248a..ae0cd4f83 100644 --- a/crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs +++ b/crypto/src/asn1/cryptopro/GOST3410ParamSetParameters.cs @@ -27,11 +27,7 @@ namespace Org.BouncyCastle.Asn1.CryptoPro throw new ArgumentException("Invalid GOST3410Parameter: " + Platform.GetTypeName(obj)); } - public Gost3410ParamSetParameters( - int keySize, - BigInteger p, - BigInteger q, - BigInteger a) + public Gost3410ParamSetParameters(int keySize, BigInteger p, BigInteger q, BigInteger a) { this.keySize = keySize; this.p = new DerInteger(p); @@ -39,8 +35,7 @@ namespace Org.BouncyCastle.Asn1.CryptoPro this.a = new DerInteger(a); } - private Gost3410ParamSetParameters( - Asn1Sequence seq) + private Gost3410ParamSetParameters(Asn1Sequence seq) { if (seq.Count != 4) throw new ArgumentException("Wrong number of elements in sequence", "seq"); diff --git a/crypto/src/asn1/esf/SignerLocation.cs b/crypto/src/asn1/esf/SignerLocation.cs index 0e87812be..106a32c59 100644 --- a/crypto/src/asn1/esf/SignerLocation.cs +++ b/crypto/src/asn1/esf/SignerLocation.cs @@ -19,9 +19,9 @@ namespace Org.BouncyCastle.Asn1.Esf public class SignerLocation : Asn1Encodable { - private DirectoryString countryName; - private DirectoryString localityName; - private Asn1Sequence postalAddress; + private readonly DirectoryString countryName; + private readonly DirectoryString localityName; + private readonly Asn1Sequence postalAddress; public SignerLocation(Asn1Sequence seq) { @@ -99,13 +99,7 @@ namespace Org.BouncyCastle.Asn1.Esf if (postalAddress == null) return null; - DirectoryString[] dirStrings = new DirectoryString[postalAddress.Count]; - for (int i = 0; i != dirStrings.Length; i++) - { - dirStrings[i] = DirectoryString.GetInstance(postalAddress[i]); - } - - return dirStrings; + return postalAddress.MapElements(element => DirectoryString.GetInstance(element.ToAsn1Object())); } public Asn1Sequence PostalAddress @@ -132,7 +126,7 @@ namespace Org.BouncyCastle.Asn1.Esf */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); v.AddOptionalTagged(true, 0, countryName); v.AddOptionalTagged(true, 1, localityName); v.AddOptionalTagged(true, 2, postalAddress); diff --git a/crypto/src/asn1/isismtt/x509/Admissions.cs b/crypto/src/asn1/isismtt/x509/Admissions.cs index 42ebceb1c..1ade6093f 100644 --- a/crypto/src/asn1/isismtt/x509/Admissions.cs +++ b/crypto/src/asn1/isismtt/x509/Admissions.cs @@ -70,13 +70,13 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 switch (tagged1.TagNo) { case 0: - admissionAuthority = GeneralName.GetInstance((Asn1TaggedObject)o, true); + admissionAuthority = GeneralName.GetInstance(tagged1, true); break; case 1: - namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true); + namingAuthority = NamingAuthority.GetInstance(tagged1, true); break; default: - throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo); + throw new ArgumentException("Bad tag number: " + tagged1.TagNo); } e.MoveNext(); o = e.Current; @@ -86,10 +86,10 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 switch (tagged2.TagNo) { case 1: - namingAuthority = NamingAuthority.GetInstance((Asn1TaggedObject)o, true); + namingAuthority = NamingAuthority.GetInstance(tagged2, true); break; default: - throw new ArgumentException("Bad tag number: " + ((Asn1TaggedObject)o).TagNo); + throw new ArgumentException("Bad tag number: " + tagged2.TagNo); } e.MoveNext(); o = e.Current; diff --git a/crypto/src/asn1/ocsp/CertID.cs b/crypto/src/asn1/ocsp/CertID.cs index 523f6b87c..12a111ec9 100644 --- a/crypto/src/asn1/ocsp/CertID.cs +++ b/crypto/src/asn1/ocsp/CertID.cs @@ -1,12 +1,10 @@ using System; -using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.X509; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.Ocsp { - public class CertID + public class CertID : Asn1Encodable { private readonly AlgorithmIdentifier hashAlgorithm; @@ -14,27 +12,18 @@ namespace Org.BouncyCastle.Asn1.Ocsp private readonly Asn1OctetString issuerKeyHash; private readonly DerInteger serialNumber; - public static CertID GetInstance( - Asn1TaggedObject obj, - bool explicitly) + public static CertID GetInstance(Asn1TaggedObject obj, bool explicitly) { return GetInstance(Asn1Sequence.GetInstance(obj, explicitly)); } - public static CertID GetInstance( - object obj) + public static CertID GetInstance(object obj) { - if (obj == null || obj is CertID) - { - return (CertID)obj; - } - - if (obj is Asn1Sequence) - { - return new CertID((Asn1Sequence)obj); - } - - throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj"); + if (obj == null) + return null; + if (obj is CertID certID) + return certID; + return new CertID(Asn1Sequence.GetInstance(obj)); } public CertID( @@ -49,8 +38,7 @@ namespace Org.BouncyCastle.Asn1.Ocsp this.serialNumber = serialNumber; } - private CertID( - Asn1Sequence seq) + private CertID(Asn1Sequence seq) { if (seq.Count != 4) throw new ArgumentException("Wrong number of elements in sequence", "seq"); diff --git a/crypto/src/asn1/pkcs/CertBag.cs b/crypto/src/asn1/pkcs/CertBag.cs index b32b10ae0..81868fef6 100644 --- a/crypto/src/asn1/pkcs/CertBag.cs +++ b/crypto/src/asn1/pkcs/CertBag.cs @@ -7,8 +7,8 @@ namespace Org.BouncyCastle.Asn1.Pkcs { public static CertBag GetInstance(object obj) { - if (obj is CertBag) - return (CertBag)obj; + if (obj is CertBag certBag) + return certBag; if (obj == null) return null; return new CertBag(Asn1Sequence.GetInstance(obj)); diff --git a/crypto/src/asn1/pkcs/ContentInfo.cs b/crypto/src/asn1/pkcs/ContentInfo.cs index d19b4659c..05d9a2033 100644 --- a/crypto/src/asn1/pkcs/ContentInfo.cs +++ b/crypto/src/asn1/pkcs/ContentInfo.cs @@ -1,5 +1,3 @@ -using System; - namespace Org.BouncyCastle.Asn1.Pkcs { public class ContentInfo @@ -12,9 +10,8 @@ namespace Org.BouncyCastle.Asn1.Pkcs { if (obj == null) return null; - ContentInfo existing = obj as ContentInfo; - if (existing != null) - return existing; + if (obj is ContentInfo contentInfo) + return contentInfo; return new ContentInfo(Asn1Sequence.GetInstance(obj)); } diff --git a/crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs b/crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs index 5ca612f27..bf0e1aaeb 100644 --- a/crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs +++ b/crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs @@ -1,7 +1,6 @@ using System; using Org.BouncyCastle.Asn1.X509; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.Pkcs { @@ -28,19 +27,14 @@ namespace Org.BouncyCastle.Asn1.Pkcs this.data = new DerOctetString(encoding); } - public static EncryptedPrivateKeyInfo GetInstance( - object obj) + public static EncryptedPrivateKeyInfo GetInstance(object obj) { - if (obj is EncryptedPrivateKeyInfo) - { - return (EncryptedPrivateKeyInfo) obj; - } - - if (obj is Asn1Sequence seq) - return new EncryptedPrivateKeyInfo(seq); - - throw new ArgumentException("Unknown object in factory: " + Platform.GetTypeName(obj), "obj"); - } + if (obj == null) + return null; + if (obj is EncryptedPrivateKeyInfo encryptedPrivateKeyInfo) + return encryptedPrivateKeyInfo; + return new EncryptedPrivateKeyInfo(Asn1Sequence.GetInstance(obj)); + } public AlgorithmIdentifier EncryptionAlgorithm { diff --git a/crypto/src/asn1/pkcs/PBEParameter.cs b/crypto/src/asn1/pkcs/PBEParameter.cs index e8e7c5a82..31d9ad1f3 100644 --- a/crypto/src/asn1/pkcs/PBEParameter.cs +++ b/crypto/src/asn1/pkcs/PBEParameter.cs @@ -1,7 +1,6 @@ using System; using Org.BouncyCastle.Math; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.Pkcs { @@ -11,20 +10,14 @@ namespace Org.BouncyCastle.Asn1.Pkcs private readonly Asn1OctetString salt; private readonly DerInteger iterationCount; - public static PbeParameter GetInstance(object obj) - { - if (obj is PbeParameter || obj == null) - { - return (PbeParameter) obj; - } - - if (obj is Asn1Sequence) - { - return new PbeParameter((Asn1Sequence) obj); - } - - throw new ArgumentException("Unknown object in factory: " + Platform.GetTypeName(obj), "obj"); - } + public static PbeParameter GetInstance(object obj) + { + if (obj == null) + return null; + if (obj is PbeParameter pbeParameter) + return pbeParameter; + return new PbeParameter(Asn1Sequence.GetInstance(obj)); + } private PbeParameter(Asn1Sequence seq) { diff --git a/crypto/src/asn1/pkcs/SignerInfo.cs b/crypto/src/asn1/pkcs/SignerInfo.cs index 7abd8e5c6..777251e84 100644 --- a/crypto/src/asn1/pkcs/SignerInfo.cs +++ b/crypto/src/asn1/pkcs/SignerInfo.cs @@ -1,7 +1,4 @@ -using System; - using Org.BouncyCastle.Asn1.X509; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.Pkcs { @@ -19,21 +16,14 @@ namespace Org.BouncyCastle.Asn1.Pkcs private Asn1OctetString encryptedDigest; private Asn1Set unauthenticatedAttributes; - public static SignerInfo GetInstance( - object obj) + public static SignerInfo GetInstance(object obj) { - if (obj is SignerInfo) - { - return (SignerInfo) obj; - } - - if (obj is Asn1Sequence) - { - return new SignerInfo((Asn1Sequence) obj); - } - - throw new ArgumentException("Unknown object in factory: " + Platform.GetTypeName(obj), "obj"); - } + if (obj == null) + return null; + if (obj is SignerInfo signerInfo) + return signerInfo; + return new SignerInfo(Asn1Sequence.GetInstance(obj)); + } public SignerInfo( DerInteger version, diff --git a/crypto/src/asn1/x509/AuthorityInformationAccess.cs b/crypto/src/asn1/x509/AuthorityInformationAccess.cs index 382513674..c601322c5 100644 --- a/crypto/src/asn1/x509/AuthorityInformationAccess.cs +++ b/crypto/src/asn1/x509/AuthorityInformationAccess.cs @@ -1,8 +1,6 @@ using System; using System.Text; -using Org.BouncyCastle.Utilities; - namespace Org.BouncyCastle.Asn1.X509 { /** @@ -31,10 +29,10 @@ namespace Org.BouncyCastle.Asn1.X509 public static AuthorityInformationAccess GetInstance(object obj) { - if (obj is AuthorityInformationAccess) - return (AuthorityInformationAccess)obj; if (obj == null) return null; + if (obj is AuthorityInformationAccess authorityInformationAccess) + return authorityInformationAccess; return new AuthorityInformationAccess(Asn1Sequence.GetInstance(obj)); } diff --git a/crypto/src/asn1/x509/ExtendedKeyUsage.cs b/crypto/src/asn1/x509/ExtendedKeyUsage.cs index f812c308d..08962ab72 100644 --- a/crypto/src/asn1/x509/ExtendedKeyUsage.cs +++ b/crypto/src/asn1/x509/ExtendedKeyUsage.cs @@ -67,10 +67,8 @@ namespace Org.BouncyCastle.Asn1.X509 { Asn1EncodableVector v = new Asn1EncodableVector(); - foreach (object usage in usages) + foreach (var oid in usages) { - DerObjectIdentifier oid = DerObjectIdentifier.GetInstance(usage); - v.Add(oid); m_usageTable.Add(oid); } diff --git a/crypto/src/asn1/x509/NameConstraints.cs b/crypto/src/asn1/x509/NameConstraints.cs index 9fe4fdd01..590b14aa0 100644 --- a/crypto/src/asn1/x509/NameConstraints.cs +++ b/crypto/src/asn1/x509/NameConstraints.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Org.BouncyCastle.Utilities; @@ -68,12 +69,7 @@ namespace Org.BouncyCastle.Asn1.X509 private DerSequence CreateSequence(IList<GeneralSubtree> subtrees) { - GeneralSubtree[] gsts = new GeneralSubtree[subtrees.Count]; - for (int i = 0; i < subtrees.Count; ++i) - { - gsts[i] = subtrees[i]; - } - return new DerSequence(gsts); + return new DerSequence(subtrees.ToArray()); } public Asn1Sequence PermittedSubtrees @@ -92,7 +88,7 @@ namespace Org.BouncyCastle.Asn1.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); v.AddOptionalTagged(false, 0, permitted); v.AddOptionalTagged(false, 1, excluded); return new DerSequence(v); diff --git a/crypto/src/asn1/x509/SubjectDirectoryAttributes.cs b/crypto/src/asn1/x509/SubjectDirectoryAttributes.cs index 6ebd35e21..c8f24ecd5 100644 --- a/crypto/src/asn1/x509/SubjectDirectoryAttributes.cs +++ b/crypto/src/asn1/x509/SubjectDirectoryAttributes.cs @@ -1,7 +1,5 @@ -using System; using System.Collections.Generic; -using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities.Collections; namespace Org.BouncyCastle.Asn1.X509 @@ -28,23 +26,16 @@ namespace Org.BouncyCastle.Asn1.X509 public class SubjectDirectoryAttributes : Asn1Encodable { - private readonly IList<AttributeX509> m_attributes; + private readonly List<AttributeX509> m_attributes; - public static SubjectDirectoryAttributes GetInstance( - object obj) - { - if (obj == null || obj is SubjectDirectoryAttributes) - { - return (SubjectDirectoryAttributes) obj; - } - - if (obj is Asn1Sequence) - { - return new SubjectDirectoryAttributes((Asn1Sequence) obj); - } - - throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj"); - } + public static SubjectDirectoryAttributes GetInstance(object obj) + { + if (obj == null) + return null; + if (obj is SubjectDirectoryAttributes subjectDirectoryAttributes) + return subjectDirectoryAttributes; + return new SubjectDirectoryAttributes(Asn1Sequence.GetInstance(obj)); + } /** * Constructor from Asn1Sequence. @@ -114,12 +105,7 @@ namespace Org.BouncyCastle.Asn1.X509 */ public override Asn1Object ToAsn1Object() { - AttributeX509[] v = new AttributeX509[m_attributes.Count]; - for (int i = 0; i < m_attributes.Count; ++i) - { - v[i] = m_attributes[i]; - } - return new DerSequence(v); + return new DerSequence(m_attributes.ToArray()); } /** diff --git a/crypto/src/asn1/x509/SubjectPublicKeyInfo.cs b/crypto/src/asn1/x509/SubjectPublicKeyInfo.cs index 52f977e91..4875152eb 100644 --- a/crypto/src/asn1/x509/SubjectPublicKeyInfo.cs +++ b/crypto/src/asn1/x509/SubjectPublicKeyInfo.cs @@ -1,5 +1,4 @@ using System; -using System.IO; namespace Org.BouncyCastle.Asn1.X509 { diff --git a/crypto/src/asn1/x509/V2TBSCertListGenerator.cs b/crypto/src/asn1/x509/V2TBSCertListGenerator.cs index aa1a0b95d..bf016c22d 100644 --- a/crypto/src/asn1/x509/V2TBSCertListGenerator.cs +++ b/crypto/src/asn1/x509/V2TBSCertListGenerator.cs @@ -2,8 +2,6 @@ using System; using System.Collections.Generic; using System.IO; -using Org.BouncyCastle.Utilities; - namespace Org.BouncyCastle.Asn1.X509 { /** diff --git a/crypto/src/asn1/x509/X509ExtensionsGenerator.cs b/crypto/src/asn1/x509/X509ExtensionsGenerator.cs index 53d18ecff..7ea6084af 100644 --- a/crypto/src/asn1/x509/X509ExtensionsGenerator.cs +++ b/crypto/src/asn1/x509/X509ExtensionsGenerator.cs @@ -90,8 +90,6 @@ namespace Org.BouncyCastle.Asn1.X509 } } - - /// <summary>Return true if there are no extension present in this generator.</summary> /// <returns>True if empty, false otherwise</returns> public bool IsEmpty |