diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-02-17 17:58:20 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-02-17 17:58:20 +0700 |
commit | e3d12a2c33a7a9d0f371e1d5ff07f7ab7a3eb7ae (patch) | |
tree | a0a855afdfbfe6a4cc8a5b026f9b815ee7147d4b /crypto/src/asn1 | |
parent | Refactoring in Cms (diff) | |
download | BouncyCastle.NET-ed25519-e3d12a2c33a7a9d0f371e1d5ff07f7ab7a3eb7ae.tar.xz |
Refactoring around Asn1EncodableVector
Diffstat (limited to 'crypto/src/asn1')
44 files changed, 55 insertions, 79 deletions
diff --git a/crypto/src/asn1/Asn1EncodableVector.cs b/crypto/src/asn1/Asn1EncodableVector.cs index bf8d324ad..2bf1cf8e2 100644 --- a/crypto/src/asn1/Asn1EncodableVector.cs +++ b/crypto/src/asn1/Asn1EncodableVector.cs @@ -35,7 +35,7 @@ namespace Org.BouncyCastle.Asn1 public Asn1EncodableVector(int initialCapacity) { if (initialCapacity < 0) - throw new ArgumentException("must not be negative", "initialCapacity"); + throw new ArgumentException("must not be negative", nameof(initialCapacity)); this.elements = (initialCapacity == 0) ? EmptyElements : new Asn1Encodable[initialCapacity]; this.elementCount = 0; @@ -64,7 +64,7 @@ namespace Org.BouncyCastle.Asn1 public void Add(Asn1Encodable element) { if (null == element) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); int capacity = elements.Length; int minCapacity = elementCount + 1; @@ -144,7 +144,7 @@ namespace Org.BouncyCastle.Asn1 public void AddAll(Asn1EncodableVector other) { if (null == other) - throw new ArgumentNullException("other"); + throw new ArgumentNullException(nameof(other)); int otherElementCount = other.Count; if (otherElementCount < 1) @@ -182,10 +182,7 @@ namespace Org.BouncyCastle.Asn1 } } - public int Count - { - get { return elementCount; } - } + public int Count => elementCount; System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { diff --git a/crypto/src/asn1/cmp/Challenge.cs b/crypto/src/asn1/cmp/Challenge.cs index 21958da67..b86c3d800 100644 --- a/crypto/src/asn1/cmp/Challenge.cs +++ b/crypto/src/asn1/cmp/Challenge.cs @@ -111,7 +111,7 @@ namespace Org.BouncyCastle.Asn1.Cmp */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); v.AddOptional(m_owf); v.Add(m_witness, m_challenge); return new DerSequence(v); diff --git a/crypto/src/asn1/cmp/PKIHeaderBuilder.cs b/crypto/src/asn1/cmp/PKIHeaderBuilder.cs index ab8db958a..6c7a2db63 100644 --- a/crypto/src/asn1/cmp/PKIHeaderBuilder.cs +++ b/crypto/src/asn1/cmp/PKIHeaderBuilder.cs @@ -126,26 +126,14 @@ namespace Org.BouncyCastle.Asn1.Cmp return this; } - private static Asn1Sequence MakeGeneralInfoSeq( - InfoTypeAndValue generalInfo) + private static Asn1Sequence MakeGeneralInfoSeq(InfoTypeAndValue generalInfo) { return new DerSequence(generalInfo); } - - private static Asn1Sequence MakeGeneralInfoSeq( - InfoTypeAndValue[] generalInfos) - { - Asn1Sequence genInfoSeq = null; - if (generalInfos != null) - { - Asn1EncodableVector v = new Asn1EncodableVector(); - for (int i = 0; i < generalInfos.Length; ++i) - { - v.Add(generalInfos[i]); - } - genInfoSeq = new DerSequence(v); - } - return genInfoSeq; + + private static Asn1Sequence MakeGeneralInfoSeq(InfoTypeAndValue[] generalInfos) + { + return generalInfos == null ? null : new DerSequence(generalInfos); } /** diff --git a/crypto/src/asn1/cmp/RevRepContentBuilder.cs b/crypto/src/asn1/cmp/RevRepContentBuilder.cs index f23bed8b5..4ff85483e 100644 --- a/crypto/src/asn1/cmp/RevRepContentBuilder.cs +++ b/crypto/src/asn1/cmp/RevRepContentBuilder.cs @@ -35,7 +35,7 @@ namespace Org.BouncyCastle.Asn1.Cmp public virtual RevRepContent Build() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); v.Add(new DerSequence(m_status)); diff --git a/crypto/src/asn1/cms/OriginatorInfo.cs b/crypto/src/asn1/cms/OriginatorInfo.cs index 23acc2d9f..c11e01dfe 100644 --- a/crypto/src/asn1/cms/OriginatorInfo.cs +++ b/crypto/src/asn1/cms/OriginatorInfo.cs @@ -103,7 +103,7 @@ namespace Org.BouncyCastle.Asn1.Cms */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); v.AddOptionalTagged(false, 0, certs); v.AddOptionalTagged(false, 1, crls); return new DerSequence(v); diff --git a/crypto/src/asn1/cms/SCVPReqRes.cs b/crypto/src/asn1/cms/SCVPReqRes.cs index a6ebf7302..6544c852b 100644 --- a/crypto/src/asn1/cms/SCVPReqRes.cs +++ b/crypto/src/asn1/cms/SCVPReqRes.cs @@ -62,7 +62,7 @@ namespace Org.BouncyCastle.Asn1.Cms */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); v.AddOptionalTagged(true, 0, request); v.Add(response); return new DerSequence(v); diff --git a/crypto/src/asn1/crmf/CertTemplateBuilder.cs b/crypto/src/asn1/crmf/CertTemplateBuilder.cs index d26e6399c..a69e3beeb 100644 --- a/crypto/src/asn1/crmf/CertTemplateBuilder.cs +++ b/crypto/src/asn1/crmf/CertTemplateBuilder.cs @@ -98,7 +98,7 @@ namespace Org.BouncyCastle.Asn1.Crmf */ public virtual CertTemplate Build() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(10); v.AddOptionalTagged(false, 0, version); v.AddOptionalTagged(false, 1, serialNumber); v.AddOptionalTagged(false, 2, signingAlg); diff --git a/crypto/src/asn1/crmf/EncryptedValue.cs b/crypto/src/asn1/crmf/EncryptedValue.cs index 950298504..05a96fd37 100644 --- a/crypto/src/asn1/crmf/EncryptedValue.cs +++ b/crypto/src/asn1/crmf/EncryptedValue.cs @@ -104,7 +104,7 @@ namespace Org.BouncyCastle.Asn1.Crmf */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(6); v.AddOptionalTagged(false, 0, m_intendedAlg); v.AddOptionalTagged(false, 1, m_symmAlg); v.AddOptionalTagged(false, 2, m_encSymmKey); diff --git a/crypto/src/asn1/crmf/OptionalValidity.cs b/crypto/src/asn1/crmf/OptionalValidity.cs index d608ea5d1..722705232 100644 --- a/crypto/src/asn1/crmf/OptionalValidity.cs +++ b/crypto/src/asn1/crmf/OptionalValidity.cs @@ -59,7 +59,7 @@ namespace Org.BouncyCastle.Asn1.Crmf */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); v.AddOptionalTagged(true, 0, notBefore); v.AddOptionalTagged(true, 1, notAfter); return new DerSequence(v); diff --git a/crypto/src/asn1/crmf/PopoSigningKey.cs b/crypto/src/asn1/crmf/PopoSigningKey.cs index 11e735415..93e14e30d 100644 --- a/crypto/src/asn1/crmf/PopoSigningKey.cs +++ b/crypto/src/asn1/crmf/PopoSigningKey.cs @@ -100,7 +100,7 @@ namespace Org.BouncyCastle.Asn1.Crmf */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); v.AddOptionalTagged(false, 0, poposkInput); v.Add(algorithmIdentifier); v.Add(signature); diff --git a/crypto/src/asn1/crmf/PopoSigningKeyInput.cs b/crypto/src/asn1/crmf/PopoSigningKeyInput.cs index e43fa138e..30d017475 100644 --- a/crypto/src/asn1/crmf/PopoSigningKeyInput.cs +++ b/crypto/src/asn1/crmf/PopoSigningKeyInput.cs @@ -97,7 +97,7 @@ namespace Org.BouncyCastle.Asn1.Crmf */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); if (sender != null) { diff --git a/crypto/src/asn1/esf/CrlOcspRef.cs b/crypto/src/asn1/esf/CrlOcspRef.cs index 6153e0c53..6f55ff057 100644 --- a/crypto/src/asn1/esf/CrlOcspRef.cs +++ b/crypto/src/asn1/esf/CrlOcspRef.cs @@ -90,7 +90,7 @@ namespace Org.BouncyCastle.Asn1.Esf public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); if (crlids != null) { diff --git a/crypto/src/asn1/esf/RevocationValues.cs b/crypto/src/asn1/esf/RevocationValues.cs index 61bfd0be1..f3b36f1d1 100644 --- a/crypto/src/asn1/esf/RevocationValues.cs +++ b/crypto/src/asn1/esf/RevocationValues.cs @@ -119,7 +119,7 @@ namespace Org.BouncyCastle.Asn1.Esf public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); v.AddOptionalTagged(true, 0, m_crlVals); v.AddOptionalTagged(true, 1, m_ocspVals); diff --git a/crypto/src/asn1/esf/SignerAttribute.cs b/crypto/src/asn1/esf/SignerAttribute.cs index 39bd910b2..f90968cf8 100644 --- a/crypto/src/asn1/esf/SignerAttribute.cs +++ b/crypto/src/asn1/esf/SignerAttribute.cs @@ -80,18 +80,9 @@ namespace Org.BouncyCastle.Asn1.Esf */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); - - if (claimedAttributes != null) - { - v.Add(new DerTaggedObject(0, claimedAttributes)); - } - else - { - v.Add(new DerTaggedObject(1, certifiedAttributes)); - } - - return new DerSequence(v); + return claimedAttributes != null + ? new DerSequence(new DerTaggedObject(0, claimedAttributes)) + : new DerSequence(new DerTaggedObject(1, certifiedAttributes)); } } } diff --git a/crypto/src/asn1/ess/ContentHints.cs b/crypto/src/asn1/ess/ContentHints.cs index 81ba0a1fe..f61bf0df8 100644 --- a/crypto/src/asn1/ess/ContentHints.cs +++ b/crypto/src/asn1/ess/ContentHints.cs @@ -79,7 +79,7 @@ namespace Org.BouncyCastle.Asn1.Ess */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); v.AddOptional(contentDescription); v.Add(contentType); return new DerSequence(v); diff --git a/crypto/src/asn1/ess/ESSCertIDv2.cs b/crypto/src/asn1/ess/ESSCertIDv2.cs index 1711a769c..b3d49ceb5 100644 --- a/crypto/src/asn1/ess/ESSCertIDv2.cs +++ b/crypto/src/asn1/ess/ESSCertIDv2.cs @@ -125,7 +125,7 @@ namespace Org.BouncyCastle.Asn1.Ess */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); if (!hashAlgorithm.Equals(DefaultAlgID)) { diff --git a/crypto/src/asn1/isismtt/x509/AdmissionSyntax.cs b/crypto/src/asn1/isismtt/x509/AdmissionSyntax.cs index a45075ee4..eac5d9a1a 100644 --- a/crypto/src/asn1/isismtt/x509/AdmissionSyntax.cs +++ b/crypto/src/asn1/isismtt/x509/AdmissionSyntax.cs @@ -243,7 +243,7 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); v.AddOptional(admissionAuthority); v.Add(contentsOfAdmissions); return new DerSequence(v); diff --git a/crypto/src/asn1/isismtt/x509/Admissions.cs b/crypto/src/asn1/isismtt/x509/Admissions.cs index 1ade6093f..57c5a6183 100644 --- a/crypto/src/asn1/isismtt/x509/Admissions.cs +++ b/crypto/src/asn1/isismtt/x509/Admissions.cs @@ -160,7 +160,7 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); v.AddOptionalTagged(true, 0, admissionAuthority); v.AddOptionalTagged(true, 1, namingAuthority); v.Add(professionInfos); diff --git a/crypto/src/asn1/isismtt/x509/NamingAuthority.cs b/crypto/src/asn1/isismtt/x509/NamingAuthority.cs index 78ef25654..3c3f0a5f5 100644 --- a/crypto/src/asn1/isismtt/x509/NamingAuthority.cs +++ b/crypto/src/asn1/isismtt/x509/NamingAuthority.cs @@ -187,7 +187,7 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); v.AddOptional(namingAuthorityID); if (namingAuthorityUrl != null) diff --git a/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs b/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs index 23be2d388..2fb7323c6 100644 --- a/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs +++ b/crypto/src/asn1/isismtt/x509/ProcurationSyntax.cs @@ -202,7 +202,7 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); if (country != null) { diff --git a/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs b/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs index daa76730d..32ad31d9a 100644 --- a/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs +++ b/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs @@ -296,7 +296,7 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(5); v.AddOptionalTagged(true, 0, namingAuthority); v.Add(professionItems); v.AddOptional(professionOids); diff --git a/crypto/src/asn1/misc/IDEACBCPar.cs b/crypto/src/asn1/misc/IDEACBCPar.cs index 9ae9f6faf..96bfb89b0 100644 --- a/crypto/src/asn1/misc/IDEACBCPar.cs +++ b/crypto/src/asn1/misc/IDEACBCPar.cs @@ -55,9 +55,9 @@ namespace Org.BouncyCastle.Asn1.Misc */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); - v.AddOptional(iv); - return new DerSequence(v); + return iv != null + ? new DerSequence(iv) + : DerSequence.Empty; } } } diff --git a/crypto/src/asn1/nist/KMACwithSHAKE128_params.cs b/crypto/src/asn1/nist/KMACwithSHAKE128_params.cs index a1fd8f403..df2bf0173 100644 --- a/crypto/src/asn1/nist/KMACwithSHAKE128_params.cs +++ b/crypto/src/asn1/nist/KMACwithSHAKE128_params.cs @@ -86,7 +86,7 @@ public class KMacWithShake128Params : Asn1Encodable public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); if (outputLength != DEF_LENGTH) { v.Add(new DerInteger(outputLength)); diff --git a/crypto/src/asn1/nist/KMACwithSHAKE256_params.cs b/crypto/src/asn1/nist/KMACwithSHAKE256_params.cs index f0560e9da..dfdfb2c36 100644 --- a/crypto/src/asn1/nist/KMACwithSHAKE256_params.cs +++ b/crypto/src/asn1/nist/KMACwithSHAKE256_params.cs @@ -85,7 +85,7 @@ public class KMacWithShake256Params : Asn1Encodable public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); if (outputLength != DEF_LENGTH) { v.Add(new DerInteger(outputLength)); diff --git a/crypto/src/asn1/ocsp/CrlID.cs b/crypto/src/asn1/ocsp/CrlID.cs index 8736b83ab..7a4172c57 100644 --- a/crypto/src/asn1/ocsp/CrlID.cs +++ b/crypto/src/asn1/ocsp/CrlID.cs @@ -73,7 +73,7 @@ namespace Org.BouncyCastle.Asn1.Ocsp */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); v.AddOptionalTagged(true, 0, crlUrl); v.AddOptionalTagged(true, 1, crlNum); v.AddOptionalTagged(true, 2, crlTime); diff --git a/crypto/src/asn1/ocsp/ResponseData.cs b/crypto/src/asn1/ocsp/ResponseData.cs index dfb234bc1..b18e1d623 100644 --- a/crypto/src/asn1/ocsp/ResponseData.cs +++ b/crypto/src/asn1/ocsp/ResponseData.cs @@ -138,7 +138,7 @@ namespace Org.BouncyCastle.Asn1.Ocsp */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); if (versionPresent || !version.Equals(V1)) { diff --git a/crypto/src/asn1/ocsp/TBSRequest.cs b/crypto/src/asn1/ocsp/TBSRequest.cs index 0166c5342..fd5f153d7 100644 --- a/crypto/src/asn1/ocsp/TBSRequest.cs +++ b/crypto/src/asn1/ocsp/TBSRequest.cs @@ -122,7 +122,7 @@ namespace Org.BouncyCastle.Asn1.Ocsp */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(4); // // if default don't include - unless explicitly provided. Not strictly correct diff --git a/crypto/src/asn1/pkcs/RC2CBCParameter.cs b/crypto/src/asn1/pkcs/RC2CBCParameter.cs index 48591f2e9..c1f09a088 100644 --- a/crypto/src/asn1/pkcs/RC2CBCParameter.cs +++ b/crypto/src/asn1/pkcs/RC2CBCParameter.cs @@ -65,7 +65,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); v.AddOptional(version); v.Add(iv); return new DerSequence(v); diff --git a/crypto/src/asn1/pkcs/RSAESOAEPparams.cs b/crypto/src/asn1/pkcs/RSAESOAEPparams.cs index 2419e33c7..988b230c8 100644 --- a/crypto/src/asn1/pkcs/RSAESOAEPparams.cs +++ b/crypto/src/asn1/pkcs/RSAESOAEPparams.cs @@ -128,7 +128,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); if (!hashAlgorithm.Equals(DefaultHashAlgorithm)) { diff --git a/crypto/src/asn1/pkcs/RSASSAPSSparams.cs b/crypto/src/asn1/pkcs/RSASSAPSSparams.cs index 85849c362..e5800993f 100644 --- a/crypto/src/asn1/pkcs/RSASSAPSSparams.cs +++ b/crypto/src/asn1/pkcs/RSASSAPSSparams.cs @@ -138,7 +138,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(4); if (!hashAlgorithm.Equals(DefaultHashAlgorithm)) { diff --git a/crypto/src/asn1/tsp/Accuracy.cs b/crypto/src/asn1/tsp/Accuracy.cs index 0cbc731ac..0d64e2dd4 100644 --- a/crypto/src/asn1/tsp/Accuracy.cs +++ b/crypto/src/asn1/tsp/Accuracy.cs @@ -110,7 +110,7 @@ namespace Org.BouncyCastle.Asn1.Tsp */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); v.AddOptional(seconds); v.AddOptionalTagged(false, 0, millis); v.AddOptionalTagged(false, 1, micros); diff --git a/crypto/src/asn1/x509/AuthorityKeyIdentifier.cs b/crypto/src/asn1/x509/AuthorityKeyIdentifier.cs index 64cfce214..810fda82e 100644 --- a/crypto/src/asn1/x509/AuthorityKeyIdentifier.cs +++ b/crypto/src/asn1/x509/AuthorityKeyIdentifier.cs @@ -166,7 +166,7 @@ namespace Org.BouncyCastle.Asn1.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); v.AddOptionalTagged(false, 0, keyidentifier); v.AddOptionalTagged(false, 1, certissuer); v.AddOptionalTagged(false, 2, certserno); diff --git a/crypto/src/asn1/x509/CertificatePair.cs b/crypto/src/asn1/x509/CertificatePair.cs index 69861e1dc..055144464 100644 --- a/crypto/src/asn1/x509/CertificatePair.cs +++ b/crypto/src/asn1/x509/CertificatePair.cs @@ -128,7 +128,7 @@ namespace Org.BouncyCastle.Asn1.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); v.AddOptionalTagged(true, 0, forward); v.AddOptionalTagged(true, 1, reverse); return new DerSequence(v); diff --git a/crypto/src/asn1/x509/IetfAttrSyntax.cs b/crypto/src/asn1/x509/IetfAttrSyntax.cs index 61fe78561..024c8dd68 100644 --- a/crypto/src/asn1/x509/IetfAttrSyntax.cs +++ b/crypto/src/asn1/x509/IetfAttrSyntax.cs @@ -143,7 +143,7 @@ namespace Org.BouncyCastle.Asn1.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); v.AddOptionalTagged(true, 0, policyAuthority); v.Add(new DerSequence(values)); return new DerSequence(v); diff --git a/crypto/src/asn1/x509/IssuingDistributionPoint.cs b/crypto/src/asn1/x509/IssuingDistributionPoint.cs index 0287fd8f5..8ae4cafa0 100644 --- a/crypto/src/asn1/x509/IssuingDistributionPoint.cs +++ b/crypto/src/asn1/x509/IssuingDistributionPoint.cs @@ -70,7 +70,7 @@ namespace Org.BouncyCastle.Asn1.X509 this._onlyContainsUserCerts = onlyContainsUserCerts; this._onlySomeReasons = onlySomeReasons; - Asn1EncodableVector vec = new Asn1EncodableVector(); + Asn1EncodableVector vec = new Asn1EncodableVector(6); if (distributionPoint != null) { // CHOICE item so explicitly tagged vec.Add(new DerTaggedObject(true, 0, distributionPoint)); diff --git a/crypto/src/asn1/x509/NoticeReference.cs b/crypto/src/asn1/x509/NoticeReference.cs index 98a64ec55..2fb275d8f 100644 --- a/crypto/src/asn1/x509/NoticeReference.cs +++ b/crypto/src/asn1/x509/NoticeReference.cs @@ -28,7 +28,7 @@ namespace Org.BouncyCastle.Asn1.X509 private static Asn1EncodableVector ConvertVector(IList<object> numbers) { - Asn1EncodableVector av = new Asn1EncodableVector(); + Asn1EncodableVector av = new Asn1EncodableVector(numbers.Count); foreach (object o in numbers) { diff --git a/crypto/src/asn1/x509/PolicyMappings.cs b/crypto/src/asn1/x509/PolicyMappings.cs index a077f2059..01a6ae88f 100644 --- a/crypto/src/asn1/x509/PolicyMappings.cs +++ b/crypto/src/asn1/x509/PolicyMappings.cs @@ -38,7 +38,7 @@ namespace Org.BouncyCastle.Asn1.X509 */ public PolicyMappings(IDictionary<string, string> mappings) { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(mappings.Count); foreach (var entry in mappings) { diff --git a/crypto/src/asn1/x509/PrivateKeyUsagePeriod.cs b/crypto/src/asn1/x509/PrivateKeyUsagePeriod.cs index a87c2ee9e..2ca1557bc 100644 --- a/crypto/src/asn1/x509/PrivateKeyUsagePeriod.cs +++ b/crypto/src/asn1/x509/PrivateKeyUsagePeriod.cs @@ -66,7 +66,7 @@ namespace Org.BouncyCastle.Asn1.X509 public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); v.AddOptionalTagged(false, 0, _notBefore); v.AddOptionalTagged(false, 1, _notAfter); return new DerSequence(v); diff --git a/crypto/src/asn1/x509/RoleSyntax.cs b/crypto/src/asn1/x509/RoleSyntax.cs index b5b217b6b..163b3d07e 100644 --- a/crypto/src/asn1/x509/RoleSyntax.cs +++ b/crypto/src/asn1/x509/RoleSyntax.cs @@ -192,7 +192,7 @@ namespace Org.BouncyCastle.Asn1.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); v.AddOptionalTagged(false, 0, roleAuthority); v.Add(new DerTaggedObject(true, 1, roleName)); return new DerSequence(v); diff --git a/crypto/src/asn1/x509/TBSCertificateStructure.cs b/crypto/src/asn1/x509/TBSCertificateStructure.cs index bd08d8bb8..5e3bf2601 100644 --- a/crypto/src/asn1/x509/TBSCertificateStructure.cs +++ b/crypto/src/asn1/x509/TBSCertificateStructure.cs @@ -216,7 +216,7 @@ namespace Org.BouncyCastle.Asn1.X509 if (null == property || Platform.EqualsIgnoreCase("true", property)) return seq; - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(8); // DEFAULT Zero if (!version.HasValue(0)) diff --git a/crypto/src/asn1/x509/UserNotice.cs b/crypto/src/asn1/x509/UserNotice.cs index 801ca0ded..c9a5e5309 100644 --- a/crypto/src/asn1/x509/UserNotice.cs +++ b/crypto/src/asn1/x509/UserNotice.cs @@ -101,7 +101,7 @@ namespace Org.BouncyCastle.Asn1.X509 public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); v.AddOptional(noticeRef, explicitText); return new DerSequence(v); } diff --git a/crypto/src/asn1/x509/V2Form.cs b/crypto/src/asn1/x509/V2Form.cs index 53475ffbe..ca1b75095 100644 --- a/crypto/src/asn1/x509/V2Form.cs +++ b/crypto/src/asn1/x509/V2Form.cs @@ -114,7 +114,7 @@ namespace Org.BouncyCastle.Asn1.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); v.AddOptional(issuerName); v.AddOptionalTagged(false, 0, baseCertificateID); v.AddOptionalTagged(false, 1, objectDigestInfo); diff --git a/crypto/src/asn1/x509/qualified/SemanticsInformation.cs b/crypto/src/asn1/x509/qualified/SemanticsInformation.cs index 23818e916..1106e10b1 100644 --- a/crypto/src/asn1/x509/qualified/SemanticsInformation.cs +++ b/crypto/src/asn1/x509/qualified/SemanticsInformation.cs @@ -104,7 +104,7 @@ namespace Org.BouncyCastle.Asn1.X509.Qualified public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(2); v.AddOptional(semanticsIdentifier); if (null != nameRegistrationAuthorities) diff --git a/crypto/src/asn1/x9/X9Curve.cs b/crypto/src/asn1/x9/X9Curve.cs index 88198335f..568bcb316 100644 --- a/crypto/src/asn1/x9/X9Curve.cs +++ b/crypto/src/asn1/x9/X9Curve.cs @@ -127,7 +127,7 @@ namespace Org.BouncyCastle.Asn1.X9 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(); + Asn1EncodableVector v = new Asn1EncodableVector(3); if (fieldIdentifier.Equals(X9ObjectIdentifiers.PrimeField) || fieldIdentifier.Equals(X9ObjectIdentifiers.CharacteristicTwoField)) |