mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 03:17:58 +01:00
Adapt changes from sop-java 8.0.0
This commit is contained in:
parent
71431b7b0a
commit
1c10dd5bce
7 changed files with 27 additions and 28 deletions
|
@ -4,30 +4,27 @@
|
||||||
|
|
||||||
package org.pgpainless.sop;
|
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.junit.jupiter.api.Test;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.util.ArmorUtils;
|
import org.pgpainless.util.ArmorUtils;
|
||||||
import sop.enums.ArmorLabel;
|
import sop.enums.ArmorLabel;
|
||||||
import sop.exception.SOPGPException;
|
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 {
|
public class ArmorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void labelIsNotSupported() {
|
public void labelIsNotSupported() {
|
||||||
assertThrows(SOPGPException.UnsupportedOption.class, () -> new SOPImpl().armor().label(ArmorLabel.Sig));
|
assertThrows(SOPGPException.UnsupportedOption.class, () -> new SOPImpl().armor().label(ArmorLabel.sig));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void armor() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
|
public void armor() throws IOException {
|
||||||
byte[] data = PGPainless.generateKeyRing().modernKeyRing("Alice").getEncoded();
|
byte[] data = PGPainless.generateKeyRing().modernKeyRing("Alice").getEncoded();
|
||||||
byte[] knownGoodArmor = ArmorUtils.toAsciiArmoredString(data)
|
byte[] knownGoodArmor = ArmorUtils.toAsciiArmoredString(data)
|
||||||
.replace("Version: PGPainless\n", "") // armor command does not add version anymore
|
.replace("Version: PGPainless\n", "") // armor command does not add version anymore
|
||||||
|
|
|
@ -11,7 +11,8 @@ import java.io.IOException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import sop.ByteArrayAndResult;
|
import sop.ByteArrayAndResult;
|
||||||
import sop.DecryptionResult;
|
import sop.DecryptionResult;
|
||||||
import sop.Ready;
|
import sop.EncryptionResult;
|
||||||
|
import sop.ReadyWithResult;
|
||||||
import sop.testsuite.assertions.VerificationListAssert;
|
import sop.testsuite.assertions.VerificationListAssert;
|
||||||
|
|
||||||
public class CarolKeySignEncryptRoundtripTest {
|
public class CarolKeySignEncryptRoundtripTest {
|
||||||
|
@ -276,11 +277,11 @@ public class CarolKeySignEncryptRoundtripTest {
|
||||||
public void regressionTest() throws IOException {
|
public void regressionTest() throws IOException {
|
||||||
SOPImpl sop = new SOPImpl();
|
SOPImpl sop = new SOPImpl();
|
||||||
byte[] msg = "Hello, World!\n".getBytes();
|
byte[] msg = "Hello, World!\n".getBytes();
|
||||||
Ready encryption = sop.encrypt()
|
ReadyWithResult<EncryptionResult> encryption = sop.encrypt()
|
||||||
.signWith(CAROL_KEY.getBytes())
|
.signWith(CAROL_KEY.getBytes())
|
||||||
.withCert(BOB_CERT.getBytes())
|
.withCert(BOB_CERT.getBytes())
|
||||||
.plaintext(msg);
|
.plaintext(msg);
|
||||||
byte[] ciphertext = encryption.getBytes();
|
byte[] ciphertext = encryption.toByteArrayAndResult().getBytes();
|
||||||
|
|
||||||
ByteArrayAndResult<DecryptionResult> decryption = sop.decrypt()
|
ByteArrayAndResult<DecryptionResult> decryption = sop.decrypt()
|
||||||
.withKey(BOB_KEY.getBytes())
|
.withKey(BOB_KEY.getBytes())
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class DetachedSignTest {
|
||||||
public void signArmored() throws IOException {
|
public void signArmored() throws IOException {
|
||||||
byte[] signature = sop.sign()
|
byte[] signature = sop.sign()
|
||||||
.key(key)
|
.key(key)
|
||||||
.mode(SignAs.Binary)
|
.mode(SignAs.binary)
|
||||||
.data(data)
|
.data(data)
|
||||||
.toByteArrayAndResult().getBytes();
|
.toByteArrayAndResult().getBytes();
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ public class DetachedSignTest {
|
||||||
byte[] signature = sop.sign()
|
byte[] signature = sop.sign()
|
||||||
.key(key)
|
.key(key)
|
||||||
.noArmor()
|
.noArmor()
|
||||||
.mode(SignAs.Text)
|
.mode(SignAs.text)
|
||||||
.data(data)
|
.data(data)
|
||||||
.toByteArrayAndResult().getBytes();
|
.toByteArrayAndResult().getBytes();
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ public class DetachedSignTest {
|
||||||
@Test
|
@Test
|
||||||
public void mode() throws IOException, PGPException {
|
public void mode() throws IOException, PGPException {
|
||||||
byte[] signature = sop.sign()
|
byte[] signature = sop.sign()
|
||||||
.mode(SignAs.Text)
|
.mode(SignAs.text)
|
||||||
.key(key)
|
.key(key)
|
||||||
.data(data)
|
.data(data)
|
||||||
.toByteArrayAndResult().getBytes();
|
.toByteArrayAndResult().getBytes();
|
||||||
|
|
|
@ -64,6 +64,7 @@ public class EncryptDecryptRoundTripTest {
|
||||||
.withCert(aliceCert)
|
.withCert(aliceCert)
|
||||||
.withCert(bobCert)
|
.withCert(bobCert)
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||||
|
@ -97,6 +98,7 @@ public class EncryptDecryptRoundTripTest {
|
||||||
.withCert(aliceCertNoArmor)
|
.withCert(aliceCertNoArmor)
|
||||||
.noArmor()
|
.noArmor()
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||||
|
@ -118,6 +120,7 @@ public class EncryptDecryptRoundTripTest {
|
||||||
byte[] encrypted = sop.encrypt()
|
byte[] encrypted = sop.encrypt()
|
||||||
.withPassword("passphr4s3")
|
.withPassword("passphr4s3")
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||||
|
@ -141,6 +144,7 @@ public class EncryptDecryptRoundTripTest {
|
||||||
sop.encrypt()
|
sop.encrypt()
|
||||||
.withPassword("passphr4s3")
|
.withPassword("passphr4s3")
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
|
.toByteArrayAndResult()
|
||||||
.getInputStream()
|
.getInputStream()
|
||||||
)
|
)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
@ -158,6 +162,7 @@ public class EncryptDecryptRoundTripTest {
|
||||||
byte[] encrypted = sop.encrypt()
|
byte[] encrypted = sop.encrypt()
|
||||||
.withPassword("passphr4s3 ")
|
.withPassword("passphr4s3 ")
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||||
|
@ -178,6 +183,7 @@ public class EncryptDecryptRoundTripTest {
|
||||||
byte[] encrypted = sop.encrypt()
|
byte[] encrypted = sop.encrypt()
|
||||||
.withCert(bobCert)
|
.withCert(bobCert)
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
DecryptionResult result = sop.decrypt()
|
DecryptionResult result = sop.decrypt()
|
||||||
|
@ -196,6 +202,7 @@ public class EncryptDecryptRoundTripTest {
|
||||||
byte[] encrypted = sop.encrypt()
|
byte[] encrypted = sop.encrypt()
|
||||||
.withCert(bobCert)
|
.withCert(bobCert)
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertThrows(SOPGPException.MissingArg.class, () -> sop
|
assertThrows(SOPGPException.MissingArg.class, () -> sop
|
||||||
|
@ -266,6 +273,7 @@ public class EncryptDecryptRoundTripTest {
|
||||||
byte[] ciphertext = sop.encrypt()
|
byte[] ciphertext = sop.encrypt()
|
||||||
.withCert(cert)
|
.withCert(cert)
|
||||||
.plaintext(plaintext)
|
.plaintext(plaintext)
|
||||||
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] decrypted = sop.decrypt()
|
byte[] decrypted = sop.decrypt()
|
||||||
|
@ -308,6 +316,7 @@ public class EncryptDecryptRoundTripTest {
|
||||||
.withCert(cert1)
|
.withCert(cert1)
|
||||||
.withCert(cert2)
|
.withCert(cert2)
|
||||||
.plaintext(plaintext)
|
.plaintext(plaintext)
|
||||||
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] decrypted = sop.decrypt()
|
byte[] decrypted = sop.decrypt()
|
||||||
|
@ -339,6 +348,7 @@ public class EncryptDecryptRoundTripTest {
|
||||||
byte[] ciphertext = sop.encrypt()
|
byte[] ciphertext = sop.encrypt()
|
||||||
.withCert(cert)
|
.withCert(cert)
|
||||||
.plaintext(plaintext)
|
.plaintext(plaintext)
|
||||||
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertThrows(SOPGPException.KeyIsProtected.class,
|
assertThrows(SOPGPException.KeyIsProtected.class,
|
||||||
|
@ -571,6 +581,7 @@ public class EncryptDecryptRoundTripTest {
|
||||||
.profile("rfc4880")
|
.profile("rfc4880")
|
||||||
.withCert(cert)
|
.withCert(cert)
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||||
|
|
|
@ -100,10 +100,4 @@ public class GenerateKeyTest {
|
||||||
assertThrows(SOPGPException.UnsupportedProfile.class, () ->
|
assertThrows(SOPGPException.UnsupportedProfile.class, () ->
|
||||||
sop.generateKey().profile("invalid"));
|
sop.generateKey().profile("invalid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void nullProfile() {
|
|
||||||
assertThrows(SOPGPException.UnsupportedProfile.class, () ->
|
|
||||||
sop.generateKey().profile((String) null));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,9 +37,4 @@ public class ListProfilesTest {
|
||||||
sop.listProfiles().subcommand("help"));
|
sop.listProfiles().subcommand("help"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void listProfilesOfNullThrows() {
|
|
||||||
assertThrows(SOPGPException.UnsupportedProfile.class, () ->
|
|
||||||
sop.listProfiles().subcommand(null));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ public class PGPainlessChangeKeyPasswordTest extends ChangeKeyPasswordTest {
|
||||||
.withKeyPassword(p4)
|
.withKeyPassword(p4)
|
||||||
.withCert(cert)
|
.withCert(cert)
|
||||||
.plaintext(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8))
|
.plaintext(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8))
|
||||||
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
byte[] plaintext = sop.decrypt()
|
byte[] plaintext = sop.decrypt()
|
||||||
.verifyWithCert(cert)
|
.verifyWithCert(cert)
|
||||||
|
|
Loading…
Reference in a new issue