/** * Parses an object identifier except for the first octet, which is parsed * differently. This way relative object identifiers can also be parsed * using this. * * @param $binaryData * @param $offsetIndex * @param $octetsToRead * * @throws ParserException * * @return string */ protected static function parseOid(&$binaryData, &$offsetIndex, $octetsToRead) { $oid = ''; while ($octetsToRead > 0) { $octets = ''; do { if (0 === $octetsToRead) { throw new ParserException('Malformed ASN.1 Object Identifier', $offsetIndex - 1); } $octetsToRead--; $octet = $binaryData[$offsetIndex++]; $octets .= $octet; } while (ord($octet) & 0x80); $oid .= sprintf('%d.', Base128::decode($octets)); } // Remove trailing '.' return substr($oid, 0, -1) ?: ''; }
/** * @param int|string $identifier * * @return int */ public static function getTagNumber($identifier) { $firstOctet = self::makeNumeric($identifier); $tagNumber = $firstOctet & self::LONG_FORM; if ($tagNumber < self::LONG_FORM) { return $tagNumber; } if (is_numeric($identifier)) { $identifier = chr($identifier); } return Base128::decode(substr($identifier, 1)); }
/** * @param int|string $identifier * * @return int */ public static function getTagNumber($identifier) { $firstOctet = substr($identifier, 0, 1); if (!IdentifierManager::isLongForm($firstOctet)) { return ord($firstOctet) & self::LONG_FORM; } $firstOctet = self::makeNumeric($identifier); if (is_numeric($identifier)) { $identifier = chr($identifier); } return Base128::decode(substr($identifier, 1)); }