1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-26 05:24:49 +02:00
pgpainless/pgpainless-core/src/test/java/org/pgpainless/key/ImportExportKeyTest.java

50 lines
2 KiB
Java
Raw Permalink Normal View History

2021-10-07 15:48:52 +02:00
// SPDX-FileCopyrightText: 2018 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.key;
2020-11-13 16:31:59 +01:00
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.util.TestAllImplementations;
public class ImportExportKeyTest {
/**
* Test the export and import of a key ring with sub keys.
* @throws IOException in case of a IO error
*/
@TestTemplate
@ExtendWith(TestAllImplementations.class)
public void testExportImportPublicKeyRing() throws IOException {
PGPPublicKeyRing publicKeys = TestKeys.getJulietPublicKeyRing();
KeyFingerPrintCalculator calc = ImplementationFactory.getInstance().getKeyFingerprintCalculator();
byte[] bytes = publicKeys.getEncoded();
PGPPublicKeyRing parsed = new PGPPublicKeyRing(bytes, calc);
assertArrayEquals(publicKeys.getEncoded(), parsed.getEncoded());
}
@TestTemplate
@ExtendWith(TestAllImplementations.class)
public void testExportImportSecretKeyRing() throws IOException, PGPException {
PGPSecretKeyRing secretKeys = TestKeys.getRomeoSecretKeyRing();
KeyFingerPrintCalculator calc = ImplementationFactory.getInstance().getKeyFingerprintCalculator();
byte[] bytes = secretKeys.getEncoded();
PGPSecretKeyRing parsed = new PGPSecretKeyRing(bytes, calc);
assertArrayEquals(secretKeys.getEncoded(), parsed.getEncoded());
assertEquals(secretKeys.getPublicKey().getKeyID(), parsed.getPublicKey().getKeyID());
}
}