1--TEST--
2Stream cipher gcm encryption filter for reading
3--SKIPIF--
4<?php if (!Crypto\Cipher::hasMode(Crypto\Cipher::MODE_GCM)) die("Skip: GCM mode not defined (update OpenSSL version)"); ?>
5--FILE--
6<?php
7$algorithm = 'aes-256-gcm';
8$key = str_repeat('x', 32);
9$iv = str_repeat('i', 16);
10$aad = str_repeat('b', 16);
11$data = str_repeat('a', 16);
12
13$filename = (dirname( __FILE__) . "/stream_filters_cipher_gcm_enc_read.tmp");
14file_put_contents($filename, $data);
15
16$context = stream_context_create(array(
17	'crypto' => array(
18		'filters' => array(
19			array(
20				'type' => 'cipher',
21				'action' => 'encrypt',
22				'algorithm' => $algorithm,
23				'key' => $key,
24				'iv'  => $iv,
25				'aad' => $aad,
26			)
27		)
28	),
29));
30
31$stream = fopen("crypto.file://" . $filename, "r", false, $context);
32if (!$stream) {
33	exit;
34}
35while ($data = fread($stream, strlen($data))) {
36	echo bin2hex($data) . "\n";
37}
38
39$meta_data = stream_get_meta_data($stream);
40echo $meta_data['wrapper_data'][0] . "\n";
41?>
42--CLEAN--
43<?php
44$filename = (dirname( __FILE__) . "/stream_filters_cipher_gcm_enc_read.tmp");
45if (file_exists($filename))
46	unlink($filename);
47?>
48--EXPECT--
49622070d3bea6f720943d1198a7e6afa5
50X-PHP-Crypto-Auth-Tag: f3c2954804f101d3342f6b37ba46ac8e
51