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$tag = pack("H*", 'f3c2954804f101d3342f6b37ba46ac8e');
12$ciphertext = pack("H*", '622070d3bea6f720943d1198a7e6afa5');
13
14$context = stream_context_create(array(
15	'crypto' => array(
16		'filters' => array(
17			array(
18				'type' => 'cipher',
19				'action' => 'decrypt',
20				'algorithm' => $algorithm,
21				'key' => $key,
22				'iv'  => $iv,
23				'tag' => $tag,
24				'aad' => $aad,
25			)
26		)
27	),
28));
29
30$filename = (dirname( __FILE__) . "/stream_filters_cipher_gcm_dec_write.tmp");
31
32$stream = fopen("crypto.file://" . $filename, "w", false, $context);
33if (!$stream) {
34	exit;
35}
36fwrite($stream, $ciphertext, strlen($ciphertext));
37fflush($stream);
38
39$meta_data = stream_get_meta_data($stream);
40echo $meta_data['wrapper_data'][0] . "\n";
41
42fclose($stream);
43
44echo file_get_contents($filename);
45?>
46--CLEAN--
47<?php
48$filename = (dirname( __FILE__) . "/stream_filters_cipher_gcm_dec_write.tmp");
49if (file_exists($filename))
50	unlink($filename);
51?>
52--EXPECT--
53X-PHP-Crypto-Auth-Result: success
54aaaaaaaaaaaaaaaa