Hi,

I attached patches for md5.c and sha1.c. They add an optional second
param to md5() and sha1(), if this param is set to true then the binary
value is returned and no bin2hex() is performed.
In some cases this can be useful.
Is there any chance to commit this?

bye,
--
------------------------------- -------------------------------------
Michael Bretterklieber        - [EMAIL PROTECTED]
JAWA Management Software GmbH - http://www.jawa.at
Liebenauer Hauptstr. 200        -------------- privat ---------------
A-8041 GRAZ                     GSM: ++43-(0)676-93 96 698
Tel: ++43-(0)316-403274-12      E-mail:   [EMAIL PROTECTED]
Fax: ++43-(0)316-403274-10      http://www.bretterklieber.com
------------------------------- -------------------------------------
"...the number of UNIX installations has grown to 10, with more
expected..." - Dennis Ritchie and Ken Thompson, June 1972

Index: md5.c
===================================================================
RCS file: /repository/php4/ext/standard/md5.c,v
retrieving revision 1.28
diff -u -u -r1.28 md5.c
--- md5.c       24 Aug 2002 01:19:28 -0000      1.28
+++ md5.c       18 Feb 2003 18:56:55 -0000
@@ -44,22 +44,35 @@
    Calculate the md5 hash of a string */
 PHP_NAMED_FUNCTION(php_if_md5)
 {
-       zval **arg;
+       zval **arg, **noBin2Hex;
        char md5str[33];
        PHP_MD5_CTX context;
        unsigned char digest[16];
+       int argc = ZEND_NUM_ARGS();
+       short bin;
        
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
+       if (argc < 1 || argc > 2  || zend_get_parameters_ex(argc, &arg, &noBin2Hex) == 
+FAILURE) {
                WRONG_PARAM_COUNT;
        }
        convert_to_string_ex(arg);
-
+       if (argc > 1) {
+               convert_to_boolean_ex(noBin2Hex);
+               bin = Z_BVAL_PP(noBin2Hex);
+       } else {
+               bin = 0;
+       }
+       
        md5str[0] = '\0';
        PHP_MD5Init(&context);
        PHP_MD5Update(&context, Z_STRVAL_PP(arg), Z_STRLEN_PP(arg));
        PHP_MD5Final(digest, &context);
-       make_digest(md5str, digest);
-       RETVAL_STRING(md5str, 1);
+       if (bin) {
+               RETURN_STRINGL(digest, sizeof digest, 1);
+       } else {
+               make_digest(md5str, digest);
+               RETVAL_STRING(md5str, 1);
+       }
+
 }
 /* }}} */
 
Index: sha1.c
===================================================================
RCS file: /repository/php4/ext/standard/sha1.c,v
retrieving revision 1.3
diff -u -u -r1.3 sha1.c
--- sha1.c      24 Aug 2002 01:19:28 -0000      1.3
+++ sha1.c      18 Feb 2003 18:57:06 -0000
@@ -41,22 +41,36 @@
    Calculate the sha1 hash of a string */
 PHP_FUNCTION(sha1)
 {
-       zval **arg;
+       zval **arg, **noBin2Hex;
        char sha1str[41];
        PHP_SHA1_CTX context;
        unsigned char digest[20];
+       int argc = ZEND_NUM_ARGS();
+       short bin;
        
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
+       if (argc < 1 || argc > 2  || zend_get_parameters_ex(argc, &arg, &noBin2Hex) == 
+FAILURE) {
                WRONG_PARAM_COUNT;
        }
        convert_to_string_ex(arg);
+       if (argc > 1) {
+               convert_to_boolean_ex(noBin2Hex);
+               bin = Z_BVAL_PP(noBin2Hex);
+       } else {
+               bin = 0;
+       }
 
        sha1str[0] = '\0';
        PHP_SHA1Init(&context);
        PHP_SHA1Update(&context, Z_STRVAL_PP(arg), Z_STRLEN_PP(arg));
        PHP_SHA1Final(digest, &context);
        make_sha1_digest(sha1str, digest);
-       RETVAL_STRING(sha1str, 1);
+       if (bin) {
+               RETURN_STRINGL(digest, sizeof digest, 1);
+       } else {
+               make_sha1_digest(sha1str, digest);
+               RETVAL_STRING(sha1str, 1);
+       }
+
 }
 
 /* }}} */


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to