From 637bd18ca616b294119b8e37cc22a23235f8c6d3 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 4 Oct 2021 16:03:24 +0200 Subject: [PATCH] Add ArmorTest --- .../java/org/pgpainless/sop/ArmorTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 pgpainless-sop/src/test/java/org/pgpainless/sop/ArmorTest.java diff --git a/pgpainless-sop/src/test/java/org/pgpainless/sop/ArmorTest.java b/pgpainless-sop/src/test/java/org/pgpainless/sop/ArmorTest.java new file mode 100644 index 00000000..9175673b --- /dev/null +++ b/pgpainless-sop/src/test/java/org/pgpainless/sop/ArmorTest.java @@ -0,0 +1,58 @@ +/* + * Copyright 2021 Paul Schaub. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.pgpainless.sop; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.io.ByteArrayInputStream; +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.pgpainless.PGPainless; +import org.pgpainless.util.ArmorUtils; +import sop.enums.ArmorLabel; +import sop.exception.SOPGPException; + +public class ArmorTest { + + @Test + public void labelIsNotSupported() { + assertThrows(SOPGPException.UnsupportedOption.class, () -> new SOPImpl().armor().label(ArmorLabel.Sig)); + } + + @Test + public void armor() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException { + byte[] data = PGPainless.generateKeyRing().modernKeyRing("Alice", null).getEncoded(); + byte[] knownGoodArmor = ArmorUtils.toAsciiArmoredString(data).getBytes(StandardCharsets.UTF_8); + byte[] armored = new SOPImpl() + .armor() + .data(new ByteArrayInputStream(data)) + .getBytes(); + + assertArrayEquals(knownGoodArmor, armored); + + byte[] dearmored = new SOPImpl().dearmor() + .data(new ByteArrayInputStream(knownGoodArmor)) + .getBytes(); + + assertArrayEquals(data, dearmored); + } +}