1--TEST--
2openssl_pkcs12_export_to_file() tests
3--EXTENSIONS--
4openssl
5--FILE--
6<?php
7$pkcsfile = __DIR__ . "/openssl_pkcs12_export_to_file__pkcsfile.tmp";
8
9$cert_file = __DIR__ . "/public.crt";
10$cert = file_get_contents($cert_file);
11$cert_path = "file://" . $cert_file;
12$priv_file = __DIR__ . "/private.crt";
13$priv = file_get_contents($priv_file);
14$priv_path = "file://" . $priv_file;
15$cert_res = openssl_x509_read($cert);
16$priv_res = openssl_pkey_get_private($priv);
17$pass = "test";
18$invalid = "";
19$invalid_path = __DIR__ . "/invalid_path";
20$opts = [];
21
22var_dump(openssl_pkcs12_export_to_file($cert, $pkcsfile, $priv, $pass));
23var_dump(openssl_pkcs12_read(file_get_contents($pkcsfile), $opts, $pass));
24var_dump(openssl_pkcs12_export_to_file($cert_path, $pkcsfile, $priv_path, $pass));
25var_dump(openssl_pkcs12_read(file_get_contents($pkcsfile), $opts, $pass));
26var_dump(openssl_pkcs12_export_to_file($cert_res, $pkcsfile, $priv_res, $pass));
27var_dump(openssl_pkcs12_read(file_get_contents($pkcsfile), $opts, $pass));
28var_dump(openssl_pkcs12_export_to_file($cert_res, $pkcsfile, $priv_res, $pass, array('extracerts' => $cert)));
29var_dump(openssl_pkcs12_read(file_get_contents($pkcsfile), $opts, $pass));
30
31var_dump(openssl_pkcs12_export_to_file($invalid, $pkcsfile, $invalid, $pass));
32var_dump(openssl_pkcs12_export_to_file($invalid_path, $pkcsfile, $invalid_path, $pass));
33try {
34    var_dump(openssl_pkcs12_export_to_file($priv_res, $pkcsfile, $cert_res, $pass));
35} catch (TypeError $e) {
36    echo $e->getMessage(), "\n";
37}
38?>
39--CLEAN--
40<?php
41$pkcsfile = __DIR__ . "/openssl_pkcs12_export_to_file__pkcsfile.tmp";
42if (file_exists($pkcsfile)) {
43    unlink($pkcsfile);
44}
45?>
46--EXPECTF--
47bool(true)
48bool(true)
49bool(true)
50bool(true)
51bool(true)
52bool(true)
53bool(true)
54bool(true)
55
56Warning: openssl_pkcs12_export_to_file(): X.509 Certificate cannot be retrieved in %s on line %d
57bool(false)
58
59Warning: openssl_pkcs12_export_to_file(): X.509 Certificate cannot be retrieved in %s on line %d
60bool(false)
61openssl_pkcs12_export_to_file(): Argument #1 ($certificate) must be of type OpenSSLCertificate|string, OpenSSLAsymmetricKey given
62