summary refs log tree commit diff
path: root/crypto/src/cms
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-02-14 19:10:46 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-02-14 19:10:46 +0700
commita443719f81481e83760aeb7b9a64589f62ef140d (patch)
tree344d1f13e87ed418aaf2d0c7984997323ab69a40 /crypto/src/cms
parentUpdate WrapperUtilities algorithms (diff)
downloadBouncyCastle.NET-ed25519-a443719f81481e83760aeb7b9a64589f62ef140d.tar.xz
Avoid unnecessary recoding
Diffstat (limited to 'crypto/src/cms')
-rw-r--r--crypto/src/cms/CMSUtils.cs2
-rw-r--r--crypto/src/cms/KeyAgreeRecipientInfoGenerator.cs16
2 files changed, 3 insertions, 15 deletions
diff --git a/crypto/src/cms/CMSUtils.cs b/crypto/src/cms/CMSUtils.cs
index 99258c995..aa25870e6 100644
--- a/crypto/src/cms/CMSUtils.cs
+++ b/crypto/src/cms/CMSUtils.cs
@@ -178,7 +178,7 @@ namespace Org.BouncyCastle.Cms
 
 		internal static TbsCertificateStructure GetTbsCertificateStructure(X509Certificate cert)
 		{
-			return TbsCertificateStructure.GetInstance(Asn1Object.FromByteArray(cert.GetTbsCertificate()));
+			return cert.CertificateStructure.TbsCertificate;
 		}
 
 		internal static IssuerAndSerialNumber GetIssuerAndSerialNumber(X509Certificate cert)
diff --git a/crypto/src/cms/KeyAgreeRecipientInfoGenerator.cs b/crypto/src/cms/KeyAgreeRecipientInfoGenerator.cs
index 7686ee422..c7c7f563f 100644
--- a/crypto/src/cms/KeyAgreeRecipientInfoGenerator.cs
+++ b/crypto/src/cms/KeyAgreeRecipientInfoGenerator.cs
@@ -109,21 +109,9 @@ namespace Org.BouncyCastle.Cms
 			Asn1EncodableVector recipientEncryptedKeys = new Asn1EncodableVector();
 			foreach (X509Certificate recipientCert in recipientCerts)
 			{
-				TbsCertificateStructure tbsCert;
-				try
-				{
-					tbsCert = TbsCertificateStructure.GetInstance(
-						Asn1Object.FromByteArray(recipientCert.GetTbsCertificate()));
-				}
-				catch (Exception)
-				{
-					throw new ArgumentException("can't extract TBS structure from certificate");
-				}
-
 				// TODO Should there be a SubjectKeyIdentifier-based alternative?
-				IssuerAndSerialNumber issuerSerial = new IssuerAndSerialNumber(
-					tbsCert.Issuer, tbsCert.SerialNumber.Value);
-				KeyAgreeRecipientIdentifier karid = new KeyAgreeRecipientIdentifier(issuerSerial);
+                KeyAgreeRecipientIdentifier karid = new KeyAgreeRecipientIdentifier(
+					CmsUtilities.GetIssuerAndSerialNumber(recipientCert));
 
 				ICipherParameters recipientPublicParams = recipientCert.GetPublicKey();
 				if (keyAgreementOID.Id.Equals(CmsEnvelopedGenerator.ECMqvSha1Kdf))