Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream verification #25

Open
sagikazarmark opened this issue Jan 1, 2016 · 0 comments
Open

Stream verification #25

sagikazarmark opened this issue Jan 1, 2016 · 0 comments

Comments

@sagikazarmark
Copy link
Member

Utilize stream filters to verify the content of stream.

For example an md5 verification:

class MD5 extends \php_user_filter
{
    private $context;

    public function onCreate()
    {
        $this->context = hash_init('md5');

        return true;
    }

    public function onClose()
    {
        $hash = hash_final($this->context);

        if (false === hash_equals($this->params, $hash)) {
            throw new VerificationException('The stream integrity cannot be verified');
        }

        return true;
    }

    public function filter($in, $out, &$consumed, $closing)
    {
        while ($bucket = stream_bucket_make_writeable($in)) {
            hash_update($this->context, $bucket->data);

            $consumed += $bucket->datalen;

            stream_bucket_append($out, $bucket);
        }

        return PSFS_PASS_ON;
    }
}

This would be useful when downloading files (PHARs for example, when a hash is likely available)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant