Пример #1
0
 /**
  * Returns pseudo random block
  *
  * @return string
  */
 protected function getPseudoRandomBlock()
 {
     global $APPLICATION;
     if (function_exists('openssl_random_pseudo_bytes')) {
         $bytes = openssl_random_pseudo_bytes(64);
         if ($bytes && String::getBinaryLength($bytes) >= 64) {
             return String::getBinarySubstring($bytes, 0, 64);
         }
     }
     $bytes = '';
     for ($i = 0; $i < 64; $i++) {
         $bytes .= pack('S', mt_rand(0, 0xffff));
     }
     $bytes .= $APPLICATION->getServerUniqID();
     return hash('sha512', $bytes, true);
 }
Пример #2
0
 /**
  * Returns pseudo random block
  *
  * @return string
  */
 protected function getPseudoRandomBlock()
 {
     global $APPLICATION;
     if (static::isOpensslSkipped()) {
         $bytes = openssl_random_pseudo_bytes(static::RANDOM_BLOCK_LENGTH);
         if ($bytes && String::getBinaryLength($bytes) >= static::RANDOM_BLOCK_LENGTH) {
             return String::getBinarySubstring($bytes, 0, static::RANDOM_BLOCK_LENGTH);
         }
     }
     $bytes = '';
     for ($i = 0; $i < static::RANDOM_BLOCK_LENGTH; $i++) {
         $bytes .= pack('S', mt_rand(0, 0xffff));
     }
     $bytes .= $APPLICATION->getServerUniqID();
     return hash('sha512', $bytes, true);
 }
Пример #3
0
 protected function decompress()
 {
     if (is_resource($this->outputStream)) {
         $compressed = stream_get_contents($this->outputStream, -1, 10);
         $compressed = String::getBinarySubstring($compressed, 0, -8);
         if ($compressed != '') {
             $uncompressed = gzinflate($compressed);
             rewind($this->outputStream);
             $len = fwrite($this->outputStream, $uncompressed);
             ftruncate($this->outputStream, $len);
         }
     } else {
         $compressed = String::getBinarySubstring($this->result, 10, -8);
         if ($compressed != '') {
             $this->result = gzinflate($compressed);
         }
     }
 }
Пример #4
0
 /**
  * Returns array of file data
  * @param $content
  * @return array
  */
 private static function getFilesInfo($content)
 {
     $offset = 0;
     $line = 0;
     $arResult = array();
     while (($newLinePos = String::getBinaryStrpos($content, "\n", $offset)) !== false) {
         $line++;
         $offset = $newLinePos + 1;
         if (String::getBinarySubstring($content, $offset, strlen(self::HEADER_START_TAG)) === self::HEADER_START_TAG) {
             $endingPos = String::getBinaryStrpos($content, self::HEADER_END_TAG, $offset);
             if ($endingPos === false) {
                 break;
             }
             $startData = $offset + strlen(self::HEADER_START_TAG);
             $data = unserialize(String::getBinarySubstring($content, $startData, $endingPos - $startData));
             if (is_array($data)) {
                 $data["line"] = $line + 1;
                 $arResult[] = $data;
             }
             $offset = $endingPos;
         }
     }
     return $arResult;
 }
Пример #5
0
 /**
  * @param string $iblockType This variable is the id iblockType.
  * @param string $datum This variable is the encrypted string.
  * @param null $siteId This variable is the id current site.
  * @throws Main\ArgumentNullException
  */
 public static function import($iblockType, $datum, $siteId = null)
 {
     if (empty($datum)) {
         throw new Main\ArgumentNullException("datum");
     }
     if (substr($datum, 0, 10) === "compressed") {
         $datum = gzuncompress(Main\Text\String::getBinarySubstring($datum, 10));
     }
     $len = intval(Main\Text\String::getBinarySubstring($datum, 0, 10));
     $iblockSerialized = Main\Text\String::getBinarySubstring($datum, 10, $len);
     $datum = Main\Text\String::getBinarySubstring($datum, $len + 10);
     $marker = Main\Text\String::getBinarySubstring($datum, 0, 1);
     $picture = null;
     $pictureType = null;
     if ($marker == "P") {
         $len = intval(Main\Text\String::getBinarySubstring($datum, 1, 10));
         $pictureType = Main\Text\String::getBinarySubstring($datum, 11, $len);
         $datum = Main\Text\String::getBinarySubstring($datum, $len + 11);
         $len = intval(Main\Text\String::getBinarySubstring($datum, 0, 10));
         $picture = Main\Text\String::getBinarySubstring($datum, 10, $len);
         $datum = Main\Text\String::getBinarySubstring($datum, $len + 10);
         $marker = Main\Text\String::getBinarySubstring($datum, 0, 1);
     }
     $iblock = CheckSerializedData($iblockSerialized) ? unserialize($iblockSerialized) : array();
     $iblock = Main\Text\Encoding::convertEncodingArray($iblock, "UTF-8", LANG_CHARSET);
     $iblockId = static::createIBlock($iblockType, $iblock, $pictureType, $picture, $siteId);
     if ($iblockId > 0) {
         $documentType = self::getDocumentType($iblockType, $iblockId);
         while (!empty($datum)) {
             if ($marker == "B") {
                 $len = intval(Main\Text\String::getBinarySubstring($datum, 1, 10));
                 $bpDescr = Main\Text\String::getBinarySubstring($datum, 11, $len);
                 $datum = Main\Text\String::getBinarySubstring($datum, $len + 11);
                 $bpDescr = CheckSerializedData($bpDescr) ? unserialize($bpDescr) : array();
                 $bpDescr = Main\Text\Encoding::convertEncodingArray($bpDescr, "UTF-8", LANG_CHARSET);
                 $len = intval(Main\Text\String::getBinarySubstring($datum, 0, 10));
                 $bp = Main\Text\String::getBinarySubstring($datum, 10, $len);
                 $datum = Main\Text\String::getBinarySubstring($datum, $len + 10);
                 static::importTemplate($documentType, $bpDescr, $bp);
             } else {
             }
             if (empty($datum)) {
                 break;
             }
             $marker = Main\Text\String::getBinarySubstring($datum, 0, 1);
         }
     }
 }