Throw more helpful exception when already decrypted

This commit is contained in:
Stephen Paul Weber 2018-07-25 09:56:57 -05:00
parent a9fc3f9322
commit 413741fa84
2 changed files with 10 additions and 0 deletions

View File

@ -146,6 +146,9 @@ class OpenPGP_Crypt_Symmetric {
public static function getCipher($algo) { public static function getCipher($algo) {
$cipher = NULL; $cipher = NULL;
switch($algo) { switch($algo) {
case NULL:
case 0:
throw new Exception("Data is already unencrypted");
case 2: case 2:
$cipher = new Crypt_TripleDES(CRYPT_DES_MODE_CFB); $cipher = new Crypt_TripleDES(CRYPT_DES_MODE_CFB);
$key_bytes = 24; $key_bytes = 24;

View File

@ -114,6 +114,13 @@ class Decryption extends PHPUnit_Framework_TestCase {
$skey = OpenPGP_Crypt_Symmetric::decryptSecretKey("hello", $key[0]); $skey = OpenPGP_Crypt_Symmetric::decryptSecretKey("hello", $key[0]);
$this->assertSame(!!$skey, true); $this->assertSame(!!$skey, true);
} }
public function testAlreadyDecryptedSecretKey() {
$this->expectException(Exception::class);
$this->expectExceptionMessage("Data is already unencrypted");
$key = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/helloKey.gpg'));
OpenPGP_Crypt_Symmetric::decryptSecretKey("hello", $key[0]);
}
} }
class Encryption extends PHPUnit_Framework_TestCase { class Encryption extends PHPUnit_Framework_TestCase {