/** * Parse 'attributeTypeAndValue'. * * attributeType "=" attributeValue * * @param int $offset * @throws \UnexpectedValueException * @return array A tuple of [type, value]. Value may be either a string or * an Element, if it's encoded as hexstring. */ private function _parseAttrTypeAndValue(&$offset) { $idx = $offset; $type = $this->_parseAttrType($idx); $this->_skipWs($idx); if ($idx >= $this->_len || "=" != $this->_dn[$idx++]) { throw new \UnexpectedValueException("Invalid type and value pair."); } $this->_skipWs($idx); // hexstring if ($idx < $this->_len && "#" == $this->_dn[$idx]) { ++$idx; $data = $this->_parseAttrHexValue($idx); try { $value = Element::fromDER($data); } catch (DecodeException $e) { throw new \UnexpectedValueException("Invalid DER encoding from hexstring.", 0, $e); } } else { $value = $this->_parseAttrStringValue($idx); } $offset = $idx; return array($type, $value); }
/** * * @see \ASN1\Element::_decodeFromDER() * @return self */ protected static function _decodeFromDER(Identifier $identifier, $data, &$offset) { $idx = $offset; if (!$identifier->isConstructed()) { throw new DecodeException("Structured element must have constructed bit set."); } $length = Length::expectFromDER($data, $idx); $end = $idx + $length->length(); $elements = array(); while ($idx < $end) { $elements[] = Element::fromDER($data, $idx); // check that element didn't overflow length if ($idx > $end) { throw new DecodeException("Structure's content overflows length."); } } $offset = $idx; // return instance by static late binding return new static(...$elements); }
/** * * @see \ASN1\Type\Tagged\ExplicitTagging::explicit() * @return UnspecifiedType */ public function explicit($expectedTag = null) { $idx = $this->_offset; Length::expectFromDER($this->_data, $idx); $element = Element::fromDER($this->_data, $idx); if (isset($expectedTag)) { $element->expectType($expectedTag); } return new UnspecifiedType($element); }