summaryrefslogtreecommitdiff
path: root/ext/mcrypt/tests
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2010-01-15 21:02:20 +0000
committerStanislav Malyshev <stas@php.net>2010-01-15 21:02:20 +0000
commit932e276c0b4f08d63779cb4b5cfffe98cda920c9 (patch)
treee563db686fb2e88f74d80fe3f16ccc92e9d49032 /ext/mcrypt/tests
parent15e31de034ad02c801ce0835fad12adfe636e70f (diff)
downloadphp-git-932e276c0b4f08d63779cb4b5cfffe98cda920c9.tar.gz
add filters to mcrypt
# trunk will follow soon
Diffstat (limited to 'ext/mcrypt/tests')
-rw-r--r--ext/mcrypt/tests/mcrypt_filters.phpt41
1 files changed, 41 insertions, 0 deletions
diff --git a/ext/mcrypt/tests/mcrypt_filters.phpt b/ext/mcrypt/tests/mcrypt_filters.phpt
new file mode 100644
index 0000000000..f528219500
--- /dev/null
+++ b/ext/mcrypt/tests/mcrypt_filters.phpt
@@ -0,0 +1,41 @@
+--TEST--
+mcrypt filters
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+foreach (stream_get_filters() as $f) {
+ if ($f == "mcrypt.*" || $f == "mdecrypt.*") {
+ echo "FOUND\n";
+ }
+}
+
+$secretfile = 'secert-file.tmp';
+$passphrase = 'My secret';
+
+$iv = substr(md5('iv'.$passphrase, true), 0, 8);
+$key = substr(md5('pass1'.$passphrase, true) .
+ md5('pass2'.$passphrase, true), 0, 24);
+$opts = array('iv'=>$iv, 'key'=>$key);
+
+$fp = fopen($secretfile, 'wb');
+stream_filter_append($fp, 'mcrypt.tripledes', STREAM_FILTER_WRITE, $opts);
+fwrite($fp, 'Secret secret secret data');
+fclose($fp);
+
+echo md5_file($secretfile)."\n";
+
+$fp = fopen($secretfile, 'rb');
+stream_filter_append($fp, 'mdecrypt.tripledes', STREAM_FILTER_READ, $opts);
+$data = stream_get_contents($fp);
+fclose($fp);
+
+echo $data."\n";
+
+@unlink($secretfile);
+
+--EXPECTF--
+FOUND
+FOUND
+32e14bd3c31f2bd666e4290ebdb166a7
+Secret secret secret data \ No newline at end of file