mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 03:17:58 +01:00
Make sop decrypt throw for unencrypted data
This commit is contained in:
parent
efc0cb357b
commit
14531f0050
2 changed files with 22 additions and 0 deletions
|
@ -149,6 +149,10 @@ public class DecryptImpl implements Decrypt {
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||||
|
|
||||||
|
if (!metadata.isEncrypted()) {
|
||||||
|
throw new SOPGPException.BadData("Data is not encrypted.");
|
||||||
|
}
|
||||||
|
|
||||||
List<Verification> verificationList = new ArrayList<>();
|
List<Verification> verificationList = new ArrayList<>();
|
||||||
for (SignatureVerification signatureVerification : metadata.getVerifiedInbandSignatures()) {
|
for (SignatureVerification signatureVerification : metadata.getVerifiedInbandSignatures()) {
|
||||||
verificationList.add(map(signatureVerification));
|
verificationList.add(map(signatureVerification));
|
||||||
|
|
|
@ -515,4 +515,22 @@ public class EncryptDecryptRoundTripTest {
|
||||||
assertThrows(SOPGPException.BadData.class, () ->
|
assertThrows(SOPGPException.BadData.class, () ->
|
||||||
sop.decrypt().withSessionKey(wrongSessionKey).ciphertext(ciphertext));
|
sop.decrypt().withSessionKey(wrongSessionKey).ciphertext(ciphertext));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void decryptNonEncryptedDataFailsBadData() throws IOException {
|
||||||
|
byte[] signed = sop.inlineSign()
|
||||||
|
.key(aliceKey)
|
||||||
|
.withKeyPassword(alicePassword)
|
||||||
|
.data(message)
|
||||||
|
.getBytes();
|
||||||
|
|
||||||
|
assertThrows(SOPGPException.BadData.class, () ->
|
||||||
|
sop.decrypt()
|
||||||
|
.verifyWithCert(aliceCert)
|
||||||
|
.withKey(aliceKey)
|
||||||
|
.withKeyPassword(alicePassword)
|
||||||
|
.ciphertext(signed)
|
||||||
|
.toByteArrayAndResult()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue