diff --git a/sop-java/src/main/java/sop/operation/AbstractVerify.java b/sop-java/src/main/java/sop/operation/AbstractVerify.java new file mode 100644 index 0000000..82582e1 --- /dev/null +++ b/sop-java/src/main/java/sop/operation/AbstractVerify.java @@ -0,0 +1,55 @@ +// SPDX-FileCopyrightText: 2022 Paul Schaub +// +// SPDX-License-Identifier: Apache-2.0 + +package sop.operation; + +import sop.exception.SOPGPException; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.Date; + +/** + * Common API methods shared between verification of inline signatures ({@link InlineVerify}) + * and verification of detached signatures ({@link Verify}). + * + * @param Builder type ({@link Verify}, {@link InlineVerify}) + */ +public interface AbstractVerify { + + /** + * Makes the SOP implementation consider signatures before this date invalid. + * + * @param timestamp timestamp + * @return builder instance + */ + T notBefore(Date timestamp) throws SOPGPException.UnsupportedOption; + + /** + * Makes the SOP implementation consider signatures after this date invalid. + * + * @param timestamp timestamp + * @return builder instance + */ + T notAfter(Date timestamp) throws SOPGPException.UnsupportedOption; + + /** + * Add one or more verification cert. + * + * @param cert input stream containing the encoded certs + * @return builder instance + */ + T cert(InputStream cert) throws SOPGPException.BadData; + + /** + * Add one or more verification cert. + * + * @param cert byte array containing the encoded certs + * @return builder instance + */ + default T cert(byte[] cert) throws SOPGPException.BadData { + return cert(new ByteArrayInputStream(cert)); + } + +} diff --git a/sop-java/src/main/java/sop/operation/InlineVerify.java b/sop-java/src/main/java/sop/operation/InlineVerify.java new file mode 100644 index 0000000..3b8031d --- /dev/null +++ b/sop-java/src/main/java/sop/operation/InlineVerify.java @@ -0,0 +1,50 @@ +// SPDX-FileCopyrightText: 2022 Paul Schaub +// +// SPDX-License-Identifier: Apache-2.0 + +package sop.operation; + +import sop.ReadyWithResult; +import sop.Verification; +import sop.exception.SOPGPException; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +/** + * API for verification of inline-signed messages. + */ +public interface InlineVerify extends AbstractVerify { + + /** + * Provide the inline-signed data. + * The result can be used to write the plaintext message out and to get the verifications. + * + * @param data signed data + * @return list of signature verifications + * + * @throws IOException in case of an IO error + * @throws SOPGPException.NoSignature when no signature is found + * @throws SOPGPException.BadData when the data is invalid OpenPGP data + */ + ReadyWithResult> data(InputStream data) + throws IOException, SOPGPException.NoSignature, SOPGPException.BadData; + + /** + * Provide the inline-signed data. + * The result can be used to write the plaintext message out and to get the verifications. + * + * @param data signed data + * @return list of signature verifications + * + * @throws IOException in case of an IO error + * @throws SOPGPException.NoSignature when no signature is found + * @throws SOPGPException.BadData when the data is invalid OpenPGP data + */ + default ReadyWithResult> data(byte[] data) + throws IOException, SOPGPException.NoSignature, SOPGPException.BadData { + return data(new ByteArrayInputStream(data)); + } +} diff --git a/sop-java/src/main/java/sop/operation/Verify.java b/sop-java/src/main/java/sop/operation/Verify.java index 1bf9fe0..d51affa 100644 --- a/sop-java/src/main/java/sop/operation/Verify.java +++ b/sop-java/src/main/java/sop/operation/Verify.java @@ -4,50 +4,18 @@ package sop.operation; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.Date; - import sop.exception.SOPGPException; -public interface Verify extends VerifySignatures { +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +/** + * API for verifying detached signatures. + */ +public interface Verify extends AbstractVerify, VerifySignatures { /** - * Makes the SOP implementation consider signatures before this date invalid. - * - * @param timestamp timestamp - * @return builder instance - */ - Verify notBefore(Date timestamp) throws SOPGPException.UnsupportedOption; - - /** - * Makes the SOP implementation consider signatures after this date invalid. - * - * @param timestamp timestamp - * @return builder instance - */ - Verify notAfter(Date timestamp) throws SOPGPException.UnsupportedOption; - - /** - * Add one or more verification cert. - * - * @param cert input stream containing the encoded certs - * @return builder instance - */ - Verify cert(InputStream cert) throws SOPGPException.BadData; - - /** - * Add one or more verification cert. - * - * @param cert byte array containing the encoded certs - * @return builder instance - */ - default Verify cert(byte[] cert) throws SOPGPException.BadData { - return cert(new ByteArrayInputStream(cert)); - } - - /** - * Provides the signatures. + * Provides the detached signatures. * @param signatures input stream containing encoded, detached signatures. * * @return builder instance @@ -55,7 +23,7 @@ public interface Verify extends VerifySignatures { VerifySignatures signatures(InputStream signatures) throws SOPGPException.BadData; /** - * Provides the signatures. + * Provides the detached signatures. * @param signatures byte array containing encoded, detached signatures. * * @return builder instance @@ -63,5 +31,4 @@ public interface Verify extends VerifySignatures { default VerifySignatures signatures(byte[] signatures) throws SOPGPException.BadData { return signatures(new ByteArrayInputStream(signatures)); } - }