xref: /PHP-8.0/ext/hash/tests/hash_hmac_error.phpt (revision b5c7a83d)
1--TEST--
2Hash: hash_hmac() function : basic functionality
3--FILE--
4<?php
5/*
6* Function is implemented in ext/hash/hash.c
7*/
8
9echo "*** Testing hash_hmac() : error conditions ***\n";
10
11$data = "This is a sample string used to test the hash_hmac function with various hashing algorithms";
12$key = 'secret';
13
14echo "\n-- Testing hash_hmac() function with invalid hash algorithm --\n";
15try {
16    var_dump(hash_hmac('foo', $data, $key));
17}
18catch (\Error $e) {
19    echo $e->getMessage() . "\n";
20}
21
22echo "\n-- Testing hash_hmac() function with non-cryptographic hash algorithm --\n";
23try {
24    var_dump(hash_hmac('crc32', $data, $key));
25}
26catch (\Error $e) {
27    echo $e->getMessage() . "\n";
28}
29
30?>
31--EXPECT--
32*** Testing hash_hmac() : error conditions ***
33
34-- Testing hash_hmac() function with invalid hash algorithm --
35hash_hmac(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm
36
37-- Testing hash_hmac() function with non-cryptographic hash algorithm --
38hash_hmac(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm
39