Skip to content

Commit

Permalink
Fix rcube::decrypt() (#9264)
Browse files Browse the repository at this point in the history
* do not skip test_encrypt_and_decrypt test
* Fix rcube::decrypt()
  • Loading branch information
mvorisek authored Dec 13, 2023
1 parent efd9605 commit a2b5bb8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion program/lib/Roundcube/rcube.php
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ public function decrypt($cipher, $key = 'des_key', $base64 = true)
$iv_size = openssl_cipher_iv_length($method);
$tag = null;

if (preg_match('/^##(.{16})##/', $cipher, $matches)) {
if (preg_match('/^##(.{16})##/s', $cipher, $matches)) {
$tag = $matches[1];
$cipher = substr($cipher, strlen($matches[0]));
}
Expand Down
19 changes: 8 additions & 11 deletions tests/Framework/Rcube.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,19 @@ function test_list_languages()
function test_encrypt_and_decrypt()
{
$rcube = rcube::get_instance();
$result = $rcube->decrypt($rcube->encrypt('test'));

$result = $rcube->decrypt($rcube->encrypt('test'));
$this->assertSame('test', $result);

// The following tests fail quite often, therefore we disable them
$this->markTestSkipped();

// Test AEAD cipher method
$defaultCipherMethod = $rcube->config->get('cipher_method');
$rcube->config->set('cipher_method', 'aes-256-gcm');

$result = $rcube->decrypt($rcube->encrypt('test'));

$this->assertSame('test', $result);

// Back to the default
$rcube->config->set('cipher_method', 'DES-EDE3-CBC');
try {
$result = $rcube->decrypt($rcube->encrypt('test'));
$this->assertSame('test', $result);
} finally {
$rcube->config->set('cipher_method', $defaultCipherMethod);
}
}

/**
Expand Down

0 comments on commit a2b5bb8

Please sign in to comment.