Skip to content

Commit c905198

Browse files
committed
Add tests for SignatureSubpackets
1 parent cacd2d1 commit c905198

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.bouncycastle.bcpg.test;
2+
3+
import org.bouncycastle.bcpg.AEADAlgorithmTags;
4+
import org.bouncycastle.bcpg.SignatureSubpacketTags;
5+
import org.bouncycastle.bcpg.sig.LibrePGPPreferredEncryptionModes;
6+
import org.bouncycastle.util.Arrays;
7+
8+
import java.io.ByteArrayOutputStream;
9+
import java.io.IOException;
10+
11+
public class SignatureSubpacketsTest
12+
extends AbstractPacketTest
13+
{
14+
@Override
15+
public String getName()
16+
{
17+
return "SignatureSubpacketsTest";
18+
}
19+
20+
@Override
21+
public void performTest()
22+
throws Exception
23+
{
24+
testLibrePGPPreferredEncryptionModesSubpacket();
25+
}
26+
27+
private void testLibrePGPPreferredEncryptionModesSubpacket()
28+
throws IOException
29+
{
30+
int[] algorithms = new int[] {AEADAlgorithmTags.EAX, AEADAlgorithmTags.OCB};
31+
LibrePGPPreferredEncryptionModes encModes = new LibrePGPPreferredEncryptionModes(
32+
false, algorithms);
33+
34+
isTrue("Encryption Modes encoding mismatch",
35+
Arrays.areEqual(algorithms, encModes.getPreferences()));
36+
isFalse("Mismatch in critical flag", encModes.isCritical());
37+
38+
// encode to byte array and check correctness
39+
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
40+
encModes.encode(bOut);
41+
42+
isEncodingEqual("Packet encoding mismatch", new byte[]{
43+
3, // length
44+
SignatureSubpacketTags.LIBREPGP_PREFERRED_ENCRYPTION_MODES,
45+
AEADAlgorithmTags.EAX,
46+
AEADAlgorithmTags.OCB
47+
}, bOut.toByteArray());
48+
}
49+
50+
public static void main(String[] args)
51+
{
52+
runTest(new SignatureSubpacketsTest());
53+
}
54+
}

pg/src/test/java/org/bouncycastle/openpgp/test/RegressionTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.security.Security;
44

5+
import org.bouncycastle.bcpg.test.SignatureSubpacketsTest;
56
import org.bouncycastle.util.test.SimpleTest;
67
import org.bouncycastle.util.test.Test;
78

@@ -63,6 +64,7 @@ public class RegressionTest
6364
new OperatorJcajceTest(),
6465
new OpenPGPTest(),
6566
new OperatorBcTest(),
67+
new SignatureSubpacketsTest(),
6668

6769
new DedicatedEd25519KeyPairTest(),
6870
new DedicatedEd448KeyPairTest(),

0 commit comments

Comments
 (0)