Skip to content

Commit

Permalink
Fixed Mcrypt deprecated functions and related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srgoogleguy committed Aug 16, 2012
1 parent 6a87a21 commit 7014a0e
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 9 deletions.
6 changes: 3 additions & 3 deletions ext/mcrypt/mcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ ZEND_END_ARG_INFO()

const zend_function_entry mcrypt_functions[] = { /* {{{ */
PHP_DEP_FE(mcrypt_ecb, arginfo_mcrypt_ecb)
PHP_FE(mcrypt_cbc, arginfo_mcrypt_cbc)
PHP_FE(mcrypt_cfb, arginfo_mcrypt_cfb)
PHP_FE(mcrypt_ofb, arginfo_mcrypt_ofb)
PHP_DEP_FE(mcrypt_cbc, arginfo_mcrypt_cbc)
PHP_DEP_FE(mcrypt_cfb, arginfo_mcrypt_cfb)
PHP_DEP_FE(mcrypt_ofb, arginfo_mcrypt_ofb)
PHP_FE(mcrypt_get_key_size, arginfo_mcrypt_get_key_size)
PHP_FE(mcrypt_get_block_size, arginfo_mcrypt_get_block_size)
PHP_FE(mcrypt_get_cipher_name, arginfo_mcrypt_get_cipher_name)
Expand Down
6 changes: 6 additions & 0 deletions ext/mcrypt/tests/mcrypt_cbc.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ echo trim(mcrypt_cbc($cipher, $key, $enc_data, MCRYPT_DECRYPT, $iv)) . "\n";
mcrypt_cbc($cipher, $key, $enc_data, MCRYPT_DECRYPT);

--EXPECTF--

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
PHP Testfest 2008

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): Attempt to use an empty IV, which is NOT recommend in %s on line %d
14 changes: 14 additions & 0 deletions ext/mcrypt/tests/mcrypt_cbc_3des_decrypt.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,45 @@ function special_var_dump($str) {
--- testing different key lengths

key length=8

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
string(32) "736563726574206d6573736167650000"

key length=20

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
string(32) "736563726574206d6573736167650000"

key length=24

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
string(32) "736563726574206d6573736167650000"

key length=26

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): Size of key is too large for this algorithm in %s on line %d
string(32) "736563726574206d6573736167650000"

--- testing different iv lengths

iv length=4

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
string(32) "736563726574206d6573736167650000"

iv length=8

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
string(32) "736563726574206d6573736167650000"

