summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-10-15 17:10:01 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-10-15 17:10:01 +0700
commitf84f98dcb1fff8ffdfa8a3b47708c6eb8f15c5cf (patch)
tree38160e84b7de77e8327fafddca26c1571c2d780d /crypto/test
parentMerge checks (diff)
downloadBouncyCastle.NET-ed25519-f84f98dcb1fff8ffdfa8a3b47708c6eb8f15c5cf.tar.xz
Use primitive encoding for short octet strings
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/src/asn1/test/CMSTest.cs46
-rw-r--r--crypto/test/src/asn1/test/PKCS12Test.cs23
2 files changed, 43 insertions, 26 deletions
diff --git a/crypto/test/src/asn1/test/CMSTest.cs b/crypto/test/src/asn1/test/CMSTest.cs

index 1afb363af..9930830f1 100644 --- a/crypto/test/src/asn1/test/CMSTest.cs +++ b/crypto/test/src/asn1/test/CMSTest.cs
@@ -18,7 +18,7 @@ namespace Org.BouncyCastle.Asn1.Tests // // compressed data object // - private static readonly byte[] compData = Base64.Decode( + private static readonly byte[] OrigCompData = Base64.Decode( "MIAGCyqGSIb3DQEJEAEJoIAwgAIBADANBgsqhkiG9w0BCRADCDCABgkqhkiG9w0BBwGggCSABIIC" + "Hnic7ZRdb9owFIbvK/k/5PqVYPFXGK12YYyboVFASSp1vQtZGiLRACZE49/XHoUW7S/0tXP8Efux" + "fU5ivWnasml72XFb3gb5druui7ytN803M570nii7C5r8tfwR281hy/p/KSM3+jzH5s3+pbQ90xSb" @@ -72,7 +72,7 @@ namespace Org.BouncyCastle.Asn1.Tests // // signed data // - private static readonly byte[] signedData = Base64.Decode( + private static readonly byte[] OrigSignedData = Base64.Decode( "MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAaCA" + "JIAEDEhlbGxvIFdvcmxkIQAAAAAAAKCCBGIwggINMIIBdqADAgECAgEBMA0GCSqG" + "SIb3DQEBBAUAMCUxFjAUBgNVBAoTDUJvdW5jeSBDYXN0bGUxCzAJBgNVBAYTAkFV" @@ -114,14 +114,10 @@ namespace Org.BouncyCastle.Asn1.Tests { try { - ContentInfo info = ContentInfo.GetInstance( - Asn1Object.FromByteArray(compData)); - CompressedData data = CompressedData.GetInstance(info.Content); - - data = new CompressedData(data.CompressionAlgorithmIdentifier, data.EncapContentInfo); - info = new ContentInfo(CmsObjectIdentifiers.CompressedData, data); + byte[] compData1 = ImplCompressionTest(OrigCompData); + byte[] compData2 = ImplCompressionTest(compData1); - if (!Arrays.AreEqual(info.GetEncoded(), compData)) + if (!Arrays.AreEqual(compData1, compData2)) { return new SimpleTestResult(false, Name + ": CMS compression failed to re-encode"); } @@ -134,7 +130,16 @@ namespace Org.BouncyCastle.Asn1.Tests } } - private ITestResult EnvelopedTest() + private byte[] ImplCompressionTest(byte[] compData) + { + ContentInfo info = ContentInfo.GetInstance(Asn1Object.FromByteArray(compData)); + CompressedData data = CompressedData.GetInstance(info.Content); + data = new CompressedData(data.CompressionAlgorithmIdentifier, data.EncapContentInfo); + info = new ContentInfo(CmsObjectIdentifiers.CompressedData, data); + return info.GetEncoded(); + } + + private ITestResult EnvelopedTest() { try { @@ -243,14 +248,10 @@ namespace Org.BouncyCastle.Asn1.Tests { try { - ContentInfo info = ContentInfo.GetInstance( - Asn1Object.FromByteArray(signedData)); - SignedData sData = SignedData.GetInstance(info.Content); - - sData = new SignedData(sData.DigestAlgorithms, sData.EncapContentInfo, sData.Certificates, sData.CRLs, sData.SignerInfos); - info = new ContentInfo(CmsObjectIdentifiers.SignedData, sData); + byte[] signedData1 = ImplSignedTest(OrigSignedData); + byte[] signedData2 = ImplSignedTest(signedData1); - if (!Arrays.AreEqual(info.GetEncoded(), signedData)) + if (!Arrays.AreEqual(signedData1, signedData2)) { return new SimpleTestResult(false, Name + ": CMS signed failed to re-encode"); } @@ -263,7 +264,16 @@ namespace Org.BouncyCastle.Asn1.Tests } } - public ITestResult Perform() + private byte[] ImplSignedTest(byte[] signedData) + { + ContentInfo info = ContentInfo.GetInstance(Asn1Object.FromByteArray(signedData)); + SignedData sData = SignedData.GetInstance(info.Content); + sData = new SignedData(sData.DigestAlgorithms, sData.EncapContentInfo, sData.Certificates, sData.CRLs, sData.SignerInfos); + info = new ContentInfo(CmsObjectIdentifiers.SignedData, sData); + return info.GetEncoded(); + } + + public ITestResult Perform() { ITestResult res = CompressionTest(); diff --git a/crypto/test/src/asn1/test/PKCS12Test.cs b/crypto/test/src/asn1/test/PKCS12Test.cs
index 5e4748728..eae61de46 100644 --- a/crypto/test/src/asn1/test/PKCS12Test.cs +++ b/crypto/test/src/asn1/test/PKCS12Test.cs
@@ -113,6 +113,20 @@ namespace Org.BouncyCastle.Asn1.Tests + "AgFkAAA="); public override void PerformTest() + { + byte[] pfxEncoding1 = ImplTest(pkcs12); + byte[] pfxEncoding2 = ImplTest(pfxEncoding1); + + // + // comparison test + // + if (!Arrays.AreEqual(pfxEncoding1, pfxEncoding2)) + { + Fail("failed comparison test"); + } + } + + private byte[] ImplTest(byte[] pkcs12) { Pfx bag = Pfx.GetInstance(pkcs12); ContentInfo info = bag.AuthSafe; @@ -178,14 +192,7 @@ namespace Org.BouncyCastle.Asn1.Tests bag = new Pfx(info, mData); - // - // comparison test - // - byte[] pfxEncoding = bag.GetEncoded(); - if (!Arrays.AreEqual(pfxEncoding, pkcs12)) - { - Fail("Failed comparison test"); - } + return bag.GetEncoded(); } public override string Name