Adapt changes from sop-java 8.0.0

This commit is contained in:
Paul Schaub 2023-11-15 13:40:22 +01:00
parent 71431b7b0a
commit 1c10dd5bce
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
7 changed files with 27 additions and 28 deletions

View File

@ -4,30 +4,27 @@
package org.pgpainless.sop;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import org.bouncycastle.openpgp.PGPException;
import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.util.ArmorUtils;
import sop.enums.ArmorLabel;
import sop.exception.SOPGPException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ArmorTest {
@Test
public void labelIsNotSupported() {
assertThrows(SOPGPException.UnsupportedOption.class, () -> new SOPImpl().armor().label(ArmorLabel.Sig));
assertThrows(SOPGPException.UnsupportedOption.class, () -> new SOPImpl().armor().label(ArmorLabel.sig));
}
@Test
public void armor() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
public void armor() throws IOException {
byte[] data = PGPainless.generateKeyRing().modernKeyRing("Alice").getEncoded();
byte[] knownGoodArmor = ArmorUtils.toAsciiArmoredString(data)
.replace("Version: PGPainless\n", "") // armor command does not add version anymore

View File

@ -11,7 +11,8 @@ import java.io.IOException;
import org.junit.jupiter.api.Test;
import sop.ByteArrayAndResult;
import sop.DecryptionResult;
import sop.Ready;
import sop.EncryptionResult;
import sop.ReadyWithResult;
import sop.testsuite.assertions.VerificationListAssert;
public class CarolKeySignEncryptRoundtripTest {
@ -276,11 +277,11 @@ public class CarolKeySignEncryptRoundtripTest {
public void regressionTest() throws IOException {
SOPImpl sop = new SOPImpl();
byte[] msg = "Hello, World!\n".getBytes();
Ready encryption = sop.encrypt()
ReadyWithResult<EncryptionResult> encryption = sop.encrypt()
.signWith(CAROL_KEY.getBytes())
.withCert(BOB_CERT.getBytes())
.plaintext(msg);
byte[] ciphertext = encryption.getBytes();
byte[] ciphertext = encryption.toByteArrayAndResult().getBytes();
ByteArrayAndResult<DecryptionResult> decryption = sop.decrypt()
.withKey(BOB_KEY.getBytes())

View File

@ -51,7 +51,7 @@ public class DetachedSignTest {
public void signArmored() throws IOException {
byte[] signature = sop.sign()
.key(key)
.mode(SignAs.Binary)
.mode(SignAs.binary)
.data(data)
.toByteArrayAndResult().getBytes();
@ -95,7 +95,7 @@ public class DetachedSignTest {
byte[] signature = sop.sign()
.key(key)
.noArmor()
.mode(SignAs.Text)
.mode(SignAs.text)
.data(data)
.toByteArrayAndResult().getBytes();
@ -142,7 +142,7 @@ public class DetachedSignTest {
@Test
public void mode() throws IOException, PGPException {
byte[] signature = sop.sign()
.mode(SignAs.Text)
.mode(SignAs.text)
.key(key)
.data(data)
.toByteArrayAndResult().getBytes();

View File

@ -64,6 +64,7 @@ public class EncryptDecryptRoundTripTest {
.withCert(aliceCert)
.withCert(bobCert)
.plaintext(message)
.toByteArrayAndResult()
.getBytes();
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
@ -97,6 +98,7 @@ public class EncryptDecryptRoundTripTest {
.withCert(aliceCertNoArmor)
.noArmor()
.plaintext(message)
.toByteArrayAndResult()
.getBytes();
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
@ -118,6 +120,7 @@ public class EncryptDecryptRoundTripTest {
byte[] encrypted = sop.encrypt()
.withPassword("passphr4s3")
.plaintext(message)
.toByteArrayAndResult()
.getBytes();
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
@ -141,6 +144,7 @@ public class EncryptDecryptRoundTripTest {
sop.encrypt()
.withPassword("passphr4s3")
.plaintext(message)
.toByteArrayAndResult()
.getInputStream()
)
.toByteArrayAndResult();
@ -158,6 +162,7 @@ public class EncryptDecryptRoundTripTest {
byte[] encrypted = sop.encrypt()
.withPassword("passphr4s3 ")
.plaintext(message)
.toByteArrayAndResult()
.getBytes();
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
@ -178,6 +183,7 @@ public class EncryptDecryptRoundTripTest {
byte[] encrypted = sop.encrypt()
.withCert(bobCert)
.plaintext(message)
.toByteArrayAndResult()
.getBytes();
DecryptionResult result = sop.decrypt()
@ -196,6 +202,7 @@ public class EncryptDecryptRoundTripTest {
byte[] encrypted = sop.encrypt()
.withCert(bobCert)
.plaintext(message)
.toByteArrayAndResult()
.getBytes();
assertThrows(SOPGPException.MissingArg.class, () -> sop
@ -266,6 +273,7 @@ public class EncryptDecryptRoundTripTest {
byte[] ciphertext = sop.encrypt()
.withCert(cert)
.plaintext(plaintext)
.toByteArrayAndResult()
.getBytes();
byte[] decrypted = sop.decrypt()
@ -308,6 +316,7 @@ public class EncryptDecryptRoundTripTest {
.withCert(cert1)
.withCert(cert2)
.plaintext(plaintext)
.toByteArrayAndResult()
.getBytes();
byte[] decrypted = sop.decrypt()
@ -339,6 +348,7 @@ public class EncryptDecryptRoundTripTest {
byte[] ciphertext = sop.encrypt()
.withCert(cert)
.plaintext(plaintext)
.toByteArrayAndResult()
.getBytes();
assertThrows(SOPGPException.KeyIsProtected.class,
@ -571,6 +581,7 @@ public class EncryptDecryptRoundTripTest {
.profile("rfc4880")
.withCert(cert)
.plaintext(message)
.toByteArrayAndResult()
.getBytes();
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()

View File

@ -100,10 +100,4 @@ public class GenerateKeyTest {
assertThrows(SOPGPException.UnsupportedProfile.class, () ->
sop.generateKey().profile("invalid"));
}
@Test
public void nullProfile() {
assertThrows(SOPGPException.UnsupportedProfile.class, () ->
sop.generateKey().profile((String) null));
}
}

View File

@ -37,9 +37,4 @@ public class ListProfilesTest {
sop.listProfiles().subcommand("help"));
}
@Test
public void listProfilesOfNullThrows() {
assertThrows(SOPGPException.UnsupportedProfile.class, () ->
sop.listProfiles().subcommand(null));
}
}

View File

@ -75,6 +75,7 @@ public class PGPainlessChangeKeyPasswordTest extends ChangeKeyPasswordTest {
.withKeyPassword(p4)
.withCert(cert)
.plaintext(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8))
.toByteArrayAndResult()
.getBytes();
byte[] plaintext = sop.decrypt()
.verifyWithCert(cert)