Wip: Refactor command implementation and enable i18n for CLI

This commit is contained in:
Paul Schaub 2022-06-06 20:06:14 +02:00
parent a7f02d58cc
commit 4934e472e2
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
34 changed files with 980 additions and 782 deletions

View file

@ -13,8 +13,8 @@ import sop.operation.GenerateKey;
import sop.operation.InlineDetach;
import sop.operation.InlineSign;
import sop.operation.InlineVerify;
import sop.operation.Sign;
import sop.operation.Verify;
import sop.operation.DetachedSign;
import sop.operation.DetachedVerify;
import sop.operation.Version;
/**
@ -47,19 +47,72 @@ public interface SOP {
/**
* Create detached signatures.
* Customize the operation using the builder {@link Sign}.
* Customize the operation using the builder {@link DetachedSign}.
*
* If you want to sign a message inline, use {@link #inlineSign()} instead.
*
* @return builder instance
*/
Sign sign();
default DetachedSign sign() {
return detachedSign();
}
/**
* Create detached signatures.
* Customize the operation using the builder {@link DetachedSign}.
*
* If you want to sign a message inline, use {@link #inlineSign()} instead.
*
* @return builder instance
*/
DetachedSign detachedSign();
/**
* Sign a message using inline signatures.
*
* If you need to create detached signatures, use {@link #detachedSign()} instead.
*
* @return builder instance
*/
InlineSign inlineSign();
/**
* Verify detached signatures.
* Customize the operation using the builder {@link Verify}.
* Customize the operation using the builder {@link DetachedVerify}.
*
* If you need to verify an inline-signed message, use {@link #inlineVerify()} instead.
*
* @return builder instance
*/
Verify verify();
default DetachedVerify verify() {
return detachedVerify();
}
/**
* Verify detached signatures.
* Customize the operation using the builder {@link DetachedVerify}.
*
* If you need to verify an inline-signed message, use {@link #inlineVerify()} instead.
*
* @return builder instance
*/
DetachedVerify detachedVerify();
/**
* Verify signatures of an inline-signed message.
*
* If you need to verify detached signatures over a message, use {@link #detachedVerify()} instead.
*
* @return builder instance
*/
InlineVerify inlineVerify();
/**
* Detach signatures from an inline signed message.
*
* @return builder instance
*/
InlineDetach inlineDetach();
/**
* Encrypt a message.
@ -93,9 +146,4 @@ public interface SOP {
*/
Dearmor dearmor();
InlineDetach inlineDetach();
InlineSign inlineSign();
InlineVerify inlineVerify();
}

View file

@ -6,6 +6,5 @@ package sop.enums;
public enum EncryptAs {
Binary,
Text,
MIME
Text
}

View file

@ -35,6 +35,10 @@ public abstract class SOPGPException extends RuntimeException {
super("No verifiable signature found.");
}
public NoSignature(String errorMsg, NoSignature e) {
super(errorMsg, e);
}
@Override
public int getExitCode() {
return EXIT_CODE;
@ -225,6 +229,10 @@ public abstract class SOPGPException extends RuntimeException {
super(message, cause);
}
public MissingInput(String errorMsg) {
super(errorMsg);
}
@Override
public int getExitCode() {
return EXIT_CODE;
@ -276,6 +284,10 @@ public abstract class SOPGPException extends RuntimeException {
public static final int EXIT_CODE = 71;
public UnsupportedSpecialPrefix(String errorMsg) {
super(errorMsg);
}
@Override
public int getExitCode() {
return EXIT_CODE;

View file

@ -20,7 +20,7 @@ public interface AbstractSign<T> {
*
* @return builder instance
*/
Sign noArmor();
DetachedSign noArmor();
/**
* Add one or more signing keys.

View file

@ -12,9 +12,9 @@ import java.util.Date;
/**
* Common API methods shared between verification of inline signatures ({@link InlineVerify})
* and verification of detached signatures ({@link Verify}).
* and verification of detached signatures ({@link DetachedVerify}).
*
* @param <T> Builder type ({@link Verify}, {@link InlineVerify})
* @param <T> Builder type ({@link DetachedVerify}, {@link InlineVerify})
*/
public interface AbstractVerify<T> {

View file

@ -9,7 +9,7 @@ import sop.exception.SOPGPException;
import java.io.InputStream;
public interface Sign extends AbstractSign<Sign> {
public interface DetachedSign extends AbstractSign<DetachedSign> {
/**
* Sets the signature mode.
@ -20,6 +20,6 @@ public interface Sign extends AbstractSign<Sign> {
*
* @throws sop.exception.SOPGPException.UnsupportedOption if this option is not supported
*/
Sign mode(SignAs mode) throws SOPGPException.UnsupportedOption;
DetachedSign mode(SignAs mode) throws SOPGPException.UnsupportedOption;
}

View file

@ -12,7 +12,7 @@ import java.io.InputStream;
/**
* API for verifying detached signatures.
*/
public interface Verify extends AbstractVerify<Verify>, VerifySignatures {
public interface DetachedVerify extends AbstractVerify<DetachedVerify>, VerifySignatures {
/**
* Provides the detached signatures.

View file

@ -20,6 +20,6 @@ public interface InlineSign extends AbstractSign<InlineSign> {
*
* @throws sop.exception.SOPGPException.UnsupportedOption if this option is not supported
*/
Sign mode(InlineSignAs mode) throws SOPGPException.UnsupportedOption;
DetachedSign mode(InlineSignAs mode) throws SOPGPException.UnsupportedOption;
}