public static function fromDER(string $data, int &$offset = null): self
    {
        $idx = $offset ?? 0;
        $datalen = strlen($data);
        if ($idx >= $datalen) {
            throw new DecodeException(
                "Unexpected end of data while decoding length.");
        }
        $indefinite = false;
        $byte = ord($data[$idx++]);
        // bits 7 to 1
        $length = (0x7f & $byte);
        // long form
        if (0x80 & $byte) {
            if (!$length) {
                $indefinite = true;
            } else {
                if ($idx + $length > $datalen) {
                    throw new DecodeException(
                        "Unexpected end of data while decoding long form length.");
                }
                $length = self::_decodeLongFormLength($length, $data, $idx);
            }
        }
        if (isset($offset)) {
            $offset = $idx;
        }
        return new self($length, $indefinite);
    }
public static function fromDER(string $data, int &$offset = null): self
    {
        $idx = $offset ?? 0;
        $datalen = strlen($data);
        if ($idx >= $datalen) {
            throw new DecodeException(
                "Unexpected end of data while decoding length.");
        }
        $indefinite = false;
        $byte = ord($data[$idx++]);
        // bits 7 to 1
        $length = (0x7f & $byte);
        // long form
        if (0x80 & $byte) {
            if (!$length) {
                $indefinite = true;
            } else {
                if ($idx + $length > $datalen) {
                    throw new DecodeException(
                        "Unexpected end of data while decoding long form length.");
                }
                $length = self::_decodeLongFormLength($length, $data, $idx);
            }
        }
        if (isset($offset)) {
            $offset = $idx;
        }
        return new self($length, $indefinite);
    }
public static function fromDER ( string $ data , int & $ offset = null ) : self { $ idx = $ offset ?? 0 ; $ datalen = strlen ( $ data ) ; if ( $ idx >= $ datalen ) { throw new DecodeException ( "Unexpected end of data while decoding length." ) ; } $ indefinite = false ; $ byte = ord ( $ data [ $ idx ++ ] ) ; // bits 7 to 1 $ length = ( 0x7f & $ byte ) ; // long form if ( 0x80 & $ byte ) { if ( ! $ length ) { $ indefinite = true ; } else { if ( $ idx + $ length > $ datalen ) { throw new DecodeException ( "Unexpected end of data while decoding long form length." ) ; } $ length = self :: _decodeLongFormLength ( $ length , $ data , $ idx ) ; } } if ( isset ( $ offset ) ) { $ offset = $ idx ; } return new self ( $ length , $ indefinite ) ; }
Decode length component from DER data.

@param string $data DER encoded data
@param int|null $offset Reference to the variable that contains offset
into the data where to start parsing. Variable is updated to
the offset next to the parsed length component. If null, start
from offset 0.
@throws DecodeException If decoding fails
@return self
Decode length component from DER data .