mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-09 10:19:47 +02:00
WiP: Implement first prototypes of all SOP commands for external binaries
This commit is contained in:
parent
efec4d9110
commit
a63b29fe80
21 changed files with 1473 additions and 146 deletions
|
@ -9,16 +9,72 @@ import org.junit.jupiter.api.condition.EnabledIf;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static sop.external.JUtils.arrayStartsWith;
|
||||
import static sop.external.JUtils.assertArrayStartsWith;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled")
|
||||
public class ExternalExtractCertTest extends AbstractExternalSOPTest {
|
||||
|
||||
private static final String BEGIN_PGP_PUBLIC_KEY_BLOCK = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n";
|
||||
private static final byte[] BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES = BEGIN_PGP_PUBLIC_KEY_BLOCK.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
@Test
|
||||
public void extractCertTest() throws IOException {
|
||||
InputStream keyIn = getSop().generateKey().userId("Alice").generate().getInputStream();
|
||||
String cert = new String(getSop().extractCert().key(keyIn).getBytes());
|
||||
assertTrue(cert.startsWith("-----BEGIN PGP PUBLIC KEY BLOCK-----\n"));
|
||||
public void extractArmoredCertFromArmoredKeyTest() throws IOException {
|
||||
InputStream keyIn = getSop().generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.generate()
|
||||
.getInputStream();
|
||||
|
||||
byte[] cert = getSop().extractCert().key(keyIn).getBytes();
|
||||
assertArrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractUnarmoredCertFromArmoredKeyTest() throws IOException {
|
||||
InputStream keyIn = getSop().generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.generate()
|
||||
.getInputStream();
|
||||
|
||||
byte[] cert = getSop().extractCert()
|
||||
.noArmor()
|
||||
.key(keyIn)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractArmoredCertFromUnarmoredKeyTest() throws IOException {
|
||||
InputStream keyIn = getSop().generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.noArmor()
|
||||
.generate()
|
||||
.getInputStream();
|
||||
|
||||
byte[] cert = getSop().extractCert()
|
||||
.key(keyIn)
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractUnarmoredCertFromUnarmoredKeyTest() throws IOException {
|
||||
InputStream keyIn = getSop().generateKey()
|
||||
.noArmor()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.generate()
|
||||
.getInputStream();
|
||||
|
||||
byte[] cert = getSop().extractCert()
|
||||
.noArmor()
|
||||
.key(keyIn)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue