• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/paysystem/asn1.php
  • Класс: BitrixSalePaySystemASN1
  • Вызов: ASN1::readDER
static function readDER($der, $offset, &$data, $ignore_bit_strings = FALSE) {
        $pos = $offset;

	$size = mb_strlen($der);

        if ($size < 2) return 0;

        // Tag/Type
        $constructed = (ord($der[$pos]) >> 5) & 0x01;
        $type = ord($der[$pos++]) & 0x1f;
        if ($type == 0x1f) return 0; // Long-form type: not supported
        if ($pos >= $size) return 0;

        // Length
        $len = ord($der[$pos++]);
        if ($len & 0x80) {
            $n = $len & 0x1f;
            $len = 0;
            while ($n-- && $pos < $size) {
                $len = ($len << 8) | ord($der[$pos++]);
            }
        }
        if ($pos >= $size || $len > $size - $pos) return 0;

        // Value
        if ($type == self::BIT_STRING) { // BIT STRING
            $pos++; // Skip the first contents octet (padding indicator)
		$data = mb_substr($der, $pos, $len - 1);
            if (!$ignore_bit_strings) $pos += $len - 1;
        } elseif (!$constructed /*&& ($type != 0x04)*/) {
		$data = mb_substr($der, $pos, $len);
            $pos += $len;
        }

        return $pos - $offset;
    }