1--TEST--
2openssl_x509_read() tests
3--SKIPIF--
4<?php if (!extension_loaded("openssl")) print "skip"; ?>
5--FILE--
6<?php
7$fp = fopen(__DIR__ . "/cert.crt","r");
8$a = fread($fp,8192);
9fclose($fp);
10
11$b = "file://" . __DIR__ . "/cert.crt";
12$c = "invalid cert";
13$d = openssl_x509_read($a);
14$e = array();
15$f = array($b);
16
17var_dump(openssl_x509_read($a)); // read cert as a string
18var_dump(openssl_x509_read($b)); // read cert as a filename string
19var_dump(openssl_x509_read($c)); // read an invalid cert, fails
20var_dump(openssl_x509_read($d)); // read cert from a resource
21
22try {
23    openssl_x509_read($e); // read an array
24} catch (TypeError $exception) {
25    echo $exception->getMessage() . "\n";
26}
27
28try {
29    openssl_x509_read($f); // read an array with the filename
30} catch (TypeError $exception) {
31    echo $exception->getMessage() . "\n";
32}
33
34?>
35--EXPECTF--
36object(OpenSSLCertificate)#%d (0) {
37}
38object(OpenSSLCertificate)#%d (0) {
39}
40
41Warning: openssl_x509_read(): X.509 Certificate cannot be retrieved in %s on line %d
42bool(false)
43object(OpenSSLCertificate)#%d (0) {
44}
45openssl_x509_read(): Argument #1 ($certificate) must be of type OpenSSLCertificate|string, array given
46openssl_x509_read(): Argument #1 ($certificate) must be of type OpenSSLCertificate|string, array given
47