Skip to content

Commit

Permalink
Roll back changes in PGPAeadTest
Browse files Browse the repository at this point in the history
  • Loading branch information
gefeili committed Nov 26, 2024
1 parent f959bc9 commit 8b3fdd3
Showing 1 changed file with 8 additions and 30 deletions.
38 changes: 8 additions & 30 deletions pg/src/test/java/org/bouncycastle/openpgp/test/PGPAeadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.bouncycastle.openpgp.operator.jcajce.JcePBEDataDecryptorFactoryBuilder;
import org.bouncycastle.openpgp.operator.jcajce.JcePBEKeyEncryptionMethodGenerator;
import org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
import org.bouncycastle.test.DumpUtil;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.Exceptions;
import org.bouncycastle.util.Strings;
Expand Down Expand Up @@ -196,53 +195,32 @@ private void knownV6TestVectorDecryptionTests()
private void testBcRoundTrip(boolean v5AEAD, int aeadAlg, int symAlg, byte[] plaintext, char[] password)
throws PGPException, IOException
{
String armored = testBcEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password, true);
String armored = testBcEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password);
testBcDecryption(armored, password, plaintext);
if (!v5AEAD)
{
armored = testBcEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password, false);
testBcDecryption(armored, password, plaintext);
}

}

private void testJceRoundTrip(boolean v5AEAD, int aeadAlg, int symAlg, byte[] plaintext, char[] password)
throws PGPException, IOException
{
String armored = testJceEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password, true);
String armored = testJceEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password);
testJceDecryption(armored, password, plaintext);
if (!v5AEAD)
{
armored = testJceEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password, false);
testJceDecryption(armored, password, plaintext);
}
}

private void testBcJceRoundTrip(boolean v5AEAD, int aeadAlg, int symAlg, byte[] plaintext, char[] password)
throws PGPException, IOException
{
String armored = testBcEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password, true);
String armored = testBcEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password);
testJceDecryption(armored, password, plaintext);
if (!v5AEAD)
{
armored = testBcEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password, false);
testJceDecryption(armored, password, plaintext);
}
}

private void testJceBcRoundTrip(boolean v5AEAD, int aeadAlg, int symAlg, byte[] plaintext, char[] password)
throws PGPException, IOException
{
String armored = testJceEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password, true);
String armored = testJceEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password);
testBcDecryption(armored, password, plaintext);
if (!v5AEAD)
{
armored = testJceEncryption(v5AEAD, aeadAlg, symAlg, plaintext, password, false);
testBcDecryption(armored, password, plaintext);
}
}

private String testBcEncryption(boolean v5AEAD, int aeadAlg, int symAlg, byte[] plaintext, char[] password, boolean setForceSessionKey)
private String testBcEncryption(boolean v5AEAD, int aeadAlg, int symAlg, byte[] plaintext, char[] password)
throws PGPException, IOException
{
ByteArrayOutputStream ciphertextOut = new ByteArrayOutputStream();
Expand All @@ -259,7 +237,7 @@ private String testBcEncryption(boolean v5AEAD, int aeadAlg, int symAlg, byte[]
encBuilder.setWithAEAD(aeadAlg, 6);

PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(encBuilder, false);
encGen.setForceSessionKey(setForceSessionKey);
encGen.setForceSessionKey(true);
PBEKeyEncryptionMethodGenerator encMethodGen = new BcPBEKeyEncryptionMethodGenerator(password,
digestCalculatorProvider.get(HashAlgorithmTags.SHA256));
encGen.addMethod(encMethodGen);
Expand Down Expand Up @@ -287,7 +265,7 @@ private String testBcEncryption(boolean v5AEAD, int aeadAlg, int symAlg, byte[]
return armored;
}

private String testJceEncryption(boolean v5AEAD, int aeadAlg, int symAlg, byte[] plaintext, char[] password, boolean setForceSessionKey)
private String testJceEncryption(boolean v5AEAD, int aeadAlg, int symAlg, byte[] plaintext, char[] password)
throws PGPException, IOException
{
BouncyCastleProvider provider = new BouncyCastleProvider();
Expand All @@ -306,7 +284,7 @@ private String testJceEncryption(boolean v5AEAD, int aeadAlg, int symAlg, byte[]
}
encBuilder.setWithAEAD(aeadAlg, 6);
PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(encBuilder, false);
encGen.setForceSessionKey(setForceSessionKey);
encGen.setForceSessionKey(true);
PBEKeyEncryptionMethodGenerator encMethodGen = new JcePBEKeyEncryptionMethodGenerator(password,
digestCalculatorProvider.get(HashAlgorithmTags.SHA256));
encGen.addMethod(encMethodGen);
Expand Down

0 comments on commit 8b3fdd3

Please sign in to comment.