com php-src: Add hash_hmac_algos() for filtered i s_crypto methods: ext/hash/hash.c ext/hash/tests/ha sh_hmac_algos.phpt

From: Date: Sun, 23 Jul 2017 19:17:09 +0000
Subject: com php-src: Add hash_hmac_algos() for filtered i s_crypto methods: ext/hash/hash.c ext/hash/tests/ha sh_hmac_algos.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-98760@lists.php.net to get a copy of this message
Commit: a6e4a713ea594137a100afd2c764aff1e21e5a58 Author: Sara Golemon <pollita@php.net> Sun, 23 Jul 2017 15:14:31 -0400 Parents: 706f0cf8a0a00bc024ff52dc3528c68dab90658b Branches: PHP-7.2 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a6e4a713ea594137a100afd2c764aff1e21e5a58 Log: Add hash_hmac_algos() for filtered is_crypto methods Changed paths: M ext/hash/hash.c A ext/hash/tests/hash_hmac_algos.phpt Diff: diff --git a/ext/hash/hash.c b/ext/hash/hash.c index e2e478f..5932ad9 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -597,6 +597,22 @@ PHP_FUNCTION(hash_algos) } /* }}} */ +/* {{{ proto array hash_hmac_algos(void) +Return a list of registered hashing algorithms suitable for hash_hmac() */ +PHP_FUNCTION(hash_hmac_algos) +{ + zend_string *str; + const php_hash_ops *ops; + + array_init(return_value); + ZEND_HASH_FOREACH_STR_KEY_PTR(&php_hash_hashtable, str, ops) { + if (ops->is_crypto) { + add_next_index_str(return_value, zend_string_copy(str)); + } + } ZEND_HASH_FOREACH_END(); +} +/* }}} */ + /* {{{ proto string hash_hkdf(string algo, string ikm [, int length = 0, string info = '', string salt = '']) RFC5869 HMAC-based key derivation function */ PHP_FUNCTION(hash_hkdf) @@ -1429,6 +1445,7 @@ const zend_function_entry hash_functions[] = { PHP_FE(hash_copy, arginfo_hash_copy) PHP_FE(hash_algos, arginfo_hash_algos) + PHP_FE(hash_hmac_algos, arginfo_hash_algos) PHP_FE(hash_pbkdf2, arginfo_hash_pbkdf2) PHP_FE(hash_equals, arginfo_hash_equals) PHP_FE(hash_hkdf, arginfo_hash_hkdf) diff --git a/ext/hash/tests/hash_hmac_algos.phpt b/ext/hash/tests/hash_hmac_algos..phpt new file mode 100644 index 0000000..89877b7 --- /dev/null +++ b/ext/hash/tests/hash_hmac_algos.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test hash_hmac_algos() function : basic functionality +--SKIPIF-- +<?php extension_loaded('hash') or die('skip: hash extension not loaded.'); ?> +--FILE-- +<?php + +print_r(hash_hmac_algos()); + +--EXPECTF-- +Array +( + [%d] => md2 + [%d] => md4 + [%d] => md5 + [%d] => sha1 + [%d] => sha224 + [%d] => sha256 + [%d] => sha384 + [%d] => sha512/224 + [%d] => sha512/256 + [%d] => sha512 + [%d] => sha3-224 + [%d] => sha3-256 + [%d] => sha3-384 + [%d] => sha3-512 + [%d] => ripemd128 + [%d] => ripemd160 + [%d] => ripemd256 + [%d] => ripemd320 + [%d] => whirlpool + [%d] => tiger128,3 + [%d] => tiger160,3 + [%d] => tiger192,3 + [%d] => tiger128,4 + [%d] => tiger160,4 + [%d] => tiger192,4 + [%d] => snefru + [%d] => snefru256 + [%d] => gost + [%d] => gost-crypto + [%d] => haval128,3 + [%d] => haval160,3 + [%d] => haval192,3 + [%d] => haval224,3 + [%d] => haval256,3 + [%d] => haval128,4 + [%d] => haval160,4 + [%d] => haval192,4 + [%d] => haval224,4 + [%d] => haval256,4 + [%d] => haval128,5 + [%d] => haval160,5 + [%d] => haval192,5 + [%d] => haval224,5 + [%d] => haval256,5 +)

« previous php.cvs (#98760) next »