1--TEST--
2Check for libsodium secretbox
3--SKIPIF--
4<?php if (!extension_loaded("sodium")) print "skip"; ?>
5--FILE--
6<?php
7$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
8$key = sodium_crypto_secretbox_keygen();
9
10$a = sodium_crypto_secretbox('test', $nonce, $key);
11$x = sodium_crypto_secretbox_open($a, $nonce, $key);
12var_dump(bin2hex($x));
13$y = sodium_crypto_secretbox_open("\0" . $a, $nonce, $key);
14var_dump($y);
15
16try {
17    sodium_crypto_secretbox('test', substr($nonce, 1), $key);
18} catch (SodiumException $ex) {
19    var_dump(true);
20}
21
22?>
23--EXPECT--
24string(8) "74657374"
25bool(false)
26bool(true)
27