Skip to content

Commit fc75aa0

Browse files
authored
Add tests for Compute{Counter}Signature with attribute certificates
1 parent 4960cab commit fc75aa0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/libraries/System.Security.Cryptography.Pkcs/tests/SignedCms/SignedCmsTests.netcoreapp.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,43 @@ public static void RemoveCertificate_NonExisting_CollectionContainsAttributeCert
654654
}
655655
}
656656

657+
[Fact]
658+
public static void ComputeCounterSignature_PreservesAttributeCertificate()
659+
{
660+
SignedCms signedCms = new SignedCms();
661+
signedCms.Decode(SignedDocuments.TstWithAttributeCertificate);
662+
int countBefore = CountCertificateChoices(SignedDocuments.TstWithAttributeCertificate);
663+
664+
using (X509Certificate2 cert = Certificates.RSA2048SignatureOnly.TryGetCertificateWithPrivateKey())
665+
{
666+
CmsSigner signer = new CmsSigner(cert);
667+
SignerInfo info = signedCms.SignerInfos[0];
668+
info.ComputeCounterSignature(signer);
669+
}
670+
671+
byte[] encoded = signedCms.Encode();
672+
int countAfter = CountCertificateChoices(encoded);
673+
Assert.Equal(countBefore + 1, countAfter);
674+
}
675+
676+
[Fact]
677+
public static void ComputeSignature_PreservesAttributeCertificate()
678+
{
679+
SignedCms signedCms = new SignedCms();
680+
signedCms.Decode(SignedDocuments.TstWithAttributeCertificate);
681+
int countBefore = CountCertificateChoices(SignedDocuments.TstWithAttributeCertificate);
682+
683+
using (X509Certificate2 cert = Certificates.RSA2048SignatureOnly.TryGetCertificateWithPrivateKey())
684+
{
685+
CmsSigner signer = new CmsSigner(cert);
686+
signedCms.ComputeSignature(signer);
687+
}
688+
689+
byte[] encoded = signedCms.Encode();
690+
int countAfter = CountCertificateChoices(encoded);
691+
Assert.Equal(countBefore + 1, countAfter);
692+
}
693+
657694
private static void VerifyWithExplicitPrivateKey(X509Certificate2 cert, AsymmetricAlgorithm key)
658695
{
659696
using (var pubCert = new X509Certificate2(cert.RawData))

0 commit comments

Comments
 (0)