1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-09 10:19:39 +02:00

SOP: Add convenience methods to deal with byte arrays

This commit is contained in:
Paul Schaub 2021-10-10 16:34:17 +02:00
parent 32f3f0246e
commit 15736586dd
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
25 changed files with 451 additions and 128 deletions

View file

@ -4,6 +4,7 @@
package sop.operation;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@ -41,6 +42,20 @@ public interface Encrypt {
SOPGPException.UnsupportedAsymmetricAlgo,
SOPGPException.BadData;
/**
* Adds the signer key.
*
* @param key byte array containing the encoded signer key
* @return builder instance
*/
default Encrypt signWith(byte[] key)
throws SOPGPException.KeyIsProtected,
SOPGPException.CertCannotSign,
SOPGPException.UnsupportedAsymmetricAlgo,
SOPGPException.BadData {
return signWith(new ByteArrayInputStream(key));
}
/**
* Encrypt with the given password.
*
@ -62,6 +77,19 @@ public interface Encrypt {
SOPGPException.UnsupportedAsymmetricAlgo,
SOPGPException.BadData;
/**
* Encrypt with the given cert.
*
* @param cert byte array containing the encoded cert.
* @return builder instance
*/
default Encrypt withCert(byte[] cert)
throws SOPGPException.CertCannotEncrypt,
SOPGPException.UnsupportedAsymmetricAlgo,
SOPGPException.BadData {
return withCert(new ByteArrayInputStream(cert));
}
/**
* Encrypt the given data yielding the ciphertext.
* @param plaintext plaintext
@ -69,4 +97,13 @@ public interface Encrypt {
*/
Ready plaintext(InputStream plaintext)
throws IOException;
/**
* Encrypt the given data yielding the ciphertext.
* @param plaintext plaintext
* @return input stream containing the ciphertext
*/
default Ready plaintext(byte[] plaintext) throws IOException {
return plaintext(new ByteArrayInputStream(plaintext));
}
}