Add API for verification of inline signed messages

This commit is contained in:
Paul Schaub 2022-05-24 21:34:50 +02:00
parent fd9192995f
commit 72c3b3218d
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
3 changed files with 114 additions and 42 deletions

View File

@ -0,0 +1,55 @@
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
//
// 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 <T> Builder type ({@link Verify}, {@link InlineVerify})
*/
public interface AbstractVerify<T> {
/**
* 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));
}
}

View File

@ -0,0 +1,50 @@
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
//
// 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<InlineVerify> {
/**
* 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<List<Verification>> 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<List<Verification>> data(byte[] data)
throws IOException, SOPGPException.NoSignature, SOPGPException.BadData {
return data(new ByteArrayInputStream(data));
}
}

View File

@ -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<Verify>, 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));
}
}