mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-23 12:52:07 +01:00
Added working tests(string, bytes) to EncryptDecryptTest
This commit is contained in:
parent
447593a65d
commit
f34c787a4d
1 changed files with 21 additions and 3 deletions
|
@ -21,11 +21,13 @@ import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
@ -43,8 +45,8 @@ class KeyRingReaderTest {
|
||||||
void publicKeyRingCollectionFromString() throws IOException, PGPException, URISyntaxException {
|
void publicKeyRingCollectionFromString() throws IOException, PGPException, URISyntaxException {
|
||||||
URL resource = getClass().getClassLoader().getResource("pub_keys_10_pieces.asc");
|
URL resource = getClass().getClassLoader().getResource("pub_keys_10_pieces.asc");
|
||||||
String armoredString = new String(Files.readAllBytes(new File(resource.toURI()).toPath()));
|
String armoredString = new String(Files.readAllBytes(new File(resource.toURI()).toPath()));
|
||||||
|
ArmoredInputStream armoredInputStream = new ArmoredInputStream(new ByteArrayInputStream(armoredString.getBytes(StandardCharsets.UTF_8)));
|
||||||
PGPPublicKeyRingCollection rings = PGPainless.readKeyRing().publicKeyRingCollection(armoredString);
|
PGPPublicKeyRingCollection rings = PGPainless.readKeyRing().publicKeyRingCollection(armoredInputStream);
|
||||||
assertEquals(rings.size(), 10);
|
assertEquals(rings.size(), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,8 +54,24 @@ class KeyRingReaderTest {
|
||||||
void publicKeyRingCollectionFromBytes() throws IOException, PGPException, URISyntaxException {
|
void publicKeyRingCollectionFromBytes() throws IOException, PGPException, URISyntaxException {
|
||||||
URL resource = getClass().getClassLoader().getResource("pub_keys_10_pieces.asc");
|
URL resource = getClass().getClassLoader().getResource("pub_keys_10_pieces.asc");
|
||||||
byte[] bytes = Files.readAllBytes(new File(resource.toURI()).toPath());
|
byte[] bytes = Files.readAllBytes(new File(resource.toURI()).toPath());
|
||||||
|
InputStream armoredInputStream = new ArmoredInputStream(new ByteArrayInputStream(bytes));
|
||||||
|
PGPPublicKeyRingCollection rings = PGPainless.readKeyRing().publicKeyRingCollection(armoredInputStream);
|
||||||
|
assertEquals(rings.size(), 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void publicKeyRingCollectionFromBytesFailed() throws IOException, PGPException, URISyntaxException {
|
||||||
|
URL resource = getClass().getClassLoader().getResource("pub_keys_10_pieces.asc");
|
||||||
|
byte[] bytes = Files.readAllBytes(new File(resource.toURI()).toPath());
|
||||||
PGPPublicKeyRingCollection rings = PGPainless.readKeyRing().publicKeyRingCollection(bytes);
|
PGPPublicKeyRingCollection rings = PGPainless.readKeyRing().publicKeyRingCollection(bytes);
|
||||||
assertEquals(rings.size(), 10);
|
assertEquals(rings.size(), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void publicKeyRingCollectionFromStringFailed() throws IOException, PGPException, URISyntaxException {
|
||||||
|
URL resource = getClass().getClassLoader().getResource("pub_keys_10_pieces.asc");
|
||||||
|
String armoredString = new String(Files.readAllBytes(new File(resource.toURI()).toPath()));
|
||||||
|
PGPPublicKeyRingCollection rings = PGPainless.readKeyRing().publicKeyRingCollection(armoredString);
|
||||||
|
assertEquals(rings.size(), 10);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue