]> granicus.if.org Git - php/commitdiff
PHP6 Updates
authorSara Golemon <pollita@php.net>
Wed, 20 Sep 2006 00:32:54 +0000 (00:32 +0000)
committerSara Golemon <pollita@php.net>
Wed, 20 Sep 2006 00:32:54 +0000 (00:32 +0000)
18 files changed:
ext/hash/hash.c
ext/hash/tests/adler32.phpt
ext/hash/tests/crc32.phpt
ext/hash/tests/gost.phpt
ext/hash/tests/haval.phpt
ext/hash/tests/hmac-md5.phpt
ext/hash/tests/md2.phpt
ext/hash/tests/md4.phpt
ext/hash/tests/md5.phpt
ext/hash/tests/ripemd128.phpt
ext/hash/tests/ripemd160.phpt
ext/hash/tests/sha1.phpt
ext/hash/tests/sha256.phpt
ext/hash/tests/sha384.phpt
ext/hash/tests/sha512.phpt
ext/hash/tests/snefru.phpt
ext/hash/tests/tiger.phpt
ext/hash/tests/whirlpool.phpt

index 6fed80051c0271bb6da59a89b782c09ec6e964bc..bb3771a019a51f91b439ce08d229729383a7d50b 100644 (file)
@@ -67,22 +67,49 @@ static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename)
 {
        char *algo, *data, *digest;
        int algo_len, data_len;
+       zend_uchar data_type = IS_STRING;
        zend_bool raw_output = 0;
        php_hash_ops *ops;
        void *context;
        php_stream *stream = NULL;
 
+#if PHP_MAJOR_VERSION >= 6
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "st|b", &algo, &algo_len, &data, &data_len, &data_type, &raw_output) == FAILURE) {
+               return;
+       }
+
+       if (data_type == IS_UNICODE) {
+               if (isfilename) {
+                       if (php_stream_path_encode(NULL, &data, &data_len, (UChar *)data, data_len, REPORT_ERRORS, FG(default_context)) == FAILURE) {
+                               RETURN_FALSE;
+                       }
+               } else {
+                       /* Unicode string passed for raw hashing */
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unicode strings can not be hashed.  Convert to a binary type.");
+                       RETURN_FALSE;
+               }
+       }
+#else
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &algo, &algo_len, &data, &data_len, &raw_output) == FAILURE) {
                return;
        }
+#endif
 
        ops = php_hash_fetch_ops(algo, algo_len);
        if (!ops) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown hashing algorithm: %s", algo);
+               if (data_type != IS_STRING) {
+                       /* Original filename was UNICODE, this string is a converted copy */
+                       efree(data);
+               }
                RETURN_FALSE;
        }
        if (isfilename) {
                stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, DEFAULT_CONTEXT);
+               if (data_type != IS_STRING) {
+                       /* Original filename was UNICODE, this string is a converted copy */
+                       efree(data);
+               }
                if (!stream) {
                        /* Stream will report errors opening file */
                        RETURN_FALSE;
@@ -121,7 +148,7 @@ static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename)
        }
 }
 
-/* {{{ proto string hash(string algo, string data[, bool raw_output = false])
+/* {{{ proto string hash(string algo, string data[, bool raw_output = false]) U
 Generate a hash of a given input string
 Returns lowercase hexits by default */
 PHP_FUNCTION(hash) {
@@ -129,7 +156,7 @@ PHP_FUNCTION(hash) {
 }
 /* }}} */
 
-/* {{{ proto string hash_file(string algo, string filename[, bool raw_output = false])
+/* {{{ proto string hash_file(string algo, string filename[, bool raw_output = false]) U
 Generate a hash of a given file
 Returns lowercase hexits by default */
 PHP_FUNCTION(hash_file) {
@@ -141,23 +168,49 @@ static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename)
 {
        char *algo, *data, *digest, *key, *K;
        int algo_len, data_len, key_len, i;
+       zend_uchar data_type = IS_STRING;
        zend_bool raw_output = 0;
        php_hash_ops *ops;
        void *context;
        php_stream *stream = NULL;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|b", &algo, &algo_len, &data, &data_len, 
-                                                                                                                                 &key, &key_len, &raw_output) == FAILURE) {
+#if PHP_MAJOR_VERSION >= 6
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "stS|b", &algo, &algo_len, &data, &data_len, &data_type, &key, &key_len, &raw_output) == FAILURE) {
+               return;
+       }
+
+       if (data_type == IS_UNICODE) {
+               if (isfilename) {
+                       if (php_stream_path_encode(NULL, &data, &data_len, (UChar *)data, data_len, REPORT_ERRORS, FG(default_context)) == FAILURE) {
+                               RETURN_FALSE;
+                       }
+               } else {
+                       /* Unicode string passed for raw hashing */
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unicode strings can not be hashed.  Convert to a binary type.");
+                       RETURN_FALSE;
+               }
+       }
+#else
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|b", &algo, &algo_len, &data, &data_len, &key, &key_len, &raw_output) == FAILURE) {
                return;
        }
