1--TEST--
2openssl_pkcs7_encrypt() tests
3--SKIPIF--
4<?php if (!extension_loaded("openssl")) print "skip"; ?>
5--FILE--
6<?php
7$infile = dirname(__FILE__) . "/cert.crt";
8$outfile = tempnam(sys_get_temp_dir(), "ssl");
9if ($outfile === false)
10    die("failed to get a temporary filename!");
11$outfile2 = tempnam(sys_get_temp_dir(), "ssl");
12if ($outfile2 === false)
13    die("failed to get a temporary filename!");
14
15$single_cert = "file://" . dirname(__FILE__) . "/cert.crt";
16$privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key";
17$multi_certs = array($single_cert, $single_cert);
18$assoc_headers = array("To" => "test@test", "Subject" => "testing openssl_pkcs7_encrypt()");
19$headers = array("test@test", "testing openssl_pkcs7_encrypt()");
20$empty_headers = array();
21$wrong = "wrong";
22$empty = "";
23
24var_dump(openssl_pkcs7_encrypt($infile, $outfile, $single_cert, $headers));
25var_dump(openssl_pkcs7_encrypt($infile, $outfile, openssl_x509_read($single_cert), $headers));
26var_dump(openssl_pkcs7_decrypt($outfile, $outfile2, $single_cert, $privkey));
27var_dump(openssl_pkcs7_encrypt($infile, $outfile, $single_cert, $assoc_headers));
28var_dump(openssl_pkcs7_encrypt($infile, $outfile, $single_cert, $empty_headers));
29var_dump(openssl_pkcs7_encrypt($infile, $outfile, $single_cert, $wrong));
30var_dump(openssl_pkcs7_encrypt($wrong, $outfile, $single_cert, $headers));
31var_dump(openssl_pkcs7_encrypt($empty, $outfile, $single_cert, $headers));
32var_dump(openssl_pkcs7_encrypt($infile, $empty, $single_cert, $headers));
33var_dump(openssl_pkcs7_encrypt($infile, $outfile, $wrong, $headers));
34var_dump(openssl_pkcs7_encrypt($infile, $outfile, $empty, $headers));
35var_dump(openssl_pkcs7_encrypt($infile, $outfile, $single_cert, $empty));
36var_dump(openssl_pkcs7_encrypt($infile, $outfile, $multi_certs, $headers));
37var_dump(openssl_pkcs7_encrypt($infile, $outfile, array_map('openssl_x509_read', $multi_certs) , $headers));
38
39if (file_exists($outfile)) {
40    echo "true\n";
41    unlink($outfile);
42}
43if (file_exists($outfile2)) {
44    echo "true\n";
45    unlink($outfile2);
46}
47?>
48--EXPECTF--
49bool(true)
50bool(true)
51bool(true)
52bool(true)
53bool(true)
54
55Warning: openssl_pkcs7_encrypt() expects parameter 4 to be array, string given in %s on line %d
56bool(false)
57bool(false)
58bool(false)
59bool(false)
60bool(false)
61bool(false)
62
63Warning: openssl_pkcs7_encrypt() expects parameter 4 to be array, string given in %s on line %d
64bool(false)
65bool(true)
66bool(true)
67true
68true
69