forked from mattbasta/itsdangerous-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
46 lines (34 loc) · 765 Bytes
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
require("itsdangerous.php");
define("NL", (php_sapi_name() == 'cli') ? "\n" : "<br />");
$s = new Signer("secret");
$foo = $s->sign("hello");
echo $foo, NL;
$bar = $s->unsign($foo);
echo $bar, NL;
$ts = new TimestampSigner("another_secret");
$foo2 = $ts->sign("haldo");
echo $foo2, NL;
$bar2 = $ts->unsign($foo2);
echo $bar2, NL;
sleep(2);
echo $ts->validate($foo2), NL;
echo $ts->validate($foo2, 0), NL;
$complex = array(
"foo",
123,
array(1.1, 2.2, "3.3")
);
$ser = new Serializer("asecret");
$c = $ser->dumps($complex);
echo $c, NL;
$cp = $ser->loads($c);
var_dump($cp);
echo NL;
$s2 = new Serializer("whatevs");
try {
echo $s2->loads($c), NL;
echo "FAILED", NL;
} catch (Exception $e){
echo $e->getMessage(), NL, NL;
}