1--TEST--
2Stream cipher gcm decryption filter for writing
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$context = stream_context_create(array(
14	'crypto' => array(
15		'filters' => array(
16			array(
17				'type' => 'cipher',
18				'action' => 'encrypt',
19				'algorithm' => $algorithm,
20				'key' => $key,
21				'iv'  => $iv,
22				'aad' => $aad,
23			)
24		)
25	),
26));
27
28$filename = (dirname( __FILE__) . "/stream_filters_cipher_gcm_enc_write.tmp");
29
30$stream = fopen("crypto.file://" . $filename, "w", false, $context);
31if (!$stream) {
32	exit;
33}
34fwrite($stream, $data, strlen($data));
35fflush($stream);
36
37$meta_data = stream_get_meta_data($stream);
38echo $meta_data['wrapper_data'][0] . "\n";
39
40fclose($stream);
41
42echo bin2hex(file_get_contents($filename));
43?>
44--CLEAN--
45<?php
46$filename = (dirname( __FILE__) . "/stream_filters_cipher_gcm_enc_write.tmp");
47if (file_exists($filename))
48	unlink($filename);
49?>
50--EXPECT--
51X-PHP-Crypto-Auth-Tag: f3c2954804f101d3342f6b37ba46ac8e
52622070d3bea6f720943d1198a7e6afa5
53