11 class Mac extends \php_user_filter
15 public function onCreate()
17 if (!isset($this->params[
'algorithm']) ||
18 !is_object($this->params[
'algorithm']) ||
19 !($this->params[
'algorithm'] instanceof
MacEnum)) {
20 throw new \InvalidArgumentException(
'Invalid algorithm');
23 if (!isset($this->params[
'innerAlgorithm']) ||
24 !is_object($this->params[
'innerAlgorithm']) ||
26 throw new \InvalidArgumentException(
'Invalid inner algorithm');
29 if (!isset($this->params[
'key']) || !is_string($this->params[
'key'])) {
30 throw new \InvalidArgumentException(
'Missing or invalid key');
33 $nonce = isset($this->params[
'nonce']) ? $this->params[
'nonce'] :
'';
34 if (!is_string($nonce)) {
35 throw new \InvalidArgumentException(
'Invalid nonce');
38 $allowUnsafe = isset($this->params[
'allowUnsafe']) ? (bool) $this->params[
'allowUnsafe'] :
false;
39 $this->context = Registry::buildMac(
40 $this->params[
'algorithm'],
41 $this->params[
'innerAlgorithm'],
49 public function filter($in, $out, &$consumed, $closing)
51 while ($bucket = stream_bucket_make_writeable($in)) {
52 $this->context->update($bucket->data);
53 $consumed += $bucket->datalen;
57 $bucket = stream_bucket_new($this->stream, $this->context->finalize(
true));
58 stream_bucket_append($out, $bucket);