1--TEST-- 2openssl_cms_encrypt() tests 3--SKIPIF-- 4<?php if (!extension_loaded("openssl")) print "skip"; ?> 5--FILE-- 6<?php 7$infile = __DIR__ . "/plain.txt"; 8$outfile = tempnam(sys_get_temp_dir(), "cms_enc_basic"); 9if ($outfile === false) 10 die("failed to get a temporary filename!"); 11$outfile2 = $outfile . ".out"; 12$single_cert = "file://" . __DIR__ . "/cert.crt"; 13$privkey = "file://" . __DIR__ . "/private_rsa_1024.key"; 14$wrongkey = "file://" . __DIR__ . "/private_rsa_2048.key"; 15$multi_certs = array($single_cert, $single_cert); 16$assoc_headers = array("To" => "test@test", "Subject" => "testing openssl_cms_encrypt()"); 17$headers = array("test@test", "testing openssl_cms_encrypt()"); 18$empty_headers = array(); 19$wrong = "wrong"; 20$empty = ""; 21 22var_dump(openssl_cms_encrypt($infile, $outfile, $single_cert, $headers)); 23var_dump(openssl_cms_encrypt($infile, $outfile, openssl_x509_read($single_cert), $headers)); 24var_dump(openssl_cms_decrypt($outfile, $outfile2, $single_cert, $privkey)); 25readfile($outfile2); 26var_dump(openssl_cms_encrypt($infile, $outfile, $single_cert, $assoc_headers)); 27var_dump(openssl_cms_encrypt($infile, $outfile, $single_cert, $empty_headers)); 28var_dump(openssl_cms_encrypt($wrong, $outfile, $single_cert, $headers)); 29var_dump(openssl_cms_encrypt($empty, $outfile, $single_cert, $headers)); 30var_dump(openssl_cms_encrypt($infile, $empty, $single_cert, $headers)); 31var_dump(openssl_cms_encrypt($infile, $outfile, $wrong, $headers)); 32var_dump(openssl_cms_encrypt($infile, $outfile, $empty, $headers)); 33var_dump(openssl_cms_encrypt($infile, $outfile, $multi_certs, $headers)); 34var_dump(openssl_cms_encrypt($infile, $outfile, array_map('openssl_x509_read', $multi_certs) , $headers)); 35 36if (file_exists($outfile)) { 37 echo "true\n"; 38 unlink($outfile); 39} 40if (file_exists($outfile2)) { 41 echo "true\n"; 42 unlink($outfile2); 43} 44?> 45--EXPECT-- 46bool(true) 47bool(true) 48bool(true) 49Now is the winter of our discontent. 50bool(true) 51bool(true) 52bool(false) 53bool(false) 54bool(false) 55bool(false) 56bool(false) 57bool(true) 58bool(true) 59true 60true 61