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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -8,6 +8,7 @@ import sop.Profile;
import sop.external.ExternalSOP; import sop.external.ExternalSOP;
import sop.operation.ListProfiles; import sop.operation.ListProfiles;
import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -25,7 +26,8 @@ public class ListProfilesExternal implements ListProfiles {
} }
@Override @Override
public List<Profile> subcommand(String command) { @Nonnull
public List<Profile> subcommand(@Nonnull String command) {
commandList.add(command); commandList.add(command);
try { try {
String output = new String(ExternalSOP.executeProducingOperation(Runtime.getRuntime(), commandList, envList).getBytes()); 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.external.ExternalSOP;
import sop.operation.RevokeKey; import sop.operation.RevokeKey;
import javax.annotation.Nonnull;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -28,13 +29,15 @@ public class RevokeKeyExternal implements RevokeKey {
} }
@Override @Override
@Nonnull
public RevokeKey noArmor() { public RevokeKey noArmor() {
this.commandList.add("--no-armor"); this.commandList.add("--no-armor");
return this; return this;
} }
@Override @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++; String envVar = "KEY_PASSWORD_" + withKeyPasswordCounter++;
commandList.add("--with-key-password=@ENV:" + envVar); commandList.add("--with-key-password=@ENV:" + envVar);
envList.add(envVar + "=" + new String(password)); envList.add(envVar + "=" + new String(password));
@ -42,7 +45,8 @@ public class RevokeKeyExternal implements RevokeKey {
} }
@Override @Override
public Ready keys(InputStream keys) { @Nonnull
public Ready keys(@Nonnull InputStream keys) {
return ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, 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.external.ExternalSOP;
import sop.operation.Version; import sop.operation.Version;
import javax.annotation.Nonnull;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -27,6 +28,7 @@ public class VersionExternal implements Version {
} }
@Override @Override
@Nonnull
public String getName() { public String getName() {
String[] command = new String[] {binary, "version"}; String[] command = new String[] {binary, "version"};
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]); String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);
@ -45,6 +47,7 @@ public class VersionExternal implements Version {
} }
@Override @Override
@Nonnull
public String getVersion() { public String getVersion() {
String[] command = new String[] {binary, "version"}; String[] command = new String[] {binary, "version"};
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]); String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);
@ -63,6 +66,7 @@ public class VersionExternal implements Version {
} }
@Override @Override
@Nonnull
public String getBackendVersion() { public String getBackendVersion() {
String[] command = new String[] {binary, "version", "--backend"}; String[] command = new String[] {binary, "version", "--backend"};
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]); String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);
@ -82,6 +86,7 @@ public class VersionExternal implements Version {
} }
@Override @Override
@Nonnull
public String getExtendedVersion() { public String getExtendedVersion() {
String[] command = new String[] {binary, "version", "--extended"}; String[] command = new String[] {binary, "version", "--extended"};
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]); String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);
@ -137,6 +142,7 @@ public class VersionExternal implements Version {
} }
@Override @Override
@Nonnull
public String getSopSpecVersion() { public String getSopSpecVersion() {
String[] command = new String[] {binary, "version", "--sop-spec"}; String[] command = new String[] {binary, "version", "--sop-spec"};
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]); String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);