File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ --TEST--
2+ Ensure hash_update_stream() always returns the same hash when $length = 0
3+ --CREDITS--
4+ Symeon Charalabides <symeon@systasis.com> - @phpdublin
5+ --SKIPIF--
6+ <?php
7+ if (!extension_loaded ('openssl ' )) die ('skip openssl extension not available ' );
8+ ?>
9+ --FILE--
10+ <?php
11+
12+ for ($ j =0 ; $ j <3 ; $ j ++)
13+ {
14+ // Create pseudo-random hash
15+ $ bytes = openssl_random_pseudo_bytes (15 , $ cstrong );
16+ $ hash = sha1 (bin2hex ($ bytes ));
17+
18+ // Create temp file with hash
19+ $ fp = tmpfile ();
20+ fwrite ($ fp , $ hash );
21+ rewind ($ fp );
22+
23+ // Stream it with 0 length and output hash
24+ $ ctx = hash_init ('md5 ' );
25+ hash_update_stream ($ ctx , $ fp , 0 );
26+ echo hash_final ($ ctx ) . "\n" ;
27+ }
28+
29+ ?>
30+ --EXPECT--
31+ d41d8cd98f00b204e9800998ecf8427e
32+ d41d8cd98f00b204e9800998ecf8427e
33+ d41d8cd98f00b204e9800998ecf8427e
You can’t perform that action at this time.
0 commit comments