Skip to content

Commit

Permalink
Skip some tests if cipher not available
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Aug 6, 2021
1 parent 1cf4fb7 commit d23a8b3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ext/openssl/tests/bug71917.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Bug #71917: openssl_open() returns junk on envelope < 16 bytes
--EXTENSIONS--
openssl
--SKIPIF--
<?php
if (!in_array('rc4', openssl_get_cipher_methods())) die('skip rc4 not available');
?>
--FILE--
<?php
function test($envkey) {
Expand Down
4 changes: 4 additions & 0 deletions ext/openssl/tests/bug72362.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Bug #72362: OpenSSL Blowfish encryption is incorrect for short keys
--EXTENSIONS--
openssl
--SKIPIF--
<?php
if (!in_array('bf-ecb', openssl_get_cipher_methods())) die('skip bf-ecb not available');
?>
--FILE--
<?php
var_dump(
Expand Down
15 changes: 10 additions & 5 deletions ext/openssl/tests/openssl_decrypt_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ $padded_data = $data . str_repeat(' ', 16 - (strlen($data) % 16));
$encrypted = openssl_encrypt($padded_data, $method, $password, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
$output = openssl_decrypt($encrypted, $method, $password, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
var_dump(rtrim($output));
// if we want to prefer variable length cipher setting
$encrypted = openssl_encrypt($data, "bf-ecb", $password, OPENSSL_DONT_ZERO_PAD_KEY);
$output = openssl_decrypt($encrypted, "bf-ecb", $password, OPENSSL_DONT_ZERO_PAD_KEY);
var_dump($output);

if (in_array("bf-ecb", openssl_get_cipher_methods())) {
// if we want to prefer variable length cipher setting
$encrypted = openssl_encrypt($data, "bf-ecb", $password, OPENSSL_DONT_ZERO_PAD_KEY);
$output = openssl_decrypt($encrypted, "bf-ecb", $password, OPENSSL_DONT_ZERO_PAD_KEY);
var_dump($output === $data);
} else {
var_dump(true);
}

// It's okay to pass $tag for a non-authenticated cipher.
// It will be populated with null in that case.
Expand All @@ -39,5 +44,5 @@ var_dump($tag);
string(45) "openssl_encrypt() and openssl_decrypt() tests"
string(45) "openssl_encrypt() and openssl_decrypt() tests"
string(45) "openssl_encrypt() and openssl_decrypt() tests"
string(45) "openssl_encrypt() and openssl_decrypt() tests"
bool(true)
NULL

0 comments on commit d23a8b3

Please sign in to comment.