mirror of
https://github.com/php/php-src.git
synced 2026-04-20 22:41:20 +02:00
openssl_encrypt() currently throws a warning if the $tag out parameter is passed for a non-authenticated cipher. This violates the principle that a function should behave the same if a parameter is not passed, and if the default value is passed for the parameter. I believe this warning should simply be dropped and the $tag be populated with null, as is already the case. Otherwise, it is not possible to use openssl_encrypt() in generic wrapper APIs, that are compatible with both authenticated and non-authenticated encryption. Closes GH-6333.
51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
--TEST--
|
|
openssl_encrypt() error tests
|
|
--SKIPIF--
|
|
<?php if (!extension_loaded("openssl")) print "skip"; ?>
|
|
--FILE--
|
|
<?php
|
|
$data = "openssl_encrypt() tests";
|
|
$method = "AES-128-CBC";
|
|
$password = "openssl";
|
|
$iv = str_repeat("\0", openssl_cipher_iv_length($method));
|
|
$wrong = "wrong";
|
|
$object = new stdclass;
|
|
$arr = array(1);
|
|
|
|
// wrong parameters tests
|
|
var_dump(openssl_encrypt($data, $wrong, $password));
|
|
var_dump(openssl_encrypt($object, $method, $password));
|
|
var_dump(openssl_encrypt($data, $object, $password));
|
|
var_dump(openssl_encrypt($data, $method, $object));
|
|
var_dump(openssl_encrypt($arr, $method, $object));
|
|
var_dump(openssl_encrypt($data, $arr, $object));
|
|
var_dump(openssl_encrypt($data, $method, $arr));
|
|
|
|
// padding of the key is disabled
|
|
var_dump(openssl_encrypt($data, $method, $password, OPENSSL_DONT_ZERO_PAD_KEY, $iv));
|
|
?>
|
|
--EXPECTF--
|
|
Warning: openssl_encrypt(): Unknown cipher algorithm in %s on line %d
|
|
bool(false)
|
|
|
|
Warning: openssl_encrypt() expects parameter 1 to be string, object given in %s on line %d
|
|
NULL
|
|
|
|
Warning: openssl_encrypt() expects parameter 2 to be string, object given in %s on line %d
|
|
NULL
|
|
|
|
Warning: openssl_encrypt() expects parameter 3 to be string, object given in %s on line %d
|
|
NULL
|
|
|
|
Warning: openssl_encrypt() expects parameter 1 to be string, array given in %s on line %d
|
|
NULL
|
|
|
|
Warning: openssl_encrypt() expects parameter 2 to be string, array given in %s on line %d
|
|
NULL
|
|
|
|
Warning: openssl_encrypt() expects parameter 3 to be string, array given in %s on line %d
|
|
NULL
|
|
|
|
Warning: openssl_encrypt(): Key length cannot be set for the cipher method in %s on line %d
|
|
bool(false)
|