diff --git a/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/ExtractCert.java b/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/ExtractCert.java index 60687ef8..03c00a3e 100644 --- a/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/ExtractCert.java +++ b/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/ExtractCert.java @@ -31,11 +31,10 @@ import static org.pgpainless.sop.Print.print_ln; @CommandLine.Command(name = "extract-cert") public class ExtractCert implements Runnable { - @CommandLine.Option(names = {"--armor"}, description = "ASCII Armor the output") - boolean armor = false; - - @CommandLine.Option(names = {"--no-armor"}) - boolean noArmor = false; + @CommandLine.Option(names = "--no-armor", + description = "ASCII armor the output", + negatable = true) + boolean armor = true; @Override public void run() { @@ -43,7 +42,7 @@ public class ExtractCert implements Runnable { PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(System.in); PGPPublicKeyRing publicKeys = BCUtil.publicKeyRingFromSecretKeyRing(secretKeys); - print_ln(Print.toString(publicKeys.getEncoded(), !noArmor)); + print_ln(Print.toString(publicKeys.getEncoded(), armor)); } catch (IOException | PGPException e) { err_ln("Error extracting certificate from keys;"); err_ln(e.getMessage()); diff --git a/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/GenerateKey.java b/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/GenerateKey.java index 5398991b..4ad33cff 100644 --- a/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/GenerateKey.java +++ b/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/GenerateKey.java @@ -31,11 +31,10 @@ import static org.pgpainless.sop.Print.print_ln; @CommandLine.Command(name = "generate-key") public class GenerateKey implements Runnable { - @CommandLine.Option(names = {"--armor"}, description = "ASCII Armor the output") - boolean armor = false; - - @CommandLine.Option(names = {"--no-armor"}, description = "Non-armored, binary output") - boolean noArmor = false; + @CommandLine.Option(names = "--no-armor", + description = "ASCII armor the output", + negatable = true) + boolean armor = true; @CommandLine.Parameters(description = "User-ID, eg. \"Alice \"") String userId; @@ -45,7 +44,7 @@ public class GenerateKey implements Runnable { try { PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing(userId); - print_ln(Print.toString(secretKeys.getEncoded(), !noArmor)); + print_ln(Print.toString(secretKeys.getEncoded(), armor)); } catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException | PGPException | IOException e) { err_ln("Error creating OpenPGP key:"); diff --git a/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/Sign.java b/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/Sign.java index 40ca52f0..928ea9ff 100644 --- a/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/Sign.java +++ b/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/Sign.java @@ -42,11 +42,10 @@ public class Sign implements Runnable { text } - @CommandLine.Option(names = {"--armor"}, description = "ASCII Armor the output") - boolean armor = false; - - @CommandLine.Option(names = {"--no-armor"}) - boolean noArmor = false; + @CommandLine.Option(names = "--no-armor", + description = "ASCII armor the output", + negatable = true) + boolean armor = true; @CommandLine.Option(names = "--as", description = "Defaults to 'binary'. If '--as=text' and the input data is not valid UTF-8, sign fails with return code 53.", paramLabel = "{binary|text}") @@ -74,15 +73,15 @@ public class Sign implements Runnable { .createDetachedSignature() .signWith(new UnprotectedKeysProtector(), secretKeys); - EncryptionBuilderInterface.Armor armor = type == Type.text ? documentType.signCanonicalText() : documentType.signBinaryDocument(); - EncryptionStream encryptionStream = noArmor ? armor.noArmor() : armor.asciiArmor(); + EncryptionBuilderInterface.Armor builder = type == Type.text ? documentType.signCanonicalText() : documentType.signBinaryDocument(); + EncryptionStream encryptionStream = armor ? builder.asciiArmor() : builder.noArmor(); Streams.pipeAll(System.in, encryptionStream); encryptionStream.close(); PGPSignature signature = encryptionStream.getResult().getSignatures().iterator().next(); - print_ln(Print.toString(signature.getEncoded(), !noArmor)); + print_ln(Print.toString(signature.getEncoded(), armor)); } catch (PGPException | IOException e) { err_ln("Error signing data."); err_ln(e.getMessage());