public static function fromDER(string $data, int &$offset = null): ElementBase
    {
        $idx = $offset ?? 0;
        // decode identifier
        $identifier = Identifier::fromDER($data, $idx);
        // determine class that implements type specific decoding
        $cls = self::_determineImplClass($identifier);
        try {
            // decode remaining element
            $element = $cls::_decodeFromDER($identifier, $data, $idx);
        } catch (\LogicException $e) {
            // rethrow as a RuntimeException for unified exception handling
            throw new DecodeException(
                sprintf("Error while decoding %s.",
                    self::tagToName($identifier->intTag())), 0, $e);
        }
        // if called in the context of a concrete class, check
        // that decoded type matches the type of a calling class
        $called_class = get_called_class();
        if (self::class != $called_class) {
            if (!$element instanceof $called_class) {
                throw new \UnexpectedValueException(
                    sprintf("%s expected, got %s.", $called_class,
                        get_class($element)));
            }
        }
        // update offset for the caller
        if (isset($offset)) {
            $offset = $idx;
        }
        return $element;
    }
public static function fromDER(string $data, int &$offset = null): ElementBase
    {
        $idx = $offset ?? 0;
        // decode identifier
        $identifier = Identifier::fromDER($data, $idx);
        // determine class that implements type specific decoding
        $cls = self::_determineImplClass($identifier);
        try {
            // decode remaining element
            $element = $cls::_decodeFromDER($identifier, $data, $idx);
        } catch (\LogicException $e) {
            // rethrow as a RuntimeException for unified exception handling
            throw new DecodeException(
                sprintf("Error while decoding %s.",
                    self::tagToName($identifier->intTag())), 0, $e);
        }
        // if called in the context of a concrete class, check
        // that decoded type matches the type of a calling class
        $called_class = get_called_class();
        if (self::class != $called_class) {
            if (!$element instanceof $called_class) {
                throw new \UnexpectedValueException(
                    sprintf("%s expected, got %s.", $called_class,
                        get_class($element)));
            }
        }
        // update offset for the caller
        if (isset($offset)) {
            $offset = $idx;
        }
        return $element;
    }
public static function fromDER ( string $ data , int & $ offset = null ) : ElementBase { $ idx = $ offset ?? 0 ; // decode identifier $ identifier = Identifier :: fromDER ( $ data , $ idx ) ; // determine class that implements type specific decoding $ cls = self :: _determineImplClass ( $ identifier ) ; try { // decode remaining element $ element = $ cls :: _decodeFromDER ( $ identifier , $ data , $ idx ) ; } catch ( \ LogicException $ e ) { // rethrow as a RuntimeException for unified exception handling throw new DecodeException ( sprintf ( "Error while decoding %s." , self :: tagToName ( $ identifier -> intTag ( ) ) ) , 0 , $ e ) ; } // if called in the context of a concrete class, check // that decoded type matches the type of a calling class $ called_class = get_called_class ( ) ; if ( self :: class != $ called_class ) { if ( ! $ element instanceof $ called_class ) { throw new \ UnexpectedValueException ( sprintf ( "%s expected, got %s." , $ called_class , get_class ( $ element ) ) ) ; } } // update offset for the caller if ( isset ( $ offset ) ) { $ offset = $ idx ; } return $ element ; }
Decode element 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 element. If null, start from offset
0.
@throws DecodeException If decoding fails
@throws \UnexpectedValueException If called in the context of an expected
type, but decoding yields another type
@return ElementBase
Decode element from DER data .