diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-02-28 18:49:21 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-02-28 18:49:21 +0700 |
commit | 5ac39b19f346e72005f41f13ff956f4fa7c97f86 (patch) | |
tree | 0ca4585a968a8b11044267b0268d3e65f29fa559 /crypto/test | |
parent | Update Asn1Tags (diff) | |
download | BouncyCastle.NET-ed25519-5ac39b19f346e72005f41f13ff956f4fa7c97f86.tar.xz |
OpenPGP updates from bc-java
Diffstat (limited to 'crypto/test')
-rw-r--r-- | crypto/test/src/openpgp/test/PolicyUrlTest.cs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/crypto/test/src/openpgp/test/PolicyUrlTest.cs b/crypto/test/src/openpgp/test/PolicyUrlTest.cs new file mode 100644 index 000000000..d98397f39 --- /dev/null +++ b/crypto/test/src/openpgp/test/PolicyUrlTest.cs @@ -0,0 +1,58 @@ +using System.IO; + +using NUnit.Framework; + +using Org.BouncyCastle.Bcpg.Sig; +using Org.BouncyCastle.Utilities; + +namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests +{ + [TestFixture] + public class PolicyUrlTest + { + [Test] + public void TestGetUrl() + { + PolicyUrl policyUrl = new PolicyUrl(true, "https://bouncycastle.org/policy/alice.txt"); + Assert.IsTrue(policyUrl.IsCritical()); + Assert.AreEqual("https://bouncycastle.org/policy/alice.txt", policyUrl.Url); + + policyUrl = new PolicyUrl(false, "https://bouncycastle.org/policy/bob.txt"); + Assert.IsFalse(policyUrl.IsCritical()); + Assert.AreEqual("https://bouncycastle.org/policy/bob.txt", policyUrl.Url); + } + + [Test] + public void TestParsingFromSignature() + { + string signatureWithPolicyUrl = "-----BEGIN PGP SIGNATURE-----\n" + + "\n" + + "iKQEHxYKAFYFAmIRIAgJEDXXpSQjWzWvFiEEVSc3S9X9kRTsyfjqNdelJCNbNa8u\n" + + "Gmh0dHBzOi8vZXhhbXBsZS5vcmcvfmFsaWNlL3NpZ25pbmctcG9saWN5LnR4dAAA\n" + + "NnwBAImA2KdiS/7kLWoQpwc+A6N2PtAvLxG0gkZmGzYgRWvGAP9g4GLAA/GQ0plr\n" + + "Xn7uLnOG49S1fFA9P+R1Dd8Qoa4+Dg==\n" + + "=OPUu\n" + + "-----END PGP SIGNATURE-----\n"; + + MemoryStream byteIn = new MemoryStream(Strings.ToByteArray(signatureWithPolicyUrl), false); + ArmoredInputStream armorIn = new ArmoredInputStream(byteIn); + PgpObjectFactory objectFactory = new PgpObjectFactory(armorIn); + + PgpSignatureList signatures = (PgpSignatureList)objectFactory.NextPgpObject(); + PgpSignature signature = signatures[0]; + + PolicyUrl policyUrl = signature.GetHashedSubPackets().GetPolicyUrl(); + Assert.AreEqual("https://example.org/~alice/signing-policy.txt", policyUrl.Url); + + PolicyUrl other = new PolicyUrl(false, "https://example.org/~alice/signing-policy.txt"); + + MemoryStream first = new MemoryStream(); + policyUrl.Encode(first); + + MemoryStream second = new MemoryStream(); + other.Encode(second); + + Assert.IsTrue(Arrays.AreEqual(first.ToArray(), second.ToArray())); + } + } +} |