mirror of
https://codeberg.org/PGPainless/bc-sop.git
synced 2025-09-09 03:09:40 +02:00
Throw MissingArg for missing arguments
This commit is contained in:
parent
ea8b1b6459
commit
80de3585d7
2 changed files with 12 additions and 0 deletions
|
@ -20,6 +20,7 @@ public class BCDetachedVerify
|
|||
{
|
||||
|
||||
private final OpenPGPDetachedSignatureProcessor processor;
|
||||
private boolean hasCerts = false;
|
||||
|
||||
public BCDetachedVerify(OpenPGPApi api)
|
||||
{
|
||||
|
@ -50,12 +51,16 @@ public class BCDetachedVerify
|
|||
@Override
|
||||
public DetachedVerify cert(@NotNull InputStream inputStream) throws SOPGPException.BadData, IOException {
|
||||
processor.addVerificationCertificate(parseCertificate(inputStream));
|
||||
hasCerts = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Verification> data(@NotNull InputStream inputStream) throws IOException, SOPGPException.NoSignature, SOPGPException.BadData {
|
||||
if (!hasCerts) {
|
||||
throw new SOPGPException.MissingArg("No certificates provided for signature verification.");
|
||||
}
|
||||
List<OpenPGPSignature.OpenPGPDocumentSignature> signatures = processor.process(inputStream);
|
||||
|
||||
List<Verification> verifications = getVerifications(signatures);
|
||||
|
|
|
@ -31,6 +31,7 @@ public class BCEncrypt
|
|||
private final OpenPGPMessageGenerator mGen;
|
||||
private final List<OpenPGPKey> signingKeys = new ArrayList<>();
|
||||
private int signatureMode = PGPSignature.BINARY_DOCUMENT;
|
||||
private boolean hasEncryptionMethod = false;
|
||||
|
||||
public BCEncrypt(OpenPGPApi api) {
|
||||
super(api);
|
||||
|
@ -83,6 +84,7 @@ public class BCEncrypt
|
|||
public Encrypt withPassword(@NotNull String s)
|
||||
throws SOPGPException.PasswordNotHumanReadable, SOPGPException.UnsupportedOption {
|
||||
mGen.addEncryptionPassphrase(s.toCharArray());
|
||||
hasEncryptionMethod = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -92,6 +94,7 @@ public class BCEncrypt
|
|||
throws SOPGPException.CertCannotEncrypt, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData {
|
||||
try {
|
||||
mGen.addEncryptionCertificate(parseCertificate(inputStream));
|
||||
hasEncryptionMethod = true;
|
||||
} catch (InvalidEncryptionKeyException e) {
|
||||
throw new SOPGPException.CertCannotEncrypt("Certificate cannot encrypt", e);
|
||||
}
|
||||
|
@ -109,6 +112,10 @@ public class BCEncrypt
|
|||
@Override
|
||||
public ReadyWithResult<EncryptionResult> plaintext(@NotNull InputStream inputStream)
|
||||
throws SOPGPException.KeyIsProtected {
|
||||
if (!hasEncryptionMethod) {
|
||||
throw new SOPGPException.MissingArg("No encryption method provided.");
|
||||
}
|
||||
|
||||
for (OpenPGPKey key : signingKeys) {
|
||||
try {
|
||||
mGen.addSigningKey(key, new SignatureParameters.Callback() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue