Throw more helpful exception when already decrypted
This commit is contained in:
parent
a9fc3f9322
commit
413741fa84
@ -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;
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user