src/lib/Herrera/Box/Signature.php
public function get($required = null)
    {
        if (null === $required) {
            $required = (bool) ini_get('phar.require_hash');
        }

        $this->seek(-4, SEEK_END);

        if ('GBMB' !== $this->read(4)) {
            if ($required) {
                throw new PharException(
                    sprintf(
                        'The phar "%s" is not signed.',
                        $this->file
                    )
                );
            }

            return null;
        }

        $this->seek(-8, SEEK_END);

        $flag = unpack('V', $this->read(4));
        $flag = $flag[1];

        foreach (self::$types as $type) {
            if ($flag === $type['flag']) {
                break;
            }

            unset($type);
        }

        if (!isset($type)) {
            throw new PharException(
                sprintf(
                    'The signature type (%x) is not recognized for the phar "%s".',
                    $flag,
                    $this->file
                )
            );
        }

        $offset = -8;

        if (0x10 === $type['flag']) {
            $offset = -12;

            $this->seek(-12, SEEK_END);

            $type['size'] = unpack('V', $this->read(4));
            $type['size'] = $type['size'][1];
        }

        $this->seek($offset - $type['size'], SEEK_END);

        $hash = $this->read($type['size']);
        $hash = unpack('H*', $hash);

        return array(
            'hash_type' => $type['name'],
            'hash' => strtoupper($hash[1])
        );
    }
public function get($required = null)
    {
        if (null === $required) {
            $required = (bool) ini_get('phar.require_hash');
        }

        $this->seek(-4, SEEK_END);

        if ('GBMB' !== $this->read(4)) {
            if ($required) {
                throw new PharException(
                    sprintf(
                        'The phar "%s" is not signed.',
                        $this->file
                    )
                );
            }

            return null;
        }

        $this->seek(-8, SEEK_END);

        $flag = unpack('V', $this->read(4));
        $flag = $flag[1];

        foreach (self::$types as $type) {
            if ($flag === $type['flag']) {
                break;
            }

            unset($type);
        }

        if (!isset($type)) {
            throw new PharException(
                sprintf(
                    'The signature type (%x) is not recognized for the phar "%s".',
                    $flag,
                    $this->file
                )
            );
        }

        $offset = -8;

        if (0x10 === $type['flag']) {
            $offset = -12;

            $this->seek(-12, SEEK_END);

            $type['size'] = unpack('V', $this->read(4));
            $type['size'] = $type['size'][1];
        }

        $this->seek($offset - $type['size'], SEEK_END);

        $hash = $this->read($type['size']);
        $hash = unpack('H*', $hash);

        return array(
            'hash_type' => $type['name'],
            'hash' => strtoupper($hash[1])
        );
    }
public function get ( $ required = null ) { if ( null === $ required ) { $ required = ( bool ) ini_get ( 'phar.require_hash' ) ; } $ this -> seek ( - 4 , SEEK_END ) ; if ( 'GBMB' !== $ this -> read ( 4 ) ) { if ( $ required ) { throw new PharException ( sprintf ( 'The phar "%s" is not signed.' , $ this -> file ) ) ; } return null ; } $ this -> seek ( - 8 , SEEK_END ) ; $ flag = unpack ( 'V' , $ this -> read ( 4 ) ) ; $ flag = $ flag [ 1 ] ; foreach ( self :: $ types as $ type ) { if ( $ flag === $ type [ 'flag' ] ) { break ; } unset ( $ type ) ; } if ( ! isset ( $ type ) ) { throw new PharException ( sprintf ( 'The signature type (%x) is not recognized for the phar "%s".' , $ flag , $ this -> file ) ) ; } $ offset = - 8 ; if ( 0x10 === $ type [ 'flag' ] ) { $ offset = - 12 ; $ this -> seek ( - 12 , SEEK_END ) ; $ type [ 'size' ] = unpack ( 'V' , $ this -> read ( 4 ) ) ; $ type [ 'size' ] = $ type [ 'size' ] [ 1 ] ; } $ this -> seek ( $ offset - $ type [ 'size' ] , SEEK_END ) ; $ hash = $ this -> read ( $ type [ 'size' ] ) ; $ hash = unpack ( 'H*' , $ hash ) ; return array ( 'hash_type' => $ type [ 'name' ] , 'hash' => strtoupper ( $ hash [ 1 ] ) ) ; }
Returns the signature for the phar.

The value returned is identical to that of `Phar->getSignature()`. If
$required is not given, it will default to the `phar.require_hash`
current value.

@param boolean $required Is the signature required?

@return array The signature.

@throws PharException If the phar is not valid.
Returns the signature for the phar .