+#endif
 
        ops = php_hash_fetch_ops(algo, algo_len);
        if (!ops) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown hashing algorithm: %s", algo);
+               if (data_type != IS_STRING) {
+                       /* Original filename was UNICODE, this string is a converted copy */
+                       efree(data);
+               }
                RETURN_FALSE;
        }
        if (isfilename) {
                stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, DEFAULT_CONTEXT);
+               if (data_type != IS_STRING) {
+                       /* Original filename was UNICODE, this string is a converted copy */
+                       efree(data);
+               }
                if (!stream) {
                        /* Stream will report errors opening file */
                        RETURN_FALSE;
@@ -230,7 +283,7 @@ static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename)
        }
 }
 
-/* {{{ proto string hash_hmac(string algo, string data, string key[, bool raw_output = false])
+/* {{{ proto string hash_hmac(string algo, string data, string key[, bool raw_output = false]) U
 Generate a hash of a given input string with a key using HMAC
 Returns lowercase hexits by default */
 PHP_FUNCTION(hash_hmac) {
@@ -238,7 +291,7 @@ PHP_FUNCTION(hash_hmac) {
 }
 /* }}} */
 
-/* {{{ proto string hash_hmac_file(string algo, string filename, string key[, bool raw_output = false])
+/* {{{ proto string hash_hmac_file(string algo, string filename, string key[, bool raw_output = false]) U
 Generate a hash of a given file with a key using HMAC
 Returns lowercase hexits by default */
 PHP_FUNCTION(hash_hmac_file) {
@@ -247,7 +300,7 @@ PHP_FUNCTION(hash_hmac_file) {
 /* }}} */
 
 
-/* {{{ proto resource hash_init(string algo[, int options, string key])
+/* {{{ proto resource hash_init(string algo[, int options, string key]) U
 Initialize a hashing context */
 PHP_FUNCTION(hash_init)
 {
@@ -312,7 +365,13 @@ PHP_FUNCTION(hash_init)
 }
 /* }}} */
 
-/* {{{ proto bool hash_update(resource context, string data)
+#if PHP_MAJOR_VERSION >= 6
+# define PHP_HASH_UPDATE_ARGS "rS"
+#else
+# define PHP_HASH_UPDATE_ARGS "rs"
+#endif
+
+/* {{{ proto bool hash_update(resource context, string data) U
 Pump data into the hashing algorithm */
 PHP_FUNCTION(hash_update)
 {
@@ -321,7 +380,7 @@ PHP_FUNCTION(hash_update)
        char *data;
        int data_len;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &zhash, &data, &data_len) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, PHP_HASH_UPDATE_ARGS, &zhash, &data, &data_len) == FAILURE) {
                return;
        }
 
@@ -333,7 +392,7 @@ PHP_FUNCTION(hash_update)
 }
 /* }}} */
 
-/* {{{ proto int hash_update_stream(resource context, resource handle[, integer length])
+/* {{{ proto int hash_update_stream(resource context, resource handle[, integer length]) U
 Pump data into the hashing algorithm from an open stream */
 PHP_FUNCTION(hash_update_stream)
 {
@@ -370,7 +429,7 @@ PHP_FUNCTION(hash_update_stream)
 }
 /* }}} */
 
-/* {{{ proto bool hash_update_file(resource context, string filename[, resource context])
+/* {{{ proto bool hash_update_file(resource context, string filename[, resource context]) U
 Pump data into the hashing algorithm from a file */
 PHP_FUNCTION(hash_update_file)
 {
@@ -380,15 +439,35 @@ PHP_FUNCTION(hash_update_file)
        php_stream *stream;
        char *filename, buf[1024];
        int filename_len, n;
+       zend_uchar filename_type = IS_STRING;
+
+#if PHP_MAJOR_VERSION >= 6
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rt|r", &zhash, &filename, &filename_len, &filename_type, &zcontext) == FAILURE) {
+               return;
+       }
+
+       context = php_stream_context_from_zval(zcontext, 0);
 
