external-sop: Mark methods with @Nonnull where applicable

This commit is contained in:
Paul Schaub 2023-11-15 13:52:36 +01:00
parent 0563105b1f
commit 2051c3632a
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
16 changed files with 146 additions and 54 deletions

View file

@ -106,76 +106,91 @@ public class ExternalSOP implements SOP {
}
@Override
@Nonnull
public Version version() {
return new VersionExternal(binaryName, properties);
}
@Override
@Nonnull
public GenerateKey generateKey() {
return new GenerateKeyExternal(binaryName, properties);
}
@Override
@Nonnull
public ExtractCert extractCert() {
return new ExtractCertExternal(binaryName, properties);
}
@Override
@Nonnull
public DetachedSign detachedSign() {
return new DetachedSignExternal(binaryName, properties, tempDirProvider);
}
@Override
@Nonnull
public InlineSign inlineSign() {
return new InlineSignExternal(binaryName, properties);
}
@Override
@Nonnull
public DetachedVerify detachedVerify() {
return new DetachedVerifyExternal(binaryName, properties);
}
@Override
@Nonnull
public InlineVerify inlineVerify() {
return new InlineVerifyExternal(binaryName, properties, tempDirProvider);
}
@Override
@Nonnull
public InlineDetach inlineDetach() {
return new InlineDetachExternal(binaryName, properties, tempDirProvider);
}
@Override
@Nonnull
public Encrypt encrypt() {
return new EncryptExternal(binaryName, properties, tempDirProvider);
}
@Override
@Nonnull
public Decrypt decrypt() {
return new DecryptExternal(binaryName, properties, tempDirProvider);
}
@Override
@Nonnull
public Armor armor() {
return new ArmorExternal(binaryName, properties);
}
@Override
@Nonnull
public ListProfiles listProfiles() {
return new ListProfilesExternal(binaryName, properties);
}
@Override
@Nonnull
public RevokeKey revokeKey() {
return new RevokeKeyExternal(binaryName, properties);
}
@Override
@Nonnull
public ChangeKeyPassword changeKeyPassword() {
return new ChangeKeyPasswordExternal(binaryName, properties);
}
@Override
@Nonnull
public Dearmor dearmor() {
return new DearmorExternal(binaryName, properties);
}
@ -349,7 +364,7 @@ public class ExternalSOP implements SOP {
return new Ready() {
@Override
public void writeTo(OutputStream outputStream) throws IOException {
public void writeTo(@Nonnull OutputStream outputStream) throws IOException {
byte[] buf = new byte[4096];
int r;
while ((r = stdIn.read(buf)) >= 0) {
@ -388,7 +403,7 @@ public class ExternalSOP implements SOP {
return new Ready() {
@Override
public void writeTo(OutputStream outputStream) throws IOException {
public void writeTo(@Nonnull OutputStream outputStream) throws IOException {
byte[] buf = new byte[4096];
int r;
while ((r = standardIn.read(buf)) > 0) {

View file

@ -10,6 +10,7 @@ import sop.exception.SOPGPException;
import sop.external.ExternalSOP;
import sop.operation.Armor;
import javax.annotation.Nonnull;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@ -30,13 +31,16 @@ public class ArmorExternal implements Armor {
}
@Override
public Armor label(ArmorLabel label) throws SOPGPException.UnsupportedOption {
@Deprecated
@Nonnull
public Armor label(@Nonnull ArmorLabel label) throws SOPGPException.UnsupportedOption {
commandList.add("--label=" + label);
return this;
}
@Override
public Ready data(InputStream data) throws SOPGPException.BadData {
@Nonnull
public Ready data(@Nonnull InputStream data) throws SOPGPException.BadData {
return ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, data);
}
}

View file

@ -9,6 +9,7 @@ import sop.exception.SOPGPException;
import sop.external.ExternalSOP;
import sop.operation.ChangeKeyPassword;
import javax.annotation.Nonnull;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@ -27,13 +28,15 @@ public class ChangeKeyPasswordExternal implements ChangeKeyPassword {
}
@Override
@Nonnull
public ChangeKeyPassword noArmor() {
this.commandList.add("--no-armor");
return this;
}
@Override
public ChangeKeyPassword oldKeyPassphrase(String oldPassphrase) {
@Nonnull
public ChangeKeyPassword oldKeyPassphrase(@Nonnull String oldPassphrase) {
this.commandList.add("--old-key-password=@ENV:KEY_PASSWORD_" + keyPasswordCounter);
this.envList.add("KEY_PASSWORD_" + keyPasswordCounter + "=" + oldPassphrase);
keyPasswordCounter++;
@ -42,7 +45,8 @@ public class ChangeKeyPasswordExternal implements ChangeKeyPassword {
}
@Override
public ChangeKeyPassword newKeyPassphrase(String newPassphrase) {
@Nonnull
public ChangeKeyPassword newKeyPassphrase(@Nonnull String newPassphrase) {
this.commandList.add("--new-key-password=@ENV:KEY_PASSWORD_" + keyPasswordCounter);
this.envList.add("KEY_PASSWORD_" + keyPasswordCounter + "=" + newPassphrase);
keyPasswordCounter++;
@ -51,7 +55,8 @@ public class ChangeKeyPasswordExternal implements ChangeKeyPassword {
}
@Override
public Ready keys(InputStream inputStream) throws SOPGPException.KeyIsProtected, SOPGPException.BadData {
@Nonnull
public Ready keys(@Nonnull InputStream inputStream) throws SOPGPException.KeyIsProtected, SOPGPException.BadData {
return ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, inputStream);
}
}

View file

@ -9,6 +9,7 @@ import sop.exception.SOPGPException;
import sop.external.ExternalSOP;
import sop.operation.Dearmor;
import javax.annotation.Nonnull;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@ -29,7 +30,8 @@ public class DearmorExternal implements Dearmor {
}
@Override
public Ready data(InputStream data) throws SOPGPException.BadData {
@Nonnull
public Ready data(@Nonnull InputStream data) throws SOPGPException.BadData {
return ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, data);
}
}

View file

@ -13,6 +13,7 @@ import sop.external.ExternalSOP;
import sop.operation.Decrypt;
import sop.util.UTCUtil;
import javax.annotation.Nonnull;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@ -48,21 +49,24 @@ public class DecryptExternal implements Decrypt {
}
@Override
public Decrypt verifyNotBefore(Date timestamp)
@Nonnull
public Decrypt verifyNotBefore(@Nonnull Date timestamp)
throws SOPGPException.UnsupportedOption {
this.commandList.add("--verify-not-before=" + UTCUtil.formatUTCDate(timestamp));
return this;
}
@Override
public Decrypt verifyNotAfter(Date timestamp)
@Nonnull
public Decrypt verifyNotAfter(@Nonnull Date timestamp)
throws SOPGPException.UnsupportedOption {
this.commandList.add("--verify-not-after=" + UTCUtil.formatUTCDate(timestamp));
return this;
}
@Override
public Decrypt verifyWithCert(InputStream cert)
@Nonnull
public Decrypt verifyWithCert(@Nonnull InputStream cert)
throws SOPGPException.BadData, SOPGPException.UnsupportedAsymmetricAlgo, IOException {
String envVar = "VERIFY_WITH_" + verifyWithCounter++;
commandList.add("--verify-with=@ENV:" + envVar);
@ -71,7 +75,8 @@ public class DecryptExternal implements Decrypt {
}
@Override
public Decrypt withSessionKey(SessionKey sessionKey)
@Nonnull
public Decrypt withSessionKey(@Nonnull SessionKey sessionKey)
throws SOPGPException.UnsupportedOption {
String envVar = "SESSION_KEY_" + withSessionKeyCounter++;
commandList.add("--with-session-key=@ENV:" + envVar);
@ -80,7 +85,8 @@ public class DecryptExternal implements Decrypt {
}
@Override
public Decrypt withPassword(String password)
@Nonnull
public Decrypt withPassword(@Nonnull String password)
throws SOPGPException.PasswordNotHumanReadable, SOPGPException.UnsupportedOption {
String envVar = "PASSWORD_" + withPasswordCounter++;
commandList.add("--with-password=@ENV:" + envVar);
@ -89,7 +95,8 @@ public class DecryptExternal implements Decrypt {
}
@Override
public Decrypt withKey(InputStream key)
@Nonnull
public Decrypt withKey(@Nonnull InputStream key)
throws SOPGPException.BadData, SOPGPException.UnsupportedAsymmetricAlgo, IOException {
String envVar = "KEY_" + keyCounter++;
commandList.add("@ENV:" + envVar);
@ -98,7 +105,8 @@ public class DecryptExternal implements Decrypt {
}
@Override
public Decrypt withKeyPassword(byte[] password)
@Nonnull
public Decrypt withKeyPassword(@Nonnull byte[] password)
throws SOPGPException.UnsupportedOption, SOPGPException.PasswordNotHumanReadable {
String envVar = "KEY_PASSWORD_" + withKeyPasswordCounter++;
commandList.add("--with-key-password=@ENV:" + envVar);
@ -107,7 +115,8 @@ public class DecryptExternal implements Decrypt {
}
@Override
public ReadyWithResult<DecryptionResult> ciphertext(InputStream ciphertext)
@Nonnull
public ReadyWithResult<DecryptionResult> ciphertext(@Nonnull InputStream ciphertext)
throws SOPGPException.BadData, SOPGPException.MissingArg, SOPGPException.CannotDecrypt,
SOPGPException.KeyIsProtected, IOException {
File tempDir = tempDirProvider.provideTempDirectory();
@ -131,7 +140,7 @@ public class DecryptExternal implements Decrypt {
return new ReadyWithResult<DecryptionResult>() {
@Override
public DecryptionResult writeTo(OutputStream outputStream) throws IOException {
public DecryptionResult writeTo(@Nonnull OutputStream outputStream) throws IOException {
byte[] buf = new byte[4096];
int r;
while ((r = ciphertext.read(buf)) > 0) {

View file

@ -12,6 +12,7 @@ import sop.exception.SOPGPException;
import sop.external.ExternalSOP;
import sop.operation.DetachedSign;
import javax.annotation.Nonnull;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@ -43,13 +44,15 @@ public class DetachedSignExternal implements DetachedSign {
}
@Override
@Nonnull
public DetachedSign noArmor() {
commandList.add("--no-armor");
return this;
}
@Override
public DetachedSign key(InputStream key) throws SOPGPException.KeyCannotSign, SOPGPException.BadData, SOPGPException.UnsupportedAsymmetricAlgo, IOException {
@Nonnull
public DetachedSign key(@Nonnull InputStream key) throws SOPGPException.KeyCannotSign, SOPGPException.BadData, SOPGPException.UnsupportedAsymmetricAlgo, IOException {
String envVar = "KEY_" + keyCounter++;
commandList.add("@ENV:" + envVar);
envList.add(envVar + "=" + ExternalSOP.readString(key));
@ -57,7 +60,8 @@ public class DetachedSignExternal implements DetachedSign {
}
@Override
public DetachedSign withKeyPassword(byte[] password) throws SOPGPException.UnsupportedOption, SOPGPException.PasswordNotHumanReadable {
@Nonnull
public DetachedSign withKeyPassword(@Nonnull byte[] password) throws SOPGPException.UnsupportedOption, SOPGPException.PasswordNotHumanReadable {
String envVar = "WITH_KEY_PASSWORD_" + withKeyPasswordCounter++;
commandList.add("--with-key-password=@ENV:" + envVar);
envList.add(envVar + "=" + new String(password));
@ -65,13 +69,15 @@ public class DetachedSignExternal implements DetachedSign {
}
@Override
public DetachedSign mode(SignAs mode) throws SOPGPException.UnsupportedOption {
@Nonnull
public DetachedSign mode(@Nonnull SignAs mode) throws SOPGPException.UnsupportedOption {
commandList.add("--as=" + mode);
return this;
}
@Override
public ReadyWithResult<SigningResult> data(InputStream data)
@Nonnull
public ReadyWithResult<SigningResult> data(@Nonnull InputStream data)
throws IOException, SOPGPException.KeyIsProtected, SOPGPException.ExpectedText {
File tempDir = tempDirProvider.provideTempDirectory();
@ -88,7 +94,7 @@ public class DetachedSignExternal implements DetachedSign {
return new ReadyWithResult<SigningResult>() {
@Override
public SigningResult writeTo(OutputStream outputStream) throws IOException {
public SigningResult writeTo(@Nonnull OutputStream outputStream) throws IOException {
byte[] buf = new byte[4096];
int r;
while ((r = data.read(buf)) > 0) {

View file

@ -11,6 +11,7 @@ import sop.operation.DetachedVerify;
import sop.operation.VerifySignatures;
import sop.util.UTCUtil;
import javax.annotation.Nonnull;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@ -42,31 +43,36 @@ public class DetachedVerifyExternal implements DetachedVerify {
}
@Override
public DetachedVerify notBefore(Date timestamp) throws SOPGPException.UnsupportedOption {
@Nonnull
public DetachedVerify notBefore(@Nonnull Date timestamp) throws SOPGPException.UnsupportedOption {
commandList.add("--not-before=" + UTCUtil.formatUTCDate(timestamp));
return this;
}
@Override
public DetachedVerify notAfter(Date timestamp) throws SOPGPException.UnsupportedOption {
@Nonnull
public DetachedVerify notAfter(@Nonnull Date timestamp) throws SOPGPException.UnsupportedOption {
commandList.add("--not-after=" + UTCUtil.formatUTCDate(timestamp));
return this;
}
@Override
public DetachedVerify cert(InputStream cert) throws SOPGPException.BadData {
@Nonnull
public DetachedVerify cert(@Nonnull InputStream cert) throws SOPGPException.BadData {
this.certs.add(cert);
return this;
}
@Override
public VerifySignatures signatures(InputStream signatures) throws SOPGPException.BadData {
@Nonnull
public VerifySignatures signatures(@Nonnull InputStream signatures) throws SOPGPException.BadData {
this.signatures = signatures;
return this;
}
@Override
public List<Verification> data(InputStream data) throws IOException, SOPGPException.NoSignature, SOPGPException.BadData {
@Nonnull
public List<Verification> data(@Nonnull InputStream data) throws IOException, SOPGPException.NoSignature, SOPGPException.BadData {
commandList.add("@ENV:SIGNATURE");
envList.add("SIGNATURE=" + ExternalSOP.readString(signatures));

View file

@ -12,6 +12,7 @@ import sop.exception.SOPGPException;
import sop.external.ExternalSOP;
import sop.operation.Encrypt;
import javax.annotation.Nonnull;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -42,20 +43,23 @@ public class EncryptExternal implements Encrypt {
}
@Override
@Nonnull
public Encrypt noArmor() {
this.commandList.add("--no-armor");
return this;
}
@Override
public Encrypt mode(EncryptAs mode)
@Nonnull
public Encrypt mode(@Nonnull EncryptAs mode)
throws SOPGPException.UnsupportedOption {
this.commandList.add("--as=" + mode);
return this;
}
@Override
public Encrypt signWith(InputStream key)
@Nonnull
public Encrypt signWith(@Nonnull InputStream key)
throws SOPGPException.KeyCannotSign, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData,
IOException {
String envVar = "SIGN_WITH_" + SIGN_WITH_COUNTER++;
@ -65,7 +69,8 @@ public class EncryptExternal implements Encrypt {
}
@Override
public Encrypt withKeyPassword(byte[] password)
@Nonnull
public Encrypt withKeyPassword(@Nonnull byte[] password)
throws SOPGPException.PasswordNotHumanReadable, SOPGPException.UnsupportedOption {
String envVar = "KEY_PASSWORD_" + KEY_PASSWORD_COUNTER++;
commandList.add("--with-key-password=@ENV:" + envVar);
@ -74,7 +79,8 @@ public class EncryptExternal implements Encrypt {
}
@Override
public Encrypt withPassword(String password)
@Nonnull
public Encrypt withPassword(@Nonnull String password)
throws SOPGPException.PasswordNotHumanReadable, SOPGPException.UnsupportedOption {
String envVar = "PASSWORD_" + PASSWORD_COUNTER++;
commandList.add("--with-password=@ENV:" + envVar);
@ -83,7 +89,8 @@ public class EncryptExternal implements Encrypt {
}
@Override
public Encrypt withCert(InputStream cert)
@Nonnull
public Encrypt withCert(@Nonnull InputStream cert)
throws SOPGPException.CertCannotEncrypt, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData,
IOException {
String envVar = "CERT_" + CERT_COUNTER++;
@ -93,13 +100,15 @@ public class EncryptExternal implements Encrypt {
}
@Override
public Encrypt profile(String profileName) {
@Nonnull
public Encrypt profile(@Nonnull String profileName) {
commandList.add("--profile=" + profileName);
return this;
}
@Override
public ReadyWithResult<EncryptionResult> plaintext(InputStream plaintext)
@Nonnull
public ReadyWithResult<EncryptionResult> plaintext(@Nonnull InputStream plaintext)
throws SOPGPException.KeyIsProtected, IOException {
File tempDir = tempDirProvider.provideTempDirectory();
@ -116,7 +125,7 @@ public class EncryptExternal implements Encrypt {
return new ReadyWithResult<EncryptionResult>() {
@Override
public EncryptionResult writeTo(OutputStream outputStream) throws IOException {
public EncryptionResult writeTo(@Nonnull OutputStream outputStream) throws IOException {
byte[] buf = new byte[4096];
int r;
while ((r = plaintext.read(buf)) > 0) {

View file

@ -9,6 +9,7 @@ import sop.exception.SOPGPException;
import sop.external.ExternalSOP;
import sop.operation.ExtractCert;
import javax.annotation.Nonnull;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@ -29,13 +30,15 @@ public class ExtractCertExternal implements ExtractCert {
}
@Override
@Nonnull
public ExtractCert noArmor() {
this.commandList.add("--no-armor");
return this;
}
@Override
public Ready key(InputStream keyInputStream) throws SOPGPException.BadData {
@Nonnull
public Ready key(@Nonnull InputStream keyInputStream) throws SOPGPException.BadData {
return ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, keyInputStream);
}
}

View file

@ -9,6 +9,7 @@ import sop.exception.SOPGPException;
import sop.external.ExternalSOP;
import sop.operation.GenerateKey;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@ -30,19 +31,22 @@ public class GenerateKeyExternal implements GenerateKey {
}
@Override
@Nonnull
public GenerateKey noArmor() {
this.commandList.add("--no-armor");
return this;
}
@Override
public GenerateKey userId(String userId) {
@Nonnull
public GenerateKey userId(@Nonnull String userId) {
this.commandList.add(userId);
return this;
}
@Override
public GenerateKey withKeyPassword(String password)
@Nonnull
public GenerateKey withKeyPassword(@Nonnull String password)
throws SOPGPException.PasswordNotHumanReadable, SOPGPException.UnsupportedOption {
this.commandList.add("--with-key-password=@ENV:KEY_PASSWORD_" + keyPasswordCounter);
this.envList.add("KEY_PASSWORD_" + keyPasswordCounter + "=" + password);
@ -52,18 +56,21 @@ public class GenerateKeyExternal implements GenerateKey {
}
@Override
public GenerateKey profile(String profile) {
@Nonnull
public GenerateKey profile(@Nonnull String profile) {
commandList.add("--profile=" + profile);
return this;
}
@Override
@Nonnull
public GenerateKey signingOnly() {
commandList.add("--signing-only");
return this;
}
@Override
@Nonnull
public Ready generate()
throws SOPGPException.MissingArg, SOPGPException.UnsupportedAsymmetricAlgo {
return ExternalSOP.executeProducingOperation(Runtime.getRuntime(), commandList, envList);

View file

@ -10,6 +10,7 @@ import sop.exception.SOPGPException;
import sop.external.ExternalSOP;
import sop.operation.InlineDetach;
import javax.annotation.Nonnull;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@ -37,13 +38,15 @@ public class InlineDetachExternal implements InlineDetach {
}
@Override
@Nonnull
public InlineDetach noArmor() {
commandList.add("--no-armor");
return this;
}
@Override
public ReadyWithResult<Signatures> message(InputStream messageInputStream) throws IOException, SOPGPException.BadData {
@Nonnull
public ReadyWithResult<Signatures> message(@Nonnull InputStream messageInputStream) throws IOException, SOPGPException.BadData {
File tempDir = tempDirProvider.provideTempDirectory();
File signaturesOut = new File(tempDir, "signatures");
@ -60,7 +63,7 @@ public class InlineDetachExternal implements InlineDetach {
return new ReadyWithResult<Signatures>() {
@Override
public Signatures writeTo(OutputStream outputStream) throws IOException {
public Signatures writeTo(@Nonnull OutputStream outputStream) throws IOException {
byte[] buf = new byte[4096];
int r;
while ((r = messageInputStream.read(buf)) > 0) {
@ -90,7 +93,7 @@ public class InlineDetachExternal implements InlineDetach {
final byte[] sigBytes = signaturesBuffer.toByteArray();
return new Signatures() {
@Override
public void writeTo(OutputStream signatureOutputStream) throws IOException {
public void writeTo(@Nonnull OutputStream signatureOutputStream) throws IOException {
signatureOutputStream.write(sigBytes);
}
};

View file

@ -10,6 +10,7 @@ import sop.exception.SOPGPException;
import sop.external.ExternalSOP;
import sop.operation.InlineSign;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@ -34,13 +35,15 @@ public class InlineSignExternal implements InlineSign {
}
@Override
@Nonnull
public InlineSign noArmor() {
commandList.add("--no-armor");
return this;
}
@Override
public InlineSign key(InputStream key) throws SOPGPException.KeyCannotSign, SOPGPException.BadData, SOPGPException.UnsupportedAsymmetricAlgo, IOException {
@Nonnull
public InlineSign key(@Nonnull InputStream key) throws SOPGPException.KeyCannotSign, SOPGPException.BadData, SOPGPException.UnsupportedAsymmetricAlgo, IOException {
String envVar = "KEY_" + keyCounter++;
commandList.add("@ENV:" + envVar);
envList.add(envVar + "=" + ExternalSOP.readString(key));
@ -48,7 +51,8 @@ public class InlineSignExternal implements InlineSign {
}
@Override
public InlineSign withKeyPassword(byte[] password) throws SOPGPException.UnsupportedOption, SOPGPException.PasswordNotHumanReadable {
@Nonnull
public InlineSign withKeyPassword(@Nonnull byte[] password) throws SOPGPException.UnsupportedOption, SOPGPException.PasswordNotHumanReadable {
String envVar = "WITH_KEY_PASSWORD_" + withKeyPasswordCounter++;
commandList.add("--with-key-password=@ENV:" + envVar);
envList.add(envVar + "=" + new String(password));
@ -56,13 +60,15 @@ public class InlineSignExternal implements InlineSign {
}
@Override
public InlineSign mode(InlineSignAs mode) throws SOPGPException.UnsupportedOption {
@Nonnull
public InlineSign mode(@Nonnull InlineSignAs mode) throws SOPGPException.UnsupportedOption {
commandList.add("--as=" + mode);
return this;
}
@Override
public Ready data(InputStream data) throws SOPGPException.KeyIsProtected, SOPGPException.ExpectedText {
@Nonnull
public Ready data(@Nonnull InputStream data) throws SOPGPException.KeyIsProtected, SOPGPException.ExpectedText {
return ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, data);
}
}

View file

@ -11,6 +11,7 @@ import sop.external.ExternalSOP;
import sop.operation.InlineVerify;
import sop.util.UTCUtil;
import javax.annotation.Nonnull;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@ -42,19 +43,22 @@ public class InlineVerifyExternal implements InlineVerify {
}
@Override
public InlineVerify notBefore(Date timestamp) throws SOPGPException.UnsupportedOption {
@Nonnull
public InlineVerify notBefore(@Nonnull Date timestamp) throws SOPGPException.UnsupportedOption {
commandList.add("--not-before=" + UTCUtil.formatUTCDate(timestamp));
return this;
}
@Override
public InlineVerify notAfter(Date timestamp) throws SOPGPException.UnsupportedOption {
@Nonnull
public InlineVerify notAfter(@Nonnull Date timestamp) throws SOPGPException.UnsupportedOption {
commandList.add("--not-after=" + UTCUtil.formatUTCDate(timestamp));
return this;
}
@Override
public InlineVerify cert(InputStream cert) throws SOPGPException.BadData, IOException {
@Nonnull
public InlineVerify cert(@Nonnull InputStream cert) throws SOPGPException.BadData, IOException {
String envVar = "CERT_" + certCounter++;
commandList.add("@ENV:" + envVar);
envList.add(envVar + "=" + ExternalSOP.readString(cert));
@ -62,7 +66,8 @@ public class InlineVerifyExternal implements InlineVerify {
}
@Override
public ReadyWithResult<List<Verification>> data(InputStream data) throws IOException, SOPGPException.NoSignature, SOPGPException.BadData {
@Nonnull
public ReadyWithResult<List<Verification>> data(@Nonnull InputStream data) throws IOException, SOPGPException.NoSignature, SOPGPException.BadData {
File tempDir = tempDirProvider.provideTempDirectory();
File verificationsOut = new File(tempDir, "verifications-out");
@ -79,7 +84,7 @@ public class InlineVerifyExternal implements InlineVerify {
return new ReadyWithResult<List<Verification>>() {
@Override
public List<Verification> writeTo(OutputStream outputStream) throws IOException, SOPGPException.NoSignature {
public List<Verification> writeTo(@Nonnull OutputStream outputStream) throws IOException, SOPGPException.NoSignature {
byte[] buf = new byte[4096];
int r;
while ((r = data.read(buf)) > 0) {

View file

@ -8,6 +8,7 @@ import sop.Profile;
import sop.external.ExternalSOP;
import sop.operation.ListProfiles;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -25,7 +26,8 @@ public class ListProfilesExternal implements ListProfiles {
}
@Override
public List<Profile> subcommand(String command) {
@Nonnull
public List<Profile> subcommand(@Nonnull String command) {
commandList.add(command);
try {
String output = new String(ExternalSOP.executeProducingOperation(Runtime.getRuntime(), commandList, envList).getBytes());

View file

@ -9,6 +9,7 @@ import sop.exception.SOPGPException;
import sop.external.ExternalSOP;
import sop.operation.RevokeKey;
import javax.annotation.Nonnull;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@ -28,13 +29,15 @@ public class RevokeKeyExternal implements RevokeKey {
}
@Override
@Nonnull
public RevokeKey noArmor() {
this.commandList.add("--no-armor");
return this;
}
@Override
public RevokeKey withKeyPassword(byte[] password) throws SOPGPException.UnsupportedOption, SOPGPException.PasswordNotHumanReadable {
@Nonnull
public RevokeKey withKeyPassword(@Nonnull byte[] password) throws SOPGPException.UnsupportedOption, SOPGPException.PasswordNotHumanReadable {
String envVar = "KEY_PASSWORD_" + withKeyPasswordCounter++;
commandList.add("--with-key-password=@ENV:" + envVar);
envList.add(envVar + "=" + new String(password));
@ -42,7 +45,8 @@ public class RevokeKeyExternal implements RevokeKey {
}
@Override
public Ready keys(InputStream keys) {
@Nonnull
public Ready keys(@Nonnull InputStream keys) {
return ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, keys);
}
}

View file

@ -7,6 +7,7 @@ package sop.external.operation;
import sop.external.ExternalSOP;
import sop.operation.Version;
import javax.annotation.Nonnull;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@ -27,6 +28,7 @@ public class VersionExternal implements Version {
}
@Override
@Nonnull
public String getName() {
String[] command = new String[] {binary, "version"};
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);
@ -45,6 +47,7 @@ public class VersionExternal implements Version {
}
@Override
@Nonnull
public String getVersion() {
String[] command = new String[] {binary, "version"};
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);
@ -63,6 +66,7 @@ public class VersionExternal implements Version {
}
@Override
@Nonnull
public String getBackendVersion() {
String[] command = new String[] {binary, "version", "--backend"};
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);
@ -82,6 +86,7 @@ public class VersionExternal implements Version {
}
@Override
@Nonnull
public String getExtendedVersion() {
String[] command = new String[] {binary, "version", "--extended"};
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);
@ -137,6 +142,7 @@ public class VersionExternal implements Version {
}
@Override
@Nonnull
public String getSopSpecVersion() {
String[] command = new String[] {binary, "version", "--sop-spec"};
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);