1--TEST--
2openssl_pkey_export() with EC key
3--SKIPIF--
4<?php
5if (!extension_loaded("openssl"))
6    die("skip");
7if (!defined('OPENSSL_KEYTYPE_EC'))
8    die("skip no EC available");
9?>
10--FILE--
11<?php
12$key = openssl_pkey_get_private('file://' . __DIR__ . '/private_ec.key');
13var_dump($key);
14
15$config_arg = array("config" => __DIR__ . DIRECTORY_SEPARATOR . "openssl.cnf");
16
17var_dump(openssl_pkey_export($key, $output, NULL, $config_arg));
18echo $output;
19
20// Load the private key from the exported pem string
21$details = openssl_pkey_get_details(openssl_pkey_get_private($output));
22var_dump(OPENSSL_KEYTYPE_EC === $details['type']);
23
24// Export key with passphrase
25openssl_pkey_export($key, $output, 'passphrase', $config_arg);
26
27$details = openssl_pkey_get_details(openssl_pkey_get_private($output, 'passphrase'));
28var_dump(OPENSSL_KEYTYPE_EC === $details['type']);
29
30// Read public key
31$pKey = openssl_pkey_get_public('file://' . __DIR__ . '/public_ec.key');
32var_dump($pKey);
33// The details are the same for a public or private key, expect the private key parameter 'd
34$detailsPKey = openssl_pkey_get_details($pKey);
35var_dump(array_diff_assoc($details['ec'], $detailsPKey['ec']));
36
37// Export to file
38$tempname = tempnam(sys_get_temp_dir(), 'openssl_ec');
39var_dump(openssl_pkey_export_to_file($key, $tempname, NULL, $config_arg));
40$details = openssl_pkey_get_details(openssl_pkey_get_private('file://' . $tempname));
41var_dump(OPENSSL_KEYTYPE_EC === $details['type']);
42var_dump($key instanceof OpenSSLAsymmetricKey);
43// Clean the temporary file
44@unlink($tempname);
45?>
46--EXPECTF--
47object(OpenSSLAsymmetricKey)#%d (0) {
48}
49bool(true)
50-----BEGIN EC PRIVATE KEY-----%a-----END EC PRIVATE KEY-----
51bool(true)
52bool(true)
53object(OpenSSLAsymmetricKey)#%d (0) {
54}
55array(1) {
56  ["d"]=>
57  string(32) "%a"
58}
59bool(true)
60bool(true)
61bool(true)
62