1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 04:42:06 +01:00

Added working tests(string, bytes) to EncryptDecryptTest

This commit is contained in:
DenBond7 2021-03-17 13:49:31 +02:00
parent 447593a65d
commit f34c787a4d
No known key found for this signature in database
GPG key ID: F74FC4E6441BA8C3

View file

@ -21,11 +21,13 @@ import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -43,8 +45,8 @@ class KeyRingReaderTest {
void publicKeyRingCollectionFromString() 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);
ArmoredInputStream armoredInputStream = new ArmoredInputStream(new ByteArrayInputStream(armoredString.getBytes(StandardCharsets.UTF_8)));
PGPPublicKeyRingCollection rings = PGPainless.readKeyRing().publicKeyRingCollection(armoredInputStream);
assertEquals(rings.size(), 10);
}
@ -52,8 +54,24 @@ class KeyRingReaderTest {
void publicKeyRingCollectionFromBytes() throws IOException, PGPException, URISyntaxException {
URL resource = getClass().getClassLoader().getResource("pub_keys_10_pieces.asc");
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);
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);
}
}