From: Derick Rethans Date: Thu, 20 Feb 2003 10:32:35 +0000 (+0000) Subject: - Also add the optional raw output parameter to md5_file and sha1_file. X-Git-Tag: RELEASE_0_5~848 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b4b33b11ef09addd53e554c0f0df195cc5166bed;p=php - Also add the optional raw output parameter to md5_file and sha1_file. --- diff --git a/NEWS b/NEWS index 1ecb7e78a5..7c56744ca1 100644 --- a/NEWS +++ b/NEWS @@ -20,8 +20,9 @@ PHP 4 NEWS - Added lightweight streaming input abstraction to the Zend Engine scanners that provides uniform support for include()'ing data from PHP streams across all platforms (Wez, Zend Engine). -- Added optional parameter to sha1() and md5() which makes them return - the digest as binary data. (Michael Bretterklieber , Derick) +- Added optional parameter to sha1(), sha1_file(), md5() and md5_file() which + makes them return the digest as binary data. (Michael Bretterklieber + , Derick) - Added proc_nice() function. Changes priority of the current process. (Ilia) - Added pcntl_getpriority() and pcntl_setpriority() functions. (Ilia) - Added idate(), date_sunrise() and date_sunset() functions. (Moshe Doron) diff --git a/ext/standard/md5.c b/ext/standard/md5.c index 1bde1f6809..78f8c3141b 100644 --- a/ext/standard/md5.c +++ b/ext/standard/md5.c @@ -69,11 +69,13 @@ PHP_NAMED_FUNCTION(php_if_md5) } /* }}} */ -/* {{{ proto string md5_file(string filename) +/* {{{ proto string md5_file(string filename [, bool raw_output]) Calculate the md5 hash of given filename */ PHP_NAMED_FUNCTION(php_if_md5_file) { - zval **arg; + char *arg; + int arg_len; + zend_bool raw_output = 0; char md5str[33]; unsigned char buf[1024]; unsigned char digest[16]; @@ -81,21 +83,19 @@ PHP_NAMED_FUNCTION(php_if_md5_file) int n; FILE *fp; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) { + return; } - convert_to_string_ex(arg); - - if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(arg), NULL, CHECKUID_CHECK_FILE_AND_DIR))) { + if (PG(safe_mode) && (!php_checkuid(arg, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { RETURN_FALSE; } - if (php_check_open_basedir(Z_STRVAL_PP(arg) TSRMLS_CC)) { + if (php_check_open_basedir(arg TSRMLS_CC)) { RETURN_FALSE; } - if ((fp = VCWD_FOPEN(Z_STRVAL_PP(arg), "rb")) == NULL) { + if ((fp = VCWD_FOPEN(arg, "rb")) == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open file"); RETURN_FALSE; } @@ -115,9 +115,12 @@ PHP_NAMED_FUNCTION(php_if_md5_file) fclose(fp); - make_digest(md5str, digest); - - RETVAL_STRING(md5str, 1); + if (raw_output) { + RETURN_STRINGL(digest, 20, 1); + } else { + make_digest(md5str, digest); + RETVAL_STRING(md5str, 1); + } } /* }}} */ diff --git a/ext/standard/sha1.c b/ext/standard/sha1.c index 77b3fbb4f9..38027f247f 100644 --- a/ext/standard/sha1.c +++ b/ext/standard/sha1.c @@ -67,11 +67,13 @@ PHP_FUNCTION(sha1) /* }}} */ -/* {{{ proto string sha1_file(string filename) +/* {{{ proto string sha1_file(string filename [, bool raw_output]) Calculate the sha1 hash of given filename */ PHP_FUNCTION(sha1_file) { - zval **arg; + char *arg; + int arg_len; + zend_bool raw_output = 0; char sha1str[41]; unsigned char buf[1024]; unsigned char digest[20]; @@ -79,21 +81,19 @@ PHP_FUNCTION(sha1_file) int n; FILE *fp; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) { + return; } - convert_to_string_ex(arg); - - if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(arg), NULL, CHECKUID_CHECK_FILE_AND_DIR))) { + if (PG(safe_mode) && (!php_checkuid(arg, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { RETURN_FALSE; } - if (php_check_open_basedir(Z_STRVAL_PP(arg) TSRMLS_CC)) { + if (php_check_open_basedir(arg TSRMLS_CC)) { RETURN_FALSE; } - if ((fp = VCWD_FOPEN(Z_STRVAL_PP(arg), "rb")) == NULL) { + if ((fp = VCWD_FOPEN(arg, "rb")) == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open file"); RETURN_FALSE; } @@ -113,9 +113,12 @@ PHP_FUNCTION(sha1_file) fclose(fp); - make_sha1_digest(sha1str, digest); - - RETVAL_STRING(sha1str, 1); + if (raw_output) { + RETURN_STRINGL(digest, 20, 1); + } else { + make_sha1_digest(sha1str, digest); + RETVAL_STRING(sha1str, 1); + } } /* }}} */