mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-17 18:02:05 +01:00
Bump sop-java to 4.0.2 and improve exception handling
This commit is contained in:
parent
3000e496bc
commit
e67c43a6f7
5 changed files with 29 additions and 6 deletions
|
@ -61,6 +61,11 @@ public class DecryptImpl implements Decrypt {
|
|||
|
||||
consumerOptions.addVerificationCerts(certs);
|
||||
|
||||
} catch (IOException e) {
|
||||
if (e.getMessage() != null && e.getMessage().startsWith("unknown object in stream:")) {
|
||||
throw new SOPGPException.BadData(e);
|
||||
}
|
||||
throw e;
|
||||
} catch (PGPException e) {
|
||||
throw new SOPGPException.BadData(e);
|
||||
}
|
||||
|
@ -96,15 +101,23 @@ public class DecryptImpl implements Decrypt {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DecryptImpl withKey(InputStream keyIn) throws SOPGPException.BadData, SOPGPException.UnsupportedAsymmetricAlgo {
|
||||
public DecryptImpl withKey(InputStream keyIn) throws SOPGPException.BadData, IOException, SOPGPException.UnsupportedAsymmetricAlgo {
|
||||
try {
|
||||
PGPSecretKeyRingCollection secretKeyCollection = PGPainless.readKeyRing()
|
||||
.secretKeyRingCollection(keyIn);
|
||||
if (secretKeyCollection.size() == 0) {
|
||||
throw new SOPGPException.BadData("No key data found.");
|
||||
}
|
||||
for (PGPSecretKeyRing key : secretKeyCollection) {
|
||||
protector.addSecretKey(key);
|
||||
consumerOptions.addDecryptionKey(key, protector);
|
||||
}
|
||||
} catch (IOException | PGPException e) {
|
||||
} catch (IOException e) {
|
||||
if (e.getMessage() != null && e.getMessage().startsWith("unknown object in stream:")) {
|
||||
throw new SOPGPException.BadData(e);
|
||||
}
|
||||
throw e;
|
||||
} catch (PGPException e) {
|
||||
throw new SOPGPException.BadData(e);
|
||||
}
|
||||
return this;
|
||||
|
@ -132,7 +145,7 @@ public class DecryptImpl implements Decrypt {
|
|||
.onInputStream(ciphertext)
|
||||
.withOptions(consumerOptions);
|
||||
} catch (MissingDecryptionMethodException e) {
|
||||
throw new SOPGPException.CannotDecrypt();
|
||||
throw new SOPGPException.CannotDecrypt("No usable decryption key or password provided.", e);
|
||||
} catch (WrongPassphraseException e) {
|
||||
throw new SOPGPException.KeyIsProtected();
|
||||
} catch (PGPException | IOException e) {
|
||||
|
|
|
@ -100,8 +100,10 @@ public class EncryptImpl implements Encrypt {
|
|||
public Encrypt withCert(InputStream cert) throws SOPGPException.CertCannotEncrypt, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData {
|
||||
try {
|
||||
PGPPublicKeyRingCollection certificates = PGPainless.readKeyRing()
|
||||
.keyRingCollection(cert, false)
|
||||
.getPgpPublicKeyRingCollection();
|
||||
.publicKeyRingCollection(cert);
|
||||
if (certificates.size() == 0) {
|
||||
throw new SOPGPException.BadData("No certificate data found.");
|
||||
}
|
||||
encryptionOptions.addRecipients(certificates);
|
||||
} catch (KeyException.UnacceptableEncryptionKeyException e) {
|
||||
throw new SOPGPException.CertCannotEncrypt(e.getMessage(), e);
|
||||
|
|
|
@ -35,6 +35,11 @@ public class ExtractCertImpl implements ExtractCert {
|
|||
PGPSecretKeyRingCollection keys;
|
||||
try {
|
||||
keys = PGPainless.readKeyRing().secretKeyRingCollection(keyInputStream);
|
||||
} catch (IOException e) {
|
||||
if (e.getMessage() != null && e.getMessage().startsWith("unknown object in stream:")) {
|
||||
throw new SOPGPException.BadData(e);
|
||||
}
|
||||
throw e;
|
||||
} catch (PGPException e) {
|
||||
throw new IOException("Cannot read keys.", e);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.pgpainless.decryption_verification.ConsumerOptions;
|
|||
import org.pgpainless.decryption_verification.DecryptionStream;
|
||||
import org.pgpainless.decryption_verification.OpenPgpMetadata;
|
||||
import org.pgpainless.decryption_verification.SignatureVerification;
|
||||
import org.pgpainless.exception.MissingDecryptionMethodException;
|
||||
import sop.ReadyWithResult;
|
||||
import sop.Verification;
|
||||
import sop.exception.SOPGPException;
|
||||
|
@ -84,6 +85,8 @@ public class InlineVerifyImpl implements InlineVerify {
|
|||
}
|
||||
|
||||
return verificationList;
|
||||
} catch (MissingDecryptionMethodException e) {
|
||||
throw new SOPGPException.BadData("Cannot verify encrypted message.", e);
|
||||
} catch (PGPException e) {
|
||||
throw new SOPGPException.BadData(e);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,6 @@ allprojects {
|
|||
logbackVersion = '1.2.11'
|
||||
mockitoVersion = '4.5.1'
|
||||
slf4jVersion = '1.7.36'
|
||||
sopJavaVersion = '4.0.1'
|
||||
sopJavaVersion = '4.0.2'
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue