xref: /PHP-8.3/ext/standard/tests/strings/sha1.phpt (revision f8d79582)
1--TEST--
2sha1() with ASCII output
3--FILE--
4<?php
5
6$filename = __DIR__."/sha1.dat";
7$a = array(
8    "abc",
9    "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
10    "a",
11    "0123456701234567012345670123456701234567012345670123456701234567",
12    ""
13);
14
15foreach ($a as $str) {
16    var_dump($val1 = sha1($str));
17    file_put_contents($filename, $str);
18    var_dump($val2 = sha1_file($filename));
19    var_dump($val1 === $val2);
20}
21
22var_dump(sha1($str, true));
23var_dump(sha1_file($filename, true));
24
25@unlink($filename);
26
27sha1_file($filename);
28
29echo "Done\n";
30?>
31--EXPECTF--
32string(40) "a9993e364706816aba3e25717850c26c9cd0d89d"
33string(40) "a9993e364706816aba3e25717850c26c9cd0d89d"
34bool(true)
35string(40) "84983e441c3bd26ebaae4aa1f95129e5e54670f1"
36string(40) "84983e441c3bd26ebaae4aa1f95129e5e54670f1"
37bool(true)
38string(40) "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8"
39string(40) "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8"
40bool(true)
41string(40) "e0c094e867ef46c350ef54a7f59dd60bed92ae83"
42string(40) "e0c094e867ef46c350ef54a7f59dd60bed92ae83"
43bool(true)
44string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709"
45string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709"
46bool(true)
47string(20) "%a"
48string(20) "%a"
49
50Warning: sha1_file(%ssha1.dat): Failed to open stream: No such file or directory in %s on line %d
51Done
52