diff --git a/crypto/src/cms/CMSAuthenticatedDataGenerator.cs b/crypto/src/cms/CMSAuthenticatedDataGenerator.cs
index 95e710c9b..9f6815161 100644
--- a/crypto/src/cms/CMSAuthenticatedDataGenerator.cs
+++ b/crypto/src/cms/CMSAuthenticatedDataGenerator.cs
@@ -94,7 +94,7 @@ namespace Org.BouncyCastle.Cms
throw new CmsException("exception decoding algorithm parameters.", e);
}
- var recipientInfos = new Asn1EncodableVector();
+ var recipientInfos = new Asn1EncodableVector(recipientInfoGenerators.Count);
foreach (RecipientInfoGenerator rig in recipientInfoGenerators)
{
@@ -111,13 +111,13 @@ namespace Org.BouncyCastle.Cms
throw new CmsException("error making encrypted content.", e);
}
}
-
+
var eci = new ContentInfo(CmsObjectIdentifiers.Data, encContent);
var contentInfo = new ContentInfo(
CmsObjectIdentifiers.AuthenticatedData,
new AuthenticatedData(null, new DerSet(recipientInfos), macAlgId, null, eci, null, macResult, null));
-
+
return new CmsAuthenticatedData(contentInfo);
}
diff --git a/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs b/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs
index 054a9c45e..d3f65af7a 100644
--- a/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs
@@ -93,7 +93,7 @@ namespace Org.BouncyCastle.Cms
AlgorithmIdentifier macAlgId = GetAlgorithmIdentifier(
macOid, encKey, asn1Params, out cipherParameters);
- Asn1EncodableVector recipientInfos = new Asn1EncodableVector();
+ Asn1EncodableVector recipientInfos = new Asn1EncodableVector(recipientInfoGenerators.Count);
foreach (RecipientInfoGenerator rig in recipientInfoGenerators)
{
diff --git a/crypto/src/cms/CMSEnvelopedDataGenerator.cs b/crypto/src/cms/CMSEnvelopedDataGenerator.cs
index d2cd18885..62fff7412 100644
--- a/crypto/src/cms/CMSEnvelopedDataGenerator.cs
+++ b/crypto/src/cms/CMSEnvelopedDataGenerator.cs
@@ -88,7 +88,7 @@ namespace Org.BouncyCastle.Cms
}
- Asn1EncodableVector recipientInfos = new Asn1EncodableVector();
+ Asn1EncodableVector recipientInfos = new Asn1EncodableVector(recipientInfoGenerators.Count);
foreach (RecipientInfoGenerator rig in recipientInfoGenerators)
{
@@ -180,7 +180,7 @@ namespace Org.BouncyCastle.Cms
}
- Asn1EncodableVector recipientInfos = new Asn1EncodableVector();
+ Asn1EncodableVector recipientInfos = new Asn1EncodableVector(recipientInfoGenerators.Count);
foreach (RecipientInfoGenerator rig in recipientInfoGenerators)
{
diff --git a/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs b/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs
index 64d501a41..48fe2eccc 100644
--- a/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs
@@ -97,7 +97,7 @@ namespace Org.BouncyCastle.Cms
AlgorithmIdentifier encAlgID = GetAlgorithmIdentifier(
encryptionOid, encKey, asn1Params, out cipherParameters);
- Asn1EncodableVector recipientInfos = new Asn1EncodableVector();
+ Asn1EncodableVector recipientInfos = new Asn1EncodableVector(recipientInfoGenerators.Count);
foreach (RecipientInfoGenerator rig in recipientInfoGenerators)
{
diff --git a/crypto/src/cms/CMSSignedData.cs b/crypto/src/cms/CMSSignedData.cs
index 10278784e..5a73df4f1 100644
--- a/crypto/src/cms/CMSSignedData.cs
+++ b/crypto/src/cms/CMSSignedData.cs
@@ -276,10 +276,10 @@ namespace Org.BouncyCastle.Cms
//
// replace the signers in the SignedData object
//
- Asn1EncodableVector digestAlgs = new Asn1EncodableVector();
- Asn1EncodableVector vec = new Asn1EncodableVector();
-
- foreach (SignerInformation signer in signerInformationStore.GetSigners())
+ var storeSigners = signerInformationStore.GetSigners();
+ Asn1EncodableVector digestAlgs = new Asn1EncodableVector(storeSigners.Count);
+ Asn1EncodableVector vec = new Asn1EncodableVector(storeSigners.Count);
+ foreach (SignerInformation signer in storeSigners)
{
digestAlgs.Add(Helper.FixAlgID(signer.DigestAlgorithmID));
vec.Add(signer.ToSignerInfo());
@@ -292,9 +292,9 @@ namespace Org.BouncyCastle.Cms
//
// signers are the last item in the sequence.
//
- vec = new Asn1EncodableVector(
- sD[0], // version
- digests);
+ vec = new Asn1EncodableVector(sD.Count);
+ vec.Add(sD[0]); // version
+ vec.Add(digests);
for (int i = 2; i != sD.Count - 1; i++)
{
diff --git a/crypto/src/cms/CMSSignedDataStreamGenerator.cs b/crypto/src/cms/CMSSignedDataStreamGenerator.cs
index 48abfbfa2..4883fc3f9 100644
--- a/crypto/src/cms/CMSSignedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSSignedDataStreamGenerator.cs
@@ -556,7 +556,7 @@ namespace Org.BouncyCastle.Cms
sigGen.AddObject(CalculateVersion(contentTypeOid));
- Asn1EncodableVector digestAlgs = new Asn1EncodableVector();
+ Asn1EncodableVector digestAlgs = new Asn1EncodableVector(_messageDigestOids.Count);
foreach (string digestOid in _messageDigestOids)
{
diff --git a/crypto/src/cms/KeyAgreeRecipientInfoGenerator.cs b/crypto/src/cms/KeyAgreeRecipientInfoGenerator.cs
index 8feb25b43..6bcba0d80 100644
--- a/crypto/src/cms/KeyAgreeRecipientInfoGenerator.cs
+++ b/crypto/src/cms/KeyAgreeRecipientInfoGenerator.cs
@@ -108,7 +108,7 @@ namespace Org.BouncyCastle.Cms
DerSequence paramSeq = new DerSequence(m_keyEncryptionOid, DerNull.Instance);
AlgorithmIdentifier keyEncAlg = new AlgorithmIdentifier(m_keyAgreementOid, paramSeq);
- Asn1EncodableVector recipientEncryptedKeys = new Asn1EncodableVector();
+ Asn1EncodableVector recipientEncryptedKeys = new Asn1EncodableVector(m_recipientIDs.Count);
for (int i = 0; i < m_recipientIDs.Count; ++i)
{
var recipientID = m_recipientIDs[i];
diff --git a/crypto/src/cms/SignerInformation.cs b/crypto/src/cms/SignerInformation.cs
index 4e21b1246..2e32a3ae6 100644
--- a/crypto/src/cms/SignerInformation.cs
+++ b/crypto/src/cms/SignerInformation.cs
@@ -784,12 +784,12 @@ namespace Org.BouncyCastle.Cms
}
else
{
- v = new Asn1EncodableVector();
+ v = new Asn1EncodableVector(1);
}
- Asn1EncodableVector sigs = new Asn1EncodableVector();
-
- foreach (SignerInformation sigInf in counterSigners.GetSigners())
+ var signers = counterSigners.GetSigners();
+ Asn1EncodableVector sigs = new Asn1EncodableVector(signers.Count);
+ foreach (SignerInformation sigInf in signers)
{
sigs.Add(sigInf.ToSignerInfo());
}
|