iv length=9

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
string(32) "736563726574206d6573736167650000"
===DONE===
14 changes: 14 additions & 0 deletions ext/mcrypt/tests/mcrypt_cbc_3des_encrypt.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,45 @@ foreach ($ivs as $iv) {
--- testing different key lengths

key length=8

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
string(112) "082b437d039d09418e20dc9de1dafa7ed6da5c6335b78950968441da1faf40c1f886e04da8ca177b80b376811e138c1bf51cb48dae2e7939"

key length=20

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
string(112) "0627351e0f8a082bf7981ae2c700a43fd3d44b270ac67b00fded1c5796eea935be0fef2a23da0b3f5e243929e62ac957bf0bf463aa90fc4f"

key length=24

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
string(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac"

key length=26

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): Size of key is too large for this algorithm in %s on line %d
string(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac"

--- testing different iv lengths

iv length=4

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
string(112) "440a6f54601969b127aad3c217ce7583c7f7b29989693130645569301db0020b29a34a3dcd104b2d0e3ba19d6cbd8a33d352b9c27cc34ef1"

iv length=8

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d
string(112) "bac347506bf092c5557c4363c301745d78f047028e2953e84fd66b30aeb6005812dadbe8baa871b83278341599b0c448ddaaa52b5a378ce5"

iv length=9

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
string(112) "440a6f54601969b127aad3c217ce7583c7f7b29989693130645569301db0020b29a34a3dcd104b2d0e3ba19d6cbd8a33d352b9c27cc34ef1"
===DONE===
4 changes: 4 additions & 0 deletions ext/mcrypt/tests/mcrypt_cbc_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ var_dump( mcrypt_cbc($cipher, $key, $data) );

-- Testing mcrypt_cbc() function with more than expected no. of arguments --

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc() expects at most 5 parameters, 6 given in %s on line %d
NULL

-- Testing mcrypt_cbc() function with less than expected no. of arguments --

Deprecated: Function mcrypt_cbc() is deprecated in %s on line %d

Warning: mcrypt_cbc() expects at least 4 parameters, 3 given in %s on line %d
NULL
===DONE===
Expand Down
26 changes: 26 additions & 0 deletions ext/mcrypt/tests/mcrypt_cbc_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -124,106 +124,132 @@ fclose($fp);
*** Testing mcrypt_cbc() : usage variation ***

--int 0--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--int 1--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--int 12345--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--int -12345--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--float 10.5--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--float -10.5--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--float 12.3456789000e10--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--float -12.3456789000e10--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--float .5--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--empty array--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc() expects parameter 1 to be string, array given, %s(%d)
NULL

--int indexed array--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc() expects parameter 1 to be string, array given, %s(%d)
NULL

--associative array--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc() expects parameter 1 to be string, array given, %s(%d)
NULL

--nested arrays--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc() expects parameter 1 to be string, array given, %s(%d)
NULL

--uppercase NULL--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--lowercase null--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--lowercase true--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--lowercase false--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--uppercase TRUE--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--uppercase FALSE--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--empty string DQ--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--empty string SQ--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--instance of classWithToString--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--instance of classWithoutToString--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc() expects parameter 1 to be string, object given, %s(%d)
NULL

--undefined var--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--unset var--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)

--resource--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc() expects parameter 1 to be string, resource given, %s(%d)
NULL
===DONE===
Expand Down
27 changes: 26 additions & 1 deletion ext/mcrypt/tests/mcrypt_cbc_variation2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -124,87 +124,112 @@ fclose($fp);
*** Testing mcrypt_cbc() : usage variation ***

--int 0--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "bc27b3a4e33b531d5983fc7df693cd09"

--int 1--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "bc27b3a4e33b531d5983fc7df693cd09"

--int 12345--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "d109b7973383127002474ae731c4b3a8"

--int -12345--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "3e82a931cedb03a38b91a637ff8c9f9e"

--float 10.5--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "de71833586c1d7132a289960ebeeca7a"

--float -10.5--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "7d0489dd2e99ae910ecc015573f3dd16"

--float 12.3456789000e10--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "978055b42c0506a8947e3c3c8d994baf"

--float -12.3456789000e10--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "4aa84ba400c2b8ef467d4d98372b4f4e"

--float .5--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "e731dc5059b84e0c8774ac490f77d6e6"

--empty array--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc() expects parameter 2 to be string, array given, %s(%d)
string(0) ""

--int indexed array--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc() expects parameter 2 to be string, array given, %s(%d)
string(0) ""

--associative array--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc() expects parameter 2 to be string, array given, %s(%d)
string(0) ""

--nested arrays--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc() expects parameter 2 to be string, array given, %s(%d)
string(0) ""

--uppercase NULL--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "be722a5ffc361d721fbcab1eacc6acf5"

--lowercase null--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "be722a5ffc361d721fbcab1eacc6acf5"

--lowercase true--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "bc27b3a4e33b531d5983fc7df693cd09"

--lowercase false--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "be722a5ffc361d721fbcab1eacc6acf5"

--uppercase TRUE--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "bc27b3a4e33b531d5983fc7df693cd09"

--uppercase FALSE--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "be722a5ffc361d721fbcab1eacc6acf5"

--empty string DQ--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "be722a5ffc361d721fbcab1eacc6acf5"

--empty string SQ--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "be722a5ffc361d721fbcab1eacc6acf5"

--instance of classWithToString--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "19420fa26f561ee82ed84abbcd2d284b"

--instance of classWithoutToString--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc() expects parameter 2 to be string, object given, %s(%d)
string(0) ""

--undefined var--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "be722a5ffc361d721fbcab1eacc6acf5"

--unset var--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
string(32) "be722a5ffc361d721fbcab1eacc6acf5"

--resource--
Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
Error: 2 - mcrypt_cbc() expects parameter 2 to be string, resource given, %s(%d)
string(0) ""
===DONE===

Loading

0 comments on commit 7014a0e

Please sign in to comment.