1--TEST--
2openssl_spki_new() test for creating SPKI string
3--SKIPIF--
4<?php
5if (!extension_loaded("openssl")) die("skip");
6?>
7--FILE--
8<?php
9
10/* array of private key sizes to test */
11$key_sizes = array(1024, 2048, 4096);
12$pkeys = array();
13foreach ($key_sizes as $key_size) {
14    $key_file = "file://" . dirname(__FILE__) . "/private_rsa_" . $key_size . ".key";
15    $pkeys[] = openssl_pkey_get_private($key_file);
16}
17
18
19/* array of available hashings to test */
20$algo = array(
21    OPENSSL_ALGO_MD4,
22    OPENSSL_ALGO_MD5,
23    OPENSSL_ALGO_SHA1,
24    OPENSSL_ALGO_SHA224,
25    OPENSSL_ALGO_SHA256,
26    OPENSSL_ALGO_SHA384,
27    OPENSSL_ALGO_SHA512,
28    OPENSSL_ALGO_RMD160
29);
30
31/* loop over key sizes for test */
32foreach ($pkeys as $pkey) {
33
34    /* loop to create and verify results */
35    foreach ($algo as $value) {
36        var_dump(openssl_spki_new($pkey, _uuid(), $value));
37    }
38}
39
40/* generate a random challenge */
41function _uuid() {
42    return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff),
43        mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000,
44        mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff),
45        mt_rand(0, 0xffff), mt_rand(0, 0xffff));
46}
47
48?>
49--EXPECTF--
50string(478) "%s"
51string(478) "%s"
52string(478) "%s"
53string(478) "%s"
54string(478) "%s"
55string(478) "%s"
56string(478) "%s"
57string(474) "%s"
58string(830) "%s"
59string(830) "%s"
60string(830) "%s"
61string(830) "%s"
62string(830) "%s"
63string(830) "%s"
64string(830) "%s"
65string(826) "%s"
66string(1510) "%s"
67string(1510) "%s"
68string(1510) "%s"
69string(1510) "%s"
70string(1510) "%s"
71string(1510) "%s"
72string(1510) "%s"
73string(1506) "%s"
74