File manager - Edit - /home/opticamezl/www/newok/spomky-labs.zip
Back
PK ��\C��, , cbor-php/LICENSEnu �[��� MIT License Copyright (c) 2018 Spomky-Labs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK ��\�z�� � cbor-php/src/MapObject.phpnu �[��� <?php declare(strict_types=1); /* * The MIT License (MIT) * * Copyright (c) 2018-2020 Spomky-Labs * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file for details. */ namespace CBOR; use ArrayIterator; use function count; use Countable; use InvalidArgumentException; use Iterator; use IteratorAggregate; final class MapObject extends AbstractCBORObject implements Countable, IteratorAggregate { private const MAJOR_TYPE = 0b101; /** * @var MapItem[] */ private $data = []; /** * @var int|null */ private $length; /** * @param MapItem[] $data */ public function __construct(array $data = []) { list($additionalInformation, $length) = LengthCalculator::getLengthOfArray($data); array_map(static function ($item): void { if (!$item instanceof MapItem) { throw new InvalidArgumentException('The list must contain only MapItem objects.'); } }, $data); parent::__construct(self::MAJOR_TYPE, $additionalInformation); $this->data = $data; $this->length = $length; } public function __toString(): string { $result = parent::__toString(); if (null !== $this->length) { $result .= $this->length; } foreach ($this->data as $object) { $result .= (string) $object->getKey(); $result .= (string) $object->getValue(); } return $result; } public function add(CBORObject $key, CBORObject $value): void { $this->data[] = new MapItem($key, $value); list($this->additionalInformation, $this->length) = LengthCalculator::getLengthOfArray($this->data); } public function count(): int { return count($this->data); } public function getIterator(): Iterator { return new ArrayIterator($this->data); } public function getNormalizedData(bool $ignoreTags = false): array { $result = []; foreach ($this->data as $object) { $result[$object->getKey()->getNormalizedData($ignoreTags)] = $object->getValue()->getNormalizedData($ignoreTags); } return $result; } } PK ��\�/g� � cbor-php/src/TagObject.phpnu �[��� <?php declare(strict_types=1); /* * The MIT License (MIT) * * Copyright (c) 2018-2020 Spomky-Labs * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file for details. */ namespace CBOR; abstract class TagObject extends AbstractCBORObject { private const MAJOR_TYPE = 0b110; /** * @var string|null */ protected $data; /** * @var CBORObject */ protected $object; public function __construct(int $additionalInformation, ?string $data, CBORObject $object) { parent::__construct(self::MAJOR_TYPE, $additionalInformation); $this->data = $data; $this->object = $object; } public function __toString(): string { $result = parent::__toString(); if (null !== $this->data) { $result .= $this->data; } $result .= (string) $this->object; return $result; } abstract public static function getTagId(): int; abstract public static function createFromLoadedData(int $additionalInformation, ?string $data, CBORObject $object): self; public function getValue(): CBORObject { return $this->object; } } PK ��\-���� � cbor-php/src/StringStream.phpnu �[��� <?php declare(strict_types=1); /* * The MIT License (MIT) * * Copyright (c) 2018-2020 Spomky-Labs * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file for details. */ namespace CBOR; use InvalidArgumentException; use RuntimeException; final class StringStream implements Stream { /** * @var resource */ private $resource; public function __construct(string $data) { $resource = fopen('php://memory', 'rb+'); if (false === $resource) { throw new RuntimeException('Unable to open the memory'); } $result = fwrite($resource, $data); if (false === $result) { throw new RuntimeException('Unable to write the memory'); } $result = rewind($resource); if (false === $result) { throw new RuntimeException('Unable to rewind the memory'); } $this->resource = $resource; } public function read(int $length): string { if (0 === $length) { return ''; } $data = fread($this->resource, $length); if (false === $data) { throw new RuntimeException('Unable to read the memory'); } if (mb_strlen($data, '8bit') !== $length) { throw new InvalidArgumentException(sprintf('Out of range. Expected: %d, read: %d.', $length, mb_strlen($data, '8bit'))); } return $data; } } PK ��\$� � � cbor-php/src/MapItem.phpnu �[��� <?php declare(strict_types=1); /* * The MIT License (MIT) * * Copyright (c) 2018-2020 Spomky-Labs * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file for details. */ namespace CBOR; class MapItem { /** * @var CBORObject */ private $key; /** * @var CBORObject */ private $value; public function __construct(CBORObject $key, CBORObject $value) { $this->key = $key; $this->value = $value; } public function getKey(): CBORObject { return $this->key; } public function getValue(): CBORObject { return $this->value; } } PK ��\Y/�g g ! cbor-php/src/LengthCalculator.phpnu �[��� <?php declare(strict_types=1); /* * The MIT License (MIT) * * Copyright (c) 2018-2020 Spomky-Labs * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file for details. */ namespace CBOR; use Brick\Math\BigInteger; use function chr; use function count; use InvalidArgumentException; final class LengthCalculator { public static function getLengthOfString(string $data): array { $length = mb_strlen($data, '8bit'); return self::computeLength($length); } public static function getLengthOfArray(array $data): array { $length = count($data); return self::computeLength($length); } private static function computeLength(int $length): array { switch (true) { case $length < 24: return [$length, null]; case $length < 0xFF: return [24, chr($length)]; case $length < 0xFFFF: return [25, self::hex2bin(static::fixHexLength(Utils::intToHex($length)))]; case $length < 0xFFFFFFFF: return [26, self::hex2bin(static::fixHexLength(Utils::intToHex($length)))]; case BigInteger::of($length)->isLessThan(BigInteger::fromBase('FFFFFFFFFFFFFFFF', 16)): return [27, self::hex2bin(static::fixHexLength(Utils::intToHex($length)))]; default: return [31, null]; } } private static function hex2bin(string $data): string { $result = hex2bin($data); if (false === $result) { throw new InvalidArgumentException('Unable to convert the data'); } return $result; } private static function fixHexLength(string $data): string { return str_pad($data, (int) (2 ** ceil(log(mb_strlen($data, '8bit'), 2))), '0', STR_PAD_LEFT); } } PK ��\D�W�e e $ cbor-php/src/SignedIntegerObject.phpnu �[��� <?php declare(strict_types=1); /* * The MIT License (MIT) * * Copyright (c) 2018-2020 Spomky-Labs * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file for details. */ namespace CBOR; use Brick\Math\BigInteger; use GMP; use InvalidArgumentException; final class SignedIntegerObject extends AbstractCBORObject { private const MAJOR_TYPE = 0b001; /** * @var string|null */ private $data; public function __construct(int $additionalInformation, ?string $data) { parent::__construct(self::MAJOR_TYPE, $additionalInformation); $this->data = $data; } public function __toString(): string { $result = parent::__toString(); if (null !== $this->data) { $result .= $this->data; } return $result; } public static function createObjectForValue(int $additionalInformation, ?string $data): self { return new self($additionalInformation, $data); } public static function create(int $value): self { return self::createFromString((string) $value); } public static function createFromString(string $value): self { $integer = BigInteger::of($value); return self::createBigInteger($integer); } /** * @deprecated Deprecated since v1.1 and will be removed in v2.0. Please use "create" or "createFromString" instead */ public static function createFromGmpValue(GMP $value): self { if (gmp_cmp($value, gmp_init(0)) >= 0) { throw new InvalidArgumentException('The value must be a negative integer.'); } $minusOne = gmp_init(-1); $computed_value = gmp_sub($minusOne, $value); switch (true) { case gmp_intval($computed_value) < 24: $ai = gmp_intval($computed_value); $data = null; break; case gmp_cmp($computed_value, gmp_init('FF', 16)) < 0: $ai = 24; $data = self::hex2bin(str_pad(gmp_strval($computed_value, 16), 2, '0', STR_PAD_LEFT)); break; case gmp_cmp($computed_value, gmp_init('FFFF', 16)) < 0: $ai = 25; $data = self::hex2bin(str_pad(gmp_strval($computed_value, 16), 4, '0', STR_PAD_LEFT)); break; case gmp_cmp($computed_value, gmp_init('FFFFFFFF', 16)) < 0: $ai = 26; $data = self::hex2bin(str_pad(gmp_strval($computed_value, 16), 8, '0', STR_PAD_LEFT)); break; default: throw new InvalidArgumentException('Out of range. Please use NegativeBigIntegerTag tag with ByteStringObject object instead.'); } return new self($ai, $data); } public function getValue(): string { return $this->getNormalizedData(); } public function getNormalizedData(bool $ignoreTags = false): string { if (null === $this->data) { return (string) (-1 - $this->additionalInformation); } $result = Utils::binToBigInteger($this->data); $minusOne = BigInteger::of(-1); return $minusOne->minus($result)->toBase(10); } private static function createBigInteger(BigInteger $integer): self { if ($integer->isGreaterThanOrEqualTo(BigInteger::zero())) { throw new InvalidArgumentException('The value must be a negative integer.'); } $minusOne = BigInteger::of(-1); $computed_value = $minusOne->minus($integer); switch (true) { case $computed_value->isLessThan(BigInteger::of(24)): $ai = $computed_value->toInt(); $data = null; break; case $computed_value->isLessThan(BigInteger::fromBase('FF', 16)): $ai = 24; $data = self::hex2bin(str_pad($computed_value->toBase(16), 2, '0', STR_PAD_LEFT)); break; case $computed_value->isLessThan(BigInteger::fromBase('FFFF', 16)): $ai = 25; $data = self::hex2bin(str_pad($computed_value->toBase(16), 4, '0', STR_PAD_LEFT)); break; case $computed_value->isLessThan(BigInteger::fromBase('FFFFFFFF', 16)): $ai = 26; $data = self::hex2bin(str_pad($computed_value->toBase(16), 8, '0', STR_PAD_LEFT)); break; default: throw new InvalidArgumentException('Out of range. Please use NegativeBigIntegerTag tag with ByteStringObject object instead.'); } return new self($ai, $data); } private static function hex2bin(string $data): string { $result = hex2bin($data); if (false === $result) { throw new InvalidArgumentException('Unable to convert the data'); } return $result; } } PK ��\���U ! cbor-php/src/ByteStringObject.phpnu �[��� <?php declare(strict_types=1); /* * The MIT License (MIT) * * Copyright (c) 2018-2020 Spomky-Labs * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file for details. */ namespace CBOR; final class ByteStringObject extends AbstractCBORObject { private const MAJOR_TYPE = 0b010; /** * @var string */ private $value; /** * @var int|null */ private $length; public function __construct(string $data) { list($additionalInformation, $length) = LengthCalculator::getLengthOfString($data); parent::__construct(self::MAJOR_TYPE, $additionalInformation); $this->length = $length; $this->value = $data; } public function __toString(): string { $result = parent::__toString(); if (null !== $this->length) { $result .= $this->length; } $result .= $this->value; return $result; } public function getValue(): string { return $this->value; } public function getLength(): int { return mb_strlen($this->value, '8bit'); } public function getNormalizedData(bool $ignoreTags = false): string { return $this->value; } } PK ��\��)�? ? cbor-php/src/Stream.phpnu �[��� <?php declare(strict_types=1); /* * The MIT License (MIT) * * Copyright (c) 2018-2020 Spomky-Labs * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file for details. */ namespace CBOR; interface Stream { public function read(int $length): string; } PK ��\OB�n n &