+       if (filename_type == IS_UNICODE) {
+               if (php_stream_path_encode(NULL, &filename, &filename_len, (UChar *)filename, filename_len, REPORT_ERRORS, context) == FAILURE) {
+                       RETURN_FALSE;
+               }
+       }
+#else
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|r", &zhash, &filename, &filename_len, &zcontext) == FAILURE) {
                return;
        }
 
-       ZEND_FETCH_RESOURCE(hash, php_hash_data*, &zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
        context = php_stream_context_from_zval(zcontext, 0);
+#endif
+
+       ZEND_FETCH_RESOURCE(hash, php_hash_data*, &zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
 
        stream = php_stream_open_wrapper_ex(filename, "rb", REPORT_ERRORS, NULL, context);
+       if (filename_type != IS_STRING) {
+               /* Original filename was UNICODE, this string is a converted copy */
+               efree(filename);
+       }
        if (!stream) {
                /* Stream will report errors opening file */
                RETURN_FALSE;
@@ -403,7 +482,7 @@ PHP_FUNCTION(hash_update_file)
 }
 /* }}} */
 
-/* {{{ proto string hash_final(resource context[, bool raw_output=false])
+/* {{{ proto string hash_final(resource context[, bool raw_output=false]) U
 Output resulting digest */
 PHP_FUNCTION(hash_final)
 {
@@ -467,7 +546,7 @@ PHP_FUNCTION(hash_final)
 }
 /* }}} */
 
-/* {{{ proto array hash_algos(void)
+/* {{{ proto array hash_algos(void) U
 Return a list of registered hashing algorithms */
 PHP_FUNCTION(hash_algos)
 {
index acfcc2b278dd7d1f618dbd88c5e8b1d8641db8f5..91dffd2bb46321d6bb86bd36090851650235da5e 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 ADLER32
 --SKIPIF--
-<?php extension_loaded('hash') or die('skip'); ?>
+<?php if (!extension_loaded('hash') || ini_get('unicode.semantics')) die('skip'); ?>
 --FILE--
 <?php
 echo hash('adler32', ''), "\n";
index c51209c60da6cec74fb004237acecc9b8a087219..886286e8e68175c1fd31ab6b79728c27e617e0b9 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 CRC32
 --SKIPIF--
-<?php extension_loaded('hash') or die('skip'); ?>
+<?php if (!extension_loaded('hash') || ini_get('unicode.semantics')) die('skip'); ?>
 --FILE--
 <?php
 echo hash('crc32', ''), "\n";
index b800e112e85c32350cc53c96081e37234cea679a..a12e662409dcc3ac61f23ad64d040252ab186a37 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 gost
 --SKIPIF--
-<?php extension_loaded('hash') or die('skip'); ?>
+<?php if (!extension_loaded('hash') || ini_get('unicode.semantics')) die('skip'); ?>
 --FILE--
 <?php
 echo hash('gost', ''), "\n";
index 16db2fa6949afdbb8924c83b5707395e49fab60c..d1e8ebc2afbd262a33df7824e47f004ec36d41d8 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 haval algorithm (multi-vector, multi-pass, multi-width)
 --SKIPIF--
-<?php if(!extension_loaded("hash")) print "skip"; ?>
+<?php if(!extension_loaded("hash") || ini_get('unicode.semantics')) print "skip"; ?>
 --FILE--
 <?php
 echo "Empty String\n";
index 283285a54420f079eedb3689e93522c3f2b95469..d1b4d99c06e4b3af8c565423f0faaf18ff5dc84c 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 hmac-md5 algorithm
 --SKIPIF--
-<?php if(!extension_loaded("hash")) print "skip"; ?>
+<?php if(!extension_loaded("hash") || ini_get('unicode.semantics')) print "skip"; ?>
 --FILE--
 <?php
 /* Test Vectors from RFC 2104 */
index c98ad34054e1030f5874efb6c6288fbde226f093..4ccbfbd2c40dc4b3e3e56d256ae9f3d056305194 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 md2 algorithm
 --SKIPIF--
-<?php if(!extension_loaded("hash")) print "skip"; ?>
+<?php if(!extension_loaded("hash") || ini_get('unicode.semantics')) print "skip"; ?>
 --FILE--
 <?php
 echo hash('md2', '') . "\n";
index 8d90429076d90acdca3380856e78b7e78b125d95..362fdc0771a1cc745a152e7d63c064fac0b7c08a 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 md4 algorithm
 --SKIPIF--
-<?php if(!extension_loaded("hash")) print "skip"; ?>
+<?php if(!extension_loaded("hash") || ini_get('unicode.semantics')) print "skip"; ?>
 --FILE--
 <?php
 /* RFC 1320 vectors */
index d56f0b91a0f76cd92f1f10e4b4a48fab33c5e3ad..a0e205d73e47b457949a301d0396fbadd70aeb6b 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 md5 algorithm
 --SKIPIF--
-<?php if(!extension_loaded("hash")) print "skip"; ?>
+<?php if(!extension_loaded("hash") || ini_get('unicode.semantics')) print "skip"; ?>
 --FILE--
 <?php
 echo hash('md5', '') . "\n";
index e7473e316cab264b2b7673fa3719511f826b52a4..4c10baf805005cf3205f712a6e77f3932310bff6 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 ripemd128 algorithm
 --SKIPIF--
-<?php if(!extension_loaded("hash")) print "skip"; ?>
+<?php if(!extension_loaded("hash") || ini_get('unicode.semantics')) print "skip"; ?>
 --FILE--
 <?php
 echo hash('ripemd128', '') . "\n";
index 8fe7b05296a64f5d567fcd9f75ca40cfd1474806..04d5bb9f6cf54aea4f30f266c02ba8c9454f713b 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 ripemd160 algorithm
 --SKIPIF--
-<?php if(!extension_loaded("hash")) print "skip"; ?>
+<?php if(!extension_loaded("hash") || ini_get('unicode.semantics')) print "skip"; ?>
 --FILE--
 <?php
 echo hash('ripemd160', '') . "\n";
index b19378165331b860c99b5235845716ed1af40649..4e98a57ebcccdc158ac81292ee100a535e8698e7 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 sha1 algorithm
 --SKIPIF--
-<?php if(!extension_loaded("hash")) print "skip"; ?>
+<?php if(!extension_loaded("hash") || ini_get('unicode.semantics')) print "skip"; ?>
 --FILE--
 <?php
 echo hash('sha1', '') . "\n";
index 04b1c11abd314b0e67dd15757953a4beeff2e0ce..bfeec455a9ddb94df45b47ec45d3124d0b49a98b 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 sha256 algorithm
 --SKIPIF--
-<?php if(!extension_loaded("hash")) print "skip"; ?>
+<?php if(!extension_loaded("hash") || ini_get('unicode.semantics')) print "skip"; ?>
 --FILE--
 <?php
 echo hash('sha256', '') . "\n";
index e5be2ab2747f56fa71f5d0ece5bbce33eadb60a0..739dcb6b69af94093b33a5bec98df2e031570944 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 sha384 algorithm
 --SKIPIF--
-<?php if(!extension_loaded("hash")) print "skip"; ?>
+<?php if(!extension_loaded("hash") || ini_get('unicode.semantics')) print "skip"; ?>
 --FILE--
 <?php
 echo hash('sha384', '') . "\n";
index 93fbb20d635a4751fac8b657641366392e7ad159..e5959699998235aa436afa21398630030ac96a6e 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 sha512 algorithm
 --SKIPIF--
-<?php if(!extension_loaded("hash")) print "skip"; ?>
+<?php if(!extension_loaded("hash") || ini_get('unicode.semantics')) print "skip"; ?>
 --FILE--
 <?php
 echo hash('sha512', '') . "\n";
index 1b0dfa70fe1540b323217a6745fcf542d2b00bbd..daf177020018050b3619d617ab5282867249ec7f 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 snefru
 --SKIPIF--
-<?php extension_loaded('hash') or die('skip'); ?>
+<?php if (!extension_loaded('hash') || ini_get('unicode.semantics')) die('skip'); ?>
 --FILE--
 <?php
 echo hash('snefru', ''), "\n";
index ee3f249bf12c8e86095a8fe7e5ebeeba981cfc1c..b24ebef04810293727f37fc8ee80d7758e90b054 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 tiger
 --SKIPIF--
-<?php extension_loaded('hash') or die('skip'); ?>
+<?php if (!extension_loaded('hash') || ini_get('unicode.semantics')) die('skip'); ?>
 --FILE--
 <?php
 echo hash('tiger192,3', ''),"\n";
index 5f9dd164debb6b0c2bbd8070a7b3ecdb7f1e89f8..83eb01a9542229b015055e65bf07d5ae44abc95e 100644 (file)
@@ -1,7 +1,7 @@
 --TEST--
 whirlpool
 --SKIPIF--
-<?php extension_loaded('hash') or die('skip'); ?>
+<?php if (!extension_loaded('hash') || ini_get('unicode.semantics')) die('skip'); ?>
 --FILE--
 <?php
 echo hash('whirlpool', ''), "\n";