diff --git a/pg/src/test/java/org/bouncycastle/bcpg/test/SignatureSubpacketsTest.java b/pg/src/test/java/org/bouncycastle/bcpg/test/SignatureSubpacketsTest.java new file mode 100644 index 0000000000..05df687b77 --- /dev/null +++ b/pg/src/test/java/org/bouncycastle/bcpg/test/SignatureSubpacketsTest.java @@ -0,0 +1,54 @@ +package org.bouncycastle.bcpg.test; + +import org.bouncycastle.bcpg.AEADAlgorithmTags; +import org.bouncycastle.bcpg.SignatureSubpacketTags; +import org.bouncycastle.bcpg.sig.LibrePGPPreferredEncryptionModes; +import org.bouncycastle.util.Arrays; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +public class SignatureSubpacketsTest + extends AbstractPacketTest +{ + @Override + public String getName() + { + return "SignatureSubpacketsTest"; + } + + @Override + public void performTest() + throws Exception + { + testLibrePGPPreferredEncryptionModesSubpacket(); + } + + private void testLibrePGPPreferredEncryptionModesSubpacket() + throws IOException + { + int[] algorithms = new int[] {AEADAlgorithmTags.EAX, AEADAlgorithmTags.OCB}; + LibrePGPPreferredEncryptionModes encModes = new LibrePGPPreferredEncryptionModes( + false, algorithms); + + isTrue("Encryption Modes encoding mismatch", + Arrays.areEqual(algorithms, encModes.getPreferences())); + isFalse("Mismatch in critical flag", encModes.isCritical()); + + // encode to byte array and check correctness + ByteArrayOutputStream bOut = new ByteArrayOutputStream(); + encModes.encode(bOut); + + isEncodingEqual("Packet encoding mismatch", new byte[]{ + 3, // length + SignatureSubpacketTags.LIBREPGP_PREFERRED_ENCRYPTION_MODES, + AEADAlgorithmTags.EAX, + AEADAlgorithmTags.OCB + }, bOut.toByteArray()); + } + + public static void main(String[] args) + { + runTest(new SignatureSubpacketsTest()); + } +} diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/RegressionTest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/RegressionTest.java index 6c5ea8dd24..a2b832ff88 100644 --- a/pg/src/test/java/org/bouncycastle/openpgp/test/RegressionTest.java +++ b/pg/src/test/java/org/bouncycastle/openpgp/test/RegressionTest.java @@ -2,6 +2,7 @@ import java.security.Security; +import org.bouncycastle.bcpg.test.SignatureSubpacketsTest; import org.bouncycastle.util.test.SimpleTest; import org.bouncycastle.util.test.Test; @@ -63,6 +64,7 @@ public class RegressionTest new OperatorJcajceTest(), new OpenPGPTest(), new OperatorBcTest(), + new SignatureSubpacketsTest(), new DedicatedEd25519KeyPairTest(), new DedicatedEd448KeyPairTest(),