Skip to content

Commit

Permalink
Add tests for SignatureSubpackets
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Jul 17, 2024
1 parent cacd2d1 commit c905198
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -63,6 +64,7 @@ public class RegressionTest
new OperatorJcajceTest(),
new OpenPGPTest(),
new OperatorBcTest(),
new SignatureSubpacketsTest(),

new DedicatedEd25519KeyPairTest(),
new DedicatedEd448KeyPairTest(),
Expand Down

0 comments on commit c905198

Please sign in to comment.