mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-12-22 12:57:57 +01:00
Implement sop encrypt --profile=XXX
This commit is contained in:
parent
f4ff5f89f7
commit
8a66f0bc4f
3 changed files with 38 additions and 0 deletions
|
@ -85,6 +85,12 @@ public class EncryptExternal implements Encrypt {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Encrypt profile(String profileName) {
|
||||||
|
commandList.add("--profile=" + profileName);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Ready plaintext(InputStream plaintext)
|
public Ready plaintext(InputStream plaintext)
|
||||||
throws IOException, SOPGPException.KeyIsProtected {
|
throws IOException, SOPGPException.KeyIsProtected {
|
||||||
|
|
|
@ -41,6 +41,10 @@ public class EncryptCmd extends AbstractSopCmd {
|
||||||
paramLabel = "PASSWORD")
|
paramLabel = "PASSWORD")
|
||||||
List<String> withKeyPassword = new ArrayList<>();
|
List<String> withKeyPassword = new ArrayList<>();
|
||||||
|
|
||||||
|
@CommandLine.Option(names = "--profile",
|
||||||
|
paramLabel = "PROFILE")
|
||||||
|
String profile;
|
||||||
|
|
||||||
@CommandLine.Parameters(index = "0..*",
|
@CommandLine.Parameters(index = "0..*",
|
||||||
paramLabel = "CERTS")
|
paramLabel = "CERTS")
|
||||||
List<String> certs = new ArrayList<>();
|
List<String> certs = new ArrayList<>();
|
||||||
|
@ -50,6 +54,15 @@ public class EncryptCmd extends AbstractSopCmd {
|
||||||
Encrypt encrypt = throwIfUnsupportedSubcommand(
|
Encrypt encrypt = throwIfUnsupportedSubcommand(
|
||||||
SopCLI.getSop().encrypt(), "encrypt");
|
SopCLI.getSop().encrypt(), "encrypt");
|
||||||
|
|
||||||
|
if (profile != null) {
|
||||||
|
try {
|
||||||
|
encrypt.profile(profile);
|
||||||
|
} catch (SOPGPException.UnsupportedProfile e) {
|
||||||
|
String errorMsg = getMsg("sop.error.usage.profile_not_supported", "encrypt", profile);
|
||||||
|
throw new SOPGPException.UnsupportedProfile(errorMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
try {
|
try {
|
||||||
encrypt.mode(type);
|
encrypt.mode(type);
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
import sop.Profile;
|
||||||
import sop.Ready;
|
import sop.Ready;
|
||||||
import sop.enums.EncryptAs;
|
import sop.enums.EncryptAs;
|
||||||
import sop.exception.SOPGPException;
|
import sop.exception.SOPGPException;
|
||||||
|
@ -146,6 +147,24 @@ public interface Encrypt {
|
||||||
return withCert(new ByteArrayInputStream(cert));
|
return withCert(new ByteArrayInputStream(cert));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pass in a profile.
|
||||||
|
*
|
||||||
|
* @param profile profile
|
||||||
|
* @return builder instance
|
||||||
|
*/
|
||||||
|
default Encrypt profile(Profile profile) {
|
||||||
|
return profile(profile.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pass in a profile identifier.
|
||||||
|
*
|
||||||
|
* @param profileName profile identifier
|
||||||
|
* @return builder instance
|
||||||
|
*/
|
||||||
|
Encrypt profile(String profileName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypt the given data yielding the ciphertext.
|
* Encrypt the given data yielding the ciphertext.
|
||||||
* @param plaintext plaintext
|
* @param plaintext plaintext
|
||||||
|
|
Loading…
Reference in a new issue