Файловый менеджер - Редактировать - /var/www/html/cose-lib.zip
Ðазад
PK ! �-Ts� � src/Key/SymmetricKey.phpnu �[��� <?php declare(strict_types=1); namespace Cose\Key; use InvalidArgumentException; /** * @final */ class SymmetricKey extends Key { final public const DATA_K = -1; /** * @param array<int|string, mixed> $data */ public function __construct(array $data) { parent::__construct($data); if (! isset($data[self::TYPE]) || (int) $data[self::TYPE] !== self::TYPE_OCT) { throw new InvalidArgumentException( 'Invalid symmetric key. The key type does not correspond to a symmetric key' ); } if (! isset($data[self::DATA_K])) { throw new InvalidArgumentException('Invalid symmetric key. The parameter "k" is missing'); } } /** * @param array<int|string, mixed> $data */ public static function create(array $data): self { return new self($data); } public function k(): string { return $this->get(self::DATA_K); } } PK ! v�(/ / src/Key/Key.phpnu �[��� <?php declare(strict_types=1); namespace Cose\Key; use InvalidArgumentException; use function array_key_exists; use function sprintf; class Key { public const TYPE = 1; public const TYPE_OKP = 1; public const TYPE_EC2 = 2; public const TYPE_RSA = 3; public const TYPE_OCT = 4; public const TYPE_NAME_OKP = 'OKP'; public const TYPE_NAME_EC2 = 'EC'; public const TYPE_NAME_RSA = 'RSA'; public const TYPE_NAME_OCT = 'oct'; public const KID = 2; public const ALG = 3; public const KEY_OPS = 4; public const BASE_IV = 5; /** * @var array<int|string, mixed> */ private readonly array $data; /** * @param array<int|string, mixed> $data */ public function __construct(array $data) { if (! array_key_exists(self::TYPE, $data)) { throw new InvalidArgumentException('Invalid key: the type is not defined'); } $this->data = $data; } /** * @param array<int|string, mixed> $data */ public static function create(array $data): self { return new self($data); } /** * @param array<int, mixed> $data */ public static function createFromData(array $data): self { if (! array_key_exists(self::TYPE, $data)) { throw new InvalidArgumentException('Invalid key: the type is not defined'); } return match ($data[self::TYPE]) { '1' => new OkpKey($data), '2' => new Ec2Key($data), '3' => new RsaKey($data), '4' => new SymmetricKey($data), default => self::create($data), }; } public function type(): int|string { return $this->data[self::TYPE]; } public function alg(): int { return (int) $this->get(self::ALG); } /** * @return array<int|string, mixed> */ public function getData(): array { return $this->data; } public function has(int|string $key): bool { return array_key_exists($key, $this->data); } public function get(int|string $key): mixed { if (! array_key_exists($key, $this->data)) { throw new InvalidArgumentException(sprintf('The key has no data at index %d', $key)); } return $this->data[$key]; } } PK ! ��ݢ. . src/Key/RsaKey.phpnu �[��� <?php declare(strict_types=1); namespace Cose\Key; use Brick\Math\BigInteger; use InvalidArgumentException; use SpomkyLabs\Pki\CryptoTypes\Asymmetric\PublicKeyInfo; use SpomkyLabs\Pki\CryptoTypes\Asymmetric\RSA\RSAPrivateKey; use SpomkyLabs\Pki\CryptoTypes\Asymmetric\RSA\RSAPublicKey; use function array_key_exists; use function in_array; /** * @final * @see \Cose\Tests\Key\RsaKeyTest */ class RsaKey extends Key { final public const DATA_N = -1; final public const DATA_E = -2; final public const DATA_D = -3; final public const DATA_P = -4; final public const DATA_Q = -5; final public const DATA_DP = -6; final public const DATA_DQ = -7; final public const DATA_QI = -8; final public const DATA_OTHER = -9; final public const DATA_RI = -10; final public const DATA_DI = -11; final public const DATA_TI = -12; /** * @param array<int|string, mixed> $data */ public function __construct(array $data) { foreach ([self::TYPE] as $key) { if (is_numeric($data[$key])) { $data[$key] = (int) $data[$key]; } } parent::__construct($data); if ($data[self::TYPE] !== self::TYPE_RSA && $data[self::TYPE] !== self::TYPE_NAME_RSA) { throw new InvalidArgumentException('Invalid RSA key. The key type does not correspond to a RSA key'); } if (! isset($data[self::DATA_N], $data[self::DATA_E])) { throw new InvalidArgumentException('Invalid RSA key. The modulus or the exponent is missing'); } } /** * @param array<int|string, mixed> $data */ public static function create(array $data): self { return new self($data); } public function n(): string { return $this->get(self::DATA_N); } public function e(): string { return $this->get(self::DATA_E); } public function d(): string { $this->checkKeyIsPrivate(); return $this->get(self::DATA_D); } public function p(): string { $this->checkKeyIsPrivate(); return $this->get(self::DATA_P); } public function q(): string { $this->checkKeyIsPrivate(); return $this->get(self::DATA_Q); } public function dP(): string { $this->checkKeyIsPrivate(); return $this->get(self::DATA_DP); } public function dQ(): string { $this->checkKeyIsPrivate(); return $this->get(self::DATA_DQ); } public function QInv(): string { $this->checkKeyIsPrivate(); return $this->get(self::DATA_QI); } /** * @return array<mixed> */ public function other(): array { $this->checkKeyIsPrivate(); return $this->get(self::DATA_OTHER); } public function rI(): string { $this->checkKeyIsPrivate(); return $this->get(self::DATA_RI); } public function dI(): string { $this->checkKeyIsPrivate(); return $this->get(self::DATA_DI); } public function tI(): string { $this->checkKeyIsPrivate(); return $this->get(self::DATA_TI); } public function hasPrimes(): bool { return $this->has(self::DATA_P) && $this->has(self::DATA_Q); } /** * @return string[] */ public function primes(): array { return [$this->p(), $this->q()]; } public function hasExponents(): bool { return $this->has(self::DATA_DP) && $this->has(self::DATA_DQ); } /** * @return string[] */ public function exponents(): array { return [$this->dP(), $this->dQ()]; } public function hasCoefficient(): bool { return $this->has(self::DATA_QI); } public function isPublic(): bool { return ! $this->isPrivate(); } public function isPrivate(): bool { return array_key_exists(self::DATA_D, $this->getData()); } public function asPem(): string { if ($this->isPrivate()) { $privateKey = RSAPrivateKey::create( $this->binaryToBigInteger($this->n()), $this->binaryToBigInteger($this->e()), $this->binaryToBigInteger($this->d()), $this->binaryToBigInteger($this->p()), $this->binaryToBigInteger($this->q()), $this->binaryToBigInteger($this->dP()), $this->binaryToBigInteger($this->dQ()), $this->binaryToBigInteger($this->QInv()) ); return $privateKey->toPEM() ->string(); } $publicKey = RSAPublicKey::create( $this->binaryToBigInteger($this->n()), $this->binaryToBigInteger($this->e()) ); $rsaKey = PublicKeyInfo::fromPublicKey($publicKey); return $rsaKey->toPEM() ->string(); } public function toPublic(): static { $toBeRemoved = [ self::DATA_D, self::DATA_P, self::DATA_Q, self::DATA_DP, self::DATA_DQ, self::DATA_QI, self::DATA_OTHER, self::DATA_RI, self::DATA_DI, self::DATA_TI, ]; $data = $this->getData(); foreach ($data as $k => $v) { if (in_array($k, $toBeRemoved, true)) { unset($data[$k]); } } return new static($data); } private function checkKeyIsPrivate(): void { if (! $this->isPrivate()) { throw new InvalidArgumentException('The key is not private.'); } } private function binaryToBigInteger(string $data): string { $res = unpack('H*', $data); $res = current($res); return BigInteger::fromBase($res, 16)->toBase(10); } } PK ! ��� src/Key/Ec2Key.phpnu �[��� <?php declare(strict_types=1); namespace Cose\Key; use InvalidArgumentException; use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence; use SpomkyLabs\Pki\ASN1\Type\Primitive\BitString; use SpomkyLabs\Pki\ASN1\Type\Primitive\Integer; use SpomkyLabs\Pki\ASN1\Type\Primitive\ObjectIdentifier; use SpomkyLabs\Pki\ASN1\Type\Primitive\OctetString; use SpomkyLabs\Pki\ASN1\Type\Tagged\ExplicitlyTaggedType; use function array_key_exists; use function in_array; use function is_int; use function sprintf; use function strlen; /** * @final * @see \Cose\Tests\Key\Ec2KeyTest */ class Ec2Key extends Key { final public const CURVE_P256 = 1; final public const CURVE_P256K = 8; final public const CURVE_P384 = 2; final public const CURVE_P521 = 3; final public const CURVE_NAME_P256 = 'P-256'; final public const CURVE_NAME_P256K = 'P-256K'; final public const CURVE_NAME_P384 = 'P-384'; final public const CURVE_NAME_P521 = 'P-521'; final public const DATA_CURVE = -1; final public const DATA_X = -2; final public const DATA_Y = -3; final public const DATA_D = -4; private const SUPPORTED_CURVES_INT = [self::CURVE_P256, self::CURVE_P256K, self::CURVE_P384, self::CURVE_P521]; private const SUPPORTED_CURVES_NAMES = [ self::CURVE_NAME_P256, self::CURVE_NAME_P256K, self::CURVE_NAME_P384, self::CURVE_NAME_P521, ]; private const NAMED_CURVE_OID = [ self::CURVE_P256 => '1.2.840.10045.3.1.7', // NIST P-256 / secp256r1 self::CURVE_P256K => '1.3.132.0.10', // NIST P-256K / secp256k1 self::CURVE_P384 => '1.3.132.0.34', // NIST P-384 / secp384r1 self::CURVE_P521 => '1.3.132.0.35', // NIST P-521 / secp521r1 ]; private const CURVE_KEY_LENGTH = [ self::CURVE_P256 => 32, self::CURVE_P256K => 32, self::CURVE_P384 => 48, self::CURVE_P521 => 66, self::CURVE_NAME_P256 => 32, self::CURVE_NAME_P256K => 32, self::CURVE_NAME_P384 => 48, self::CURVE_NAME_P521 => 66, ]; /** * @param array<int|string, mixed> $data */ public function __construct(array $data) { foreach ([self::DATA_CURVE, self::TYPE] as $key) { if (is_numeric($data[$key])) { $data[$key] = (int) $data[$key]; } } parent::__construct($data); if ($data[self::TYPE] !== self::TYPE_EC2 && $data[self::TYPE] !== self::TYPE_NAME_EC2) { throw new InvalidArgumentException('Invalid EC2 key. The key type does not correspond to an EC2 key'); } if (! isset($data[self::DATA_CURVE], $data[self::DATA_X], $data[self::DATA_Y])) { throw new InvalidArgumentException('Invalid EC2 key. The curve or the "x/y" coordinates are missing'); } if (strlen((string) $data[self::DATA_X]) !== self::CURVE_KEY_LENGTH[$data[self::DATA_CURVE]]) { throw new InvalidArgumentException('Invalid length for x coordinate'); } if (strlen((string) $data[self::DATA_Y]) !== self::CURVE_KEY_LENGTH[$data[self::DATA_CURVE]]) { throw new InvalidArgumentException('Invalid length for y coordinate'); } if (is_int($data[self::DATA_CURVE])) { if (! in_array($data[self::DATA_CURVE], self::SUPPORTED_CURVES_INT, true)) { throw new InvalidArgumentException('The curve is not supported'); } } elseif (! in_array($data[self::DATA_CURVE], self::SUPPORTED_CURVES_NAMES, true)) { throw new InvalidArgumentException('The curve is not supported'); } } /** * @param array<int|string, mixed> $data */ public static function create(array $data): self { return new self($data); } public function toPublic(): self { $data = $this->getData(); unset($data[self::DATA_D]); return new self($data); } public function x(): string { return $this->get(self::DATA_X); } public function y(): string { return $this->get(self::DATA_Y); } public function isPrivate(): bool { return array_key_exists(self::DATA_D, $this->getData()); } public function d(): string { if (! $this->isPrivate()) { throw new InvalidArgumentException('The key is not private.'); } return $this->get(self::DATA_D); } public function curve(): int|string { return $this->get(self::DATA_CURVE); } public function asPEM(): string { if ($this->isPrivate()) { $der = Sequence::create( Integer::create(1), OctetString::create($this->d()), ExplicitlyTaggedType::create(0, ObjectIdentifier::create($this->getCurveOid())), ExplicitlyTaggedType::create(1, BitString::create($this->getUncompressedCoordinates())), ); return $this->pem('EC PRIVATE KEY', $der->toDER()); } $der = Sequence::create( Sequence::create( ObjectIdentifier::create('1.2.840.10045.2.1'), ObjectIdentifier::create($this->getCurveOid()) ), BitString::create($this->getUncompressedCoordinates()) ); return $this->pem('PUBLIC KEY', $der->toDER()); } public function getUncompressedCoordinates(): string { return "\x04" . $this->x() . $this->y(); } private function getCurveOid(): string { return self::NAMED_CURVE_OID[$this->curve()]; } private function pem(string $type, string $der): string { return sprintf("-----BEGIN %s-----\n", strtoupper($type)) . chunk_split(base64_encode($der), 64, "\n") . sprintf("-----END %s-----\n", strtoupper($type)); } } PK ! �jh�G G src/Key/OkpKey.phpnu �[��� <?php declare(strict_types=1); namespace Cose\Key; use InvalidArgumentException; use function array_key_exists; use function in_array; /** * @final * @see \Cose\Tests\Key\OkpKeyTest */ class OkpKey extends Key { final public const CURVE_X25519 = 4; final public const CURVE_X448 = 5; final public const CURVE_ED25519 = 6; final public const CURVE_ED448 = 7; final public const CURVE_NAME_X25519 = 'X25519'; final public const CURVE_NAME_X448 = 'X448'; final public const CURVE_NAME_ED25519 = 'Ed25519'; final public const CURVE_NAME_ED448 = 'Ed448'; final public const DATA_CURVE = -1; final public const DATA_X = -2; final public const DATA_D = -4; private const SUPPORTED_CURVES_INT = [ self::CURVE_X25519, self::CURVE_X448, self::CURVE_ED25519, self::CURVE_ED448, ]; private const SUPPORTED_CURVES_NAME = [ self::CURVE_NAME_X25519, self::CURVE_NAME_X448, self::CURVE_NAME_ED25519, self::CURVE_NAME_ED448, ]; /** * @param array<int|string, mixed> $data */ public function __construct(array $data) { foreach ([self::DATA_CURVE, self::TYPE] as $key) { if (is_numeric($data[$key])) { $data[$key] = (int) $data[$key]; } } parent::__construct($data); if ($data[self::TYPE] !== self::TYPE_OKP && $data[self::TYPE] !== self::TYPE_NAME_OKP) { throw new InvalidArgumentException('Invalid OKP key. The key type does not correspond to an OKP key'); } if (! isset($data[self::DATA_CURVE], $data[self::DATA_X])) { throw new InvalidArgumentException('Invalid EC2 key. The curve or the "x" coordinate is missing'); } if (is_numeric($data[self::DATA_CURVE])) { if (! in_array((int) $data[self::DATA_CURVE], self::SUPPORTED_CURVES_INT, true)) { throw new InvalidArgumentException('The curve is not supported'); } } elseif (! in_array($data[self::DATA_CURVE], self::SUPPORTED_CURVES_NAME, true)) { throw new InvalidArgumentException('The curve is not supported'); } } /** * @param array<int|string, mixed> $data */ public static function create(array $data): self { return new self($data); } public function x(): string { return $this->get(self::DATA_X); } public function isPrivate(): bool { return array_key_exists(self::DATA_D, $this->getData()); } public function d(): string { if (! $this->isPrivate()) { throw new InvalidArgumentException('The key is not private.'); } return $this->get(self::DATA_D); } public function curve(): int|string { return $this->get(self::DATA_CURVE); } } PK ! 8�~+� � src/BigInteger.phpnu �[��� <?php declare(strict_types=1); namespace Cose; use Brick\Math\BigInteger as BrickBigInteger; use function chr; use function hex2bin; use function strlen; use function unpack; /** * @internal */ final class BigInteger { private function __construct( private readonly BrickBigInteger $value ) { } public static function createFromBinaryString(string $value): self { $res = unpack('H*', $value); $data = current($res); return new self(BrickBigInteger::fromBase($data, 16)); } public static function createFromDecimal(int $value): self { return new self(BrickBigInteger::of($value)); } /** * Converts a BigInteger to a binary string. */ public function toBytes(): string { if ($this->value->isEqualTo(BrickBigInteger::zero())) { return ''; } $temp = $this->value->toBase(16); $temp = 0 !== (strlen($temp) & 1) ? '0' . $temp : $temp; $temp = hex2bin($temp); return ltrim($temp, chr(0)); } /** * Adds two BigIntegers. */ public function add(self $y): self { $value = $this->value->plus($y->value); return new self($value); } /** * Subtracts two BigIntegers. */ public function subtract(self $y): self { $value = $this->value->minus($y->value); return new self($value); } /** * Multiplies two BigIntegers. */ public function multiply(self $x): self { $value = $this->value->multipliedBy($x->value); return new self($value); } /** * Performs modular exponentiation. */ public function modPow(self $e, self $n): self { $value = $this->value->modPow($e->value, $n->value); return new self($value); } /** * Performs modular exponentiation. */ public function mod(self $d): self { $value = $this->value->mod($d->value); return new self($value); } /** * Compares two numbers. */ public function compare(self $y): int { return $this->value->compareTo($y->value); } } PK ! �H�% % src/Algorithms.phpnu �[��� <?php declare(strict_types=1); namespace Cose; use InvalidArgumentException; use function array_key_exists; use const OPENSSL_ALGO_SHA1; use const OPENSSL_ALGO_SHA256; use const OPENSSL_ALGO_SHA384; use const OPENSSL_ALGO_SHA512; /** * @see https://www.iana.org/assignments/cose/cose.xhtml#algorithms */ abstract class Algorithms { final public const COSE_ALGORITHM_AES_CCM_64_128_256 = 33; final public const COSE_ALGORITHM_AES_CCM_64_128_128 = 32; final public const COSE_ALGORITHM_AES_CCM_16_128_256 = 31; final public const COSE_ALGORITHM_AES_CCM_16_128_128 = 30; final public const COSE_ALGORITHM_AES_MAC_256_128 = 26; final public const COSE_ALGORITHM_AES_MAC_128_128 = 25; final public const COSE_ALGORITHM_CHACHA20_POLY1305 = 24; final public const COSE_ALGORITHM_AES_MAC_256_64 = 15; final public const COSE_ALGORITHM_AES_MAC_128_64 = 14; final public const COSE_ALGORITHM_AES_CCM_64_64_256 = 13; final public const COSE_ALGORITHM_AES_CCM_64_64_128 = 12; final public const COSE_ALGORITHM_AES_CCM_16_64_256 = 11; final public const COSE_ALGORITHM_AES_CCM_16_64_128 = 10; final public const COSE_ALGORITHM_HS512 = 7; final public const COSE_ALGORITHM_HS384 = 6; final public const COSE_ALGORITHM_HS256 = 5; final public const COSE_ALGORITHM_HS256_64 = 4; final public const COSE_ALGORITHM_A256GCM = 3; final public const COSE_ALGORITHM_A192GCM = 2; final public const COSE_ALGORITHM_A128GCM = 1; final public const COSE_ALGORITHM_A128KW = -3; final public const COSE_ALGORITHM_A192KW = -4; final public const COSE_ALGORITHM_A256KW = -5; final public const COSE_ALGORITHM_DIRECT = -6; final public const COSE_ALGORITHM_ES256 = -7; /** * @deprecated since v4.0.6. Please use COSE_ALGORITHM_EDDSA instead. Will be removed in v5.0.0 */ final public const COSE_ALGORITHM_EdDSA = -8; final public const COSE_ALGORITHM_EDDSA = -8; final public const COSE_ALGORITHM_ED256 = -260; final public const COSE_ALGORITHM_ED512 = -261; final public const COSE_ALGORITHM_DIRECT_HKDF_SHA_256 = -10; final public const COSE_ALGORITHM_DIRECT_HKDF_SHA_512 = -11; final public const COSE_ALGORITHM_DIRECT_HKDF_AES_128 = -12; final public const COSE_ALGORITHM_DIRECT_HKDF_AES_256 = -13; final public const COSE_ALGORITHM_ECDH_ES_HKDF_256 = -25; final public const COSE_ALGORITHM_ECDH_ES_HKDF_512 = -26; final public const COSE_ALGORITHM_ECDH_SS_HKDF_256 = -27; final public const COSE_ALGORITHM_ECDH_SS_HKDF_512 = -28; final public const COSE_ALGORITHM_ECDH_ES_A128KW = -29; final public const COSE_ALGORITHM_ECDH_ES_A192KW = -30; final public const COSE_ALGORITHM_ECDH_ES_A256KW = -31; final public const COSE_ALGORITHM_ECDH_SS_A128KW = -32; final public const COSE_ALGORITHM_ECDH_SS_A192KW = -33; final public const COSE_ALGORITHM_ECDH_SS_A256KW = -34; final public const COSE_ALGORITHM_ES384 = -35; final public const COSE_ALGORITHM_ES512 = -36; final public const COSE_ALGORITHM_PS256 = -37; final public const COSE_ALGORITHM_PS384 = -38; final public const COSE_ALGORITHM_PS512 = -39; final public const COSE_ALGORITHM_RSAES_OAEP = -40; final public const COSE_ALGORITHM_RSAES_OAEP_256 = -41; final public const COSE_ALGORITHM_RSAES_OAEP_512 = -42; final public const COSE_ALGORITHM_ES256K = -46; final public const COSE_ALGORITHM_RS256 = -257; final public const COSE_ALGORITHM_RS384 = -258; final public const COSE_ALGORITHM_RS512 = -259; final public const COSE_ALGORITHM_RS1 = -65535; final public const COSE_ALGORITHM_MAP = [ self::COSE_ALGORITHM_ES256 => OPENSSL_ALGO_SHA256, self::COSE_ALGORITHM_ES384 => OPENSSL_ALGO_SHA384, self::COSE_ALGORITHM_ES512 => OPENSSL_ALGO_SHA512, self::COSE_ALGORITHM_RS256 => OPENSSL_ALGO_SHA256, self::COSE_ALGORITHM_RS384 => OPENSSL_ALGO_SHA384, self::COSE_ALGORITHM_RS512 => OPENSSL_ALGO_SHA512, self::COSE_ALGORITHM_RS1 => OPENSSL_ALGO_SHA1, ]; final public const COSE_HASH_MAP = [ self::COSE_ALGORITHM_ES256K => 'sha256', self::COSE_ALGORITHM_ES256 => 'sha256', self::COSE_ALGORITHM_ES384 => 'sha384', self::COSE_ALGORITHM_ES512 => 'sha512', self::COSE_ALGORITHM_RS256 => 'sha256', self::COSE_ALGORITHM_RS384 => 'sha384', self::COSE_ALGORITHM_RS512 => 'sha512', self::COSE_ALGORITHM_PS256 => 'sha256', self::COSE_ALGORITHM_PS384 => 'sha384', self::COSE_ALGORITHM_PS512 => 'sha512', self::COSE_ALGORITHM_RS1 => 'sha1', ]; public static function getOpensslAlgorithmFor(int $algorithmIdentifier): int { if (! array_key_exists($algorithmIdentifier, self::COSE_ALGORITHM_MAP)) { throw new InvalidArgumentException('The specified algorithm identifier is not supported'); } return self::COSE_ALGORITHM_MAP[$algorithmIdentifier]; } public static function getHashAlgorithmFor(int $algorithmIdentifier): string { if (! array_key_exists($algorithmIdentifier, self::COSE_HASH_MAP)) { throw new InvalidArgumentException('The specified algorithm identifier is not supported'); } return self::COSE_HASH_MAP[$algorithmIdentifier]; } } PK ! `p.� src/Hash.phpnu �[��� <?php declare(strict_types=1); namespace Cose; /** * @internal */ final class Hash { private function __construct( private readonly string $hash, private readonly int $length, private readonly string $t ) { } public static function sha1(): self { return new self('sha1', 20, "\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14"); } public static function sha256(): self { return new self('sha256', 32, "\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01\x05\x00\x04\x20"); } public static function sha384(): self { return new self('sha384', 48, "\x30\x41\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x02\x05\x00\x04\x30"); } public static function sha512(): self { return new self('sha512', 64, "\x30\x51\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x03\x05\x00\x04\x40"); } public function getLength(): int { return $this->length; } /** * Compute the HMAC. */ public function hash(string $text): string { return hash($this->hash, $text, true); } public function name(): string { return $this->hash; } public function t(): string { return $this->t; } } PK ! �X&_� � src/Algorithm/Manager.phpnu �[��� <?php declare(strict_types=1); namespace Cose\Algorithm; use InvalidArgumentException; use function array_key_exists; final class Manager { /** * @var array<int, Algorithm> */ private array $algorithms = []; public static function create(): self { return new self(); } public function add(Algorithm ...$algorithms): self { foreach ($algorithms as $algorithm) { $identifier = $algorithm::identifier(); $this->algorithms[$identifier] = $algorithm; } return $this; } /** * @return iterable<int> */ public function list(): iterable { yield from array_keys($this->algorithms); } /** * @return iterable<int, Algorithm> */ public function all(): iterable { yield from $this->algorithms; } public function has(int $identifier): bool { return array_key_exists($identifier, $this->algorithms); } public function get(int $identifier): Algorithm { if (! $this->has($identifier)) { throw new InvalidArgumentException('Unsupported algorithm'); } return $this->algorithms[$identifier]; } } PK ! gd'Q� � src/Algorithm/ManagerFactory.phpnu �[��� <?php declare(strict_types=1); namespace Cose\Algorithm; use InvalidArgumentException; use function array_key_exists; use function sprintf; final class ManagerFactory { /** * @var array<string, Algorithm> */ private array $algorithms = []; public static function create(): self { return new self(); } public function add(string $alias, Algorithm $algorithm): self { $this->algorithms[$alias] = $algorithm; return $this; } /** * @return string[] */ public function list(): iterable { yield from array_keys($this->algorithms); } /** * @return Algorithm[] */ public function all(): iterable { yield from $this->algorithms; } public function generate(string ...$aliases): Manager { $manager = Manager::create(); foreach ($aliases as $alias) { if (! array_key_exists($alias, $this->algorithms)) { throw new InvalidArgumentException(sprintf('The algorithm with alias "%s" is not supported', $alias)); } $manager->add($this->algorithms[$alias]); } return $manager; } } PK ! �rԎ� � src/Algorithm/Algorithm.phpnu �[��� <?php declare(strict_types=1); namespace Cose\Algorithm; interface Algorithm { public static function identifier(): int; } PK ! 7z�) ) % src/Algorithm/Signature/Signature.phpnu �[��� <?php declare(strict_types=1); namespace Cose\Algorithm\Signature; use Cose\Algorithm\Algorithm; use Cose\Key\Key; interface Signature extends Algorithm { public function sign(string $data, Key $key): string; public function verify(string $data, Key $key, string $signature): bool; } PK ! �4�� � '