diff options
author | Mario <mario@mariovavti.com> | 2020-11-27 08:04:00 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2020-11-27 08:04:00 +0000 |
commit | f4bb7bcbff3770387c2fecfa91ce4a60b916a474 (patch) | |
tree | ea007e664d435f1f3d63c87bfe1600484d2bd46c /vendor/ramsey/uuid/src/Generator | |
parent | 07e5b8295ea9d342f66d8119d88bd58124b548e6 (diff) | |
download | volse-hubzilla-f4bb7bcbff3770387c2fecfa91ce4a60b916a474.tar.gz volse-hubzilla-f4bb7bcbff3770387c2fecfa91ce4a60b916a474.tar.bz2 volse-hubzilla-f4bb7bcbff3770387c2fecfa91ce4a60b916a474.zip |
update composer libs
Diffstat (limited to 'vendor/ramsey/uuid/src/Generator')
19 files changed, 605 insertions, 344 deletions
diff --git a/vendor/ramsey/uuid/src/Generator/CombGenerator.php b/vendor/ramsey/uuid/src/Generator/CombGenerator.php index 1d4a5f604..88ae6ea23 100644 --- a/vendor/ramsey/uuid/src/Generator/CombGenerator.php +++ b/vendor/ramsey/uuid/src/Generator/CombGenerator.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,27 +8,58 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ +declare(strict_types=1); + namespace Ramsey\Uuid\Generator; -use Exception; -use InvalidArgumentException; use Ramsey\Uuid\Converter\NumberConverterInterface; -use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; +use Ramsey\Uuid\Exception\InvalidArgumentException; + +use function bin2hex; +use function explode; +use function hex2bin; +use function microtime; +use function str_pad; +use function substr; + +use const STR_PAD_LEFT; /** - * CombGenerator provides functionality to generate COMB (combined GUID/timestamp) - * sequential UUIDs + * CombGenerator generates COMBs (combined UUID/timestamp) + * + * The CombGenerator, when used with the StringCodec (and, by proxy, the + * TimestampLastCombCodec) or the TimestampFirstCombCodec, combines the current + * timestamp with a UUID (hence the name "COMB"). The timestamp either appears + * as the first or last 48 bits of the COMB, depending on the codec used. + * + * By default, COMBs will have the timestamp set as the last 48 bits of the + * identifier. + * + * ``` php + * $factory = new UuidFactory(); + * + * $factory->setRandomGenerator(new CombGenerator( + * $factory->getRandomGenerator(), + * $factory->getNumberConverter() + * )); + * + * $comb = $factory->uuid4(); + * ``` * - * @link https://en.wikipedia.org/wiki/Globally_unique_identifier#Sequential_algorithms + * To generate a COMB with the timestamp as the first 48 bits, set the + * TimestampFirstCombCodec as the codec. + * + * ``` php + * $factory->setCodec(new TimestampFirstCombCodec($factory->getUuidBuilder())); + * ``` + * + * @link https://www.informit.com/articles/printerfriendly/25862 The Cost of GUIDs as Primary Keys */ class CombGenerator implements RandomGeneratorInterface { - const TIMESTAMP_BYTES = 6; + public const TIMESTAMP_BYTES = 6; /** * @var RandomGeneratorInterface @@ -39,50 +71,54 @@ class CombGenerator implements RandomGeneratorInterface */ private $converter; - /** - * Constructs a `CombGenerator` using a random-number generator and a number converter - * - * @param RandomGeneratorInterface $generator Random-number generator for the non-time part. - * @param NumberConverterInterface $numberConverter Instance of number converter. - */ - public function __construct(RandomGeneratorInterface $generator, NumberConverterInterface $numberConverter) - { + public function __construct( + RandomGeneratorInterface $generator, + NumberConverterInterface $numberConverter + ) { $this->converter = $numberConverter; $this->randomGenerator = $generator; } /** - * Generates a string of binary data of the specified length + * @throws InvalidArgumentException if $length is not a positive integer + * greater than or equal to CombGenerator::TIMESTAMP_BYTES * - * @param integer $length The number of bytes of random binary data to generate - * @return string A binary string - * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present - * @throws InvalidArgumentException if length is not a positive integer - * @throws Exception + * @inheritDoc */ - public function generate($length) + public function generate(int $length): string { if ($length < self::TIMESTAMP_BYTES || $length < 0) { - throw new InvalidArgumentException('Length must be a positive integer.'); + throw new InvalidArgumentException( + 'Length must be a positive integer greater than or equal to ' . self::TIMESTAMP_BYTES + ); } $hash = ''; - if (self::TIMESTAMP_BYTES > 0 && $length > self::TIMESTAMP_BYTES) { $hash = $this->randomGenerator->generate($length - self::TIMESTAMP_BYTES); } - $lsbTime = str_pad($this->converter->toHex($this->timestamp()), self::TIMESTAMP_BYTES * 2, '0', STR_PAD_LEFT); + $lsbTime = str_pad( + $this->converter->toHex($this->timestamp()), + self::TIMESTAMP_BYTES * 2, + '0', + STR_PAD_LEFT + ); - return hex2bin(str_pad(bin2hex($hash), $length - self::TIMESTAMP_BYTES, '0') . $lsbTime); + return (string) hex2bin( + str_pad( + bin2hex((string) $hash), + $length - self::TIMESTAMP_BYTES, + '0' + ) + . $lsbTime + ); } /** - * Returns current timestamp as integer, precise to 0.00001 seconds - * - * @return string + * Returns current timestamp a string integer, precise to 0.00001 seconds */ - private function timestamp() + private function timestamp(): string { $time = explode(' ', microtime(false)); diff --git a/vendor/ramsey/uuid/src/Generator/DceSecurityGenerator.php b/vendor/ramsey/uuid/src/Generator/DceSecurityGenerator.php new file mode 100644 index 000000000..a3f07f2ff --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/DceSecurityGenerator.php @@ -0,0 +1,161 @@ +<?php + +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Exception\DceSecurityException; +use Ramsey\Uuid\Provider\DceSecurityProviderInterface; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use Ramsey\Uuid\Uuid; + +use function hex2bin; +use function in_array; +use function pack; +use function str_pad; +use function strlen; +use function substr_replace; + +use const STR_PAD_LEFT; + +/** + * DceSecurityGenerator generates strings of binary data based on a local + * domain, local identifier, node ID, clock sequence, and the current time + */ +class DceSecurityGenerator implements DceSecurityGeneratorInterface +{ + private const DOMAINS = [ + Uuid::DCE_DOMAIN_PERSON, + Uuid::DCE_DOMAIN_GROUP, + Uuid::DCE_DOMAIN_ORG, + ]; + + /** + * Upper bounds for the clock sequence in DCE Security UUIDs. + */ + private const CLOCK_SEQ_HIGH = 63; + + /** + * Lower bounds for the clock sequence in DCE Security UUIDs. + */ + private const CLOCK_SEQ_LOW = 0; + + /** + * @var NumberConverterInterface + */ + private $numberConverter; + + /** + * @var TimeGeneratorInterface + */ + private $timeGenerator; + + /** + * @var DceSecurityProviderInterface + */ + private $dceSecurityProvider; + + public function __construct( + NumberConverterInterface $numberConverter, + TimeGeneratorInterface $timeGenerator, + DceSecurityProviderInterface $dceSecurityProvider + ) { + $this->numberConverter = $numberConverter; + $this->timeGenerator = $timeGenerator; + $this->dceSecurityProvider = $dceSecurityProvider; + } + + public function generate( + int $localDomain, + ?IntegerObject $localIdentifier = null, + ?Hexadecimal $node = null, + ?int $clockSeq = null + ): string { + if (!in_array($localDomain, self::DOMAINS)) { + throw new DceSecurityException( + 'Local domain must be a valid DCE Security domain' + ); + } + + if ($localIdentifier && $localIdentifier->isNegative()) { + throw new DceSecurityException( + 'Local identifier out of bounds; it must be a value between 0 and 4294967295' + ); + } + + if ($clockSeq > self::CLOCK_SEQ_HIGH || $clockSeq < self::CLOCK_SEQ_LOW) { + throw new DceSecurityException( + 'Clock sequence out of bounds; it must be a value between 0 and 63' + ); + } + + switch ($localDomain) { + case Uuid::DCE_DOMAIN_ORG: + if ($localIdentifier === null) { + throw new DceSecurityException( + 'A local identifier must be provided for the org domain' + ); + } + + break; + case Uuid::DCE_DOMAIN_PERSON: + if ($localIdentifier === null) { + $localIdentifier = $this->dceSecurityProvider->getUid(); + } + + break; + case Uuid::DCE_DOMAIN_GROUP: + default: + if ($localIdentifier === null) { + $localIdentifier = $this->dceSecurityProvider->getGid(); + } + + break; + } + + $identifierHex = $this->numberConverter->toHex($localIdentifier->toString()); + + // The maximum value for the local identifier is 0xffffffff, or + // 4294967295. This is 8 hexadecimal digits, so if the length of + // hexadecimal digits is greater than 8, we know the value is greater + // than 0xffffffff. + if (strlen($identifierHex) > 8) { + throw new DceSecurityException( + 'Local identifier out of bounds; it must be a value between 0 and 4294967295' + ); + } + + $domainByte = pack('n', $localDomain)[1]; + $identifierBytes = hex2bin(str_pad($identifierHex, 8, '0', STR_PAD_LEFT)); + + if ($node instanceof Hexadecimal) { + $node = $node->toString(); + } + + // Shift the clock sequence 8 bits to the left, so it matches 0x3f00. + if ($clockSeq !== null) { + $clockSeq = $clockSeq << 8; + } + + /** @var string $bytes */ + $bytes = $this->timeGenerator->generate($node, $clockSeq); + + // Replace bytes in the time-based UUID with DCE Security values. + $bytes = substr_replace($bytes, $identifierBytes, 0, 4); + $bytes = substr_replace($bytes, $domainByte, 9, 1); + + return $bytes; + } +} diff --git a/vendor/ramsey/uuid/src/Generator/DceSecurityGeneratorInterface.php b/vendor/ramsey/uuid/src/Generator/DceSecurityGeneratorInterface.php new file mode 100644 index 000000000..faa29a53d --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/DceSecurityGeneratorInterface.php @@ -0,0 +1,53 @@ +<?php + +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Rfc4122\UuidV2; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; + +/** + * A DCE Security generator generates strings of binary data based on a local + * domain, local identifier, node ID, clock sequence, and the current time + * + * @see UuidV2 + */ +interface DceSecurityGeneratorInterface +{ + /** + * Generate a binary string from a local domain, local identifier, node ID, + * clock sequence, and current time + * + * @param int $localDomain The local domain to use when generating bytes, + * according to DCE Security + * @param IntegerObject|null $localIdentifier The local identifier for the + * given domain; this may be a UID or GID on POSIX systems, if the local + * domain is person or group, or it may be a site-defined identifier + * if the local domain is org + * @param Hexadecimal|null $node A 48-bit number representing the hardware + * address + * @param int|null $clockSeq A 14-bit number used to help avoid duplicates + * that could arise when the clock is set backwards in time or if the + * node ID changes + * + * @return string A binary string + */ + public function generate( + int $localDomain, + ?IntegerObject $localIdentifier = null, + ?Hexadecimal $node = null, + ?int $clockSeq = null + ): string; +} diff --git a/vendor/ramsey/uuid/src/Generator/DefaultNameGenerator.php b/vendor/ramsey/uuid/src/Generator/DefaultNameGenerator.php new file mode 100644 index 000000000..270e8fbe1 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/DefaultNameGenerator.php @@ -0,0 +1,43 @@ +<?php + +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Exception\NameException; +use Ramsey\Uuid\UuidInterface; + +use function hash; + +/** + * DefaultNameGenerator generates strings of binary data based on a namespace, + * name, and hashing algorithm + */ +class DefaultNameGenerator implements NameGeneratorInterface +{ + /** @psalm-pure */ + public function generate(UuidInterface $ns, string $name, string $hashAlgorithm): string + { + /** @var string|bool $bytes */ + $bytes = @hash($hashAlgorithm, $ns->getBytes() . $name, true); + + if ($bytes === false) { + throw new NameException(sprintf( + 'Unable to hash namespace and name with algorithm \'%s\'', + $hashAlgorithm + )); + } + + return (string) $bytes; + } +} diff --git a/vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php b/vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php index 5c5ccb294..d245c7bcc 100644 --- a/vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php +++ b/vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,25 +8,35 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ +declare(strict_types=1); + namespace Ramsey\Uuid\Generator; -use Exception; -use InvalidArgumentException; -use Ramsey\Uuid\BinaryUtils; use Ramsey\Uuid\Converter\TimeConverterInterface; -use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; +use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Exception\RandomSourceException; +use Ramsey\Uuid\Exception\TimeSourceException; use Ramsey\Uuid\Provider\NodeProviderInterface; use Ramsey\Uuid\Provider\TimeProviderInterface; +use Ramsey\Uuid\Type\Hexadecimal; +use Throwable; + +use function ctype_xdigit; +use function dechex; +use function hex2bin; +use function is_int; +use function pack; +use function sprintf; +use function str_pad; +use function strlen; + +use const STR_PAD_LEFT; /** - * DefaultTimeGenerator provides functionality to generate strings of binary - * data for version 1 UUIDs based on a host ID, sequence number, and the current - * time + * DefaultTimeGenerator generates strings of binary data based on a node ID, + * clock sequence, and the current time */ class DefaultTimeGenerator implements TimeGeneratorInterface { @@ -44,14 +55,6 @@ class DefaultTimeGenerator implements TimeGeneratorInterface */ private $timeProvider; - /** - * Constructs a `DefaultTimeGenerator` using a node provider, time converter, - * and time provider - * - * @param NodeProviderInterface $nodeProvider - * @param TimeConverterInterface $timeConverter - * @param TimeProviderInterface $timeProvider - */ public function __construct( NodeProviderInterface $nodeProvider, TimeConverterInterface $timeConverter, @@ -63,79 +66,82 @@ class DefaultTimeGenerator implements TimeGeneratorInterface } /** - * Generate a version 1 UUID from a host ID, sequence number, and the current time + * @throws InvalidArgumentException if the parameters contain invalid values + * @throws RandomSourceException if random_int() throws an exception/error * - * If $node is not given, we will attempt to obtain the local hardware - * address. If $clockSeq is given, it is used as the sequence number; - * otherwise a random 14-bit sequence number is chosen. - * - * @param int|string $node A 48-bit number representing the hardware address - * This number may be represented as an integer or a hexadecimal string. - * @param int $clockSeq A 14-bit number used to help avoid duplicates that - * could arise when the clock is set backwards in time or if the node ID - * changes. - * @return string A binary string - * @throws UnsatisfiedDependencyException if called on a 32-bit system and - * `Moontoast\Math\BigNumber` is not present - * @throws InvalidArgumentException - * @throws Exception if it was not possible to gather sufficient entropy + * @inheritDoc */ - public function generate($node = null, $clockSeq = null) + public function generate($node = null, ?int $clockSeq = null): string { + if ($node instanceof Hexadecimal) { + $node = $node->toString(); + } + $node = $this->getValidNode($node); if ($clockSeq === null) { - // Not using "stable storage"; see RFC 4122, Section 4.2.1.1 - $clockSeq = random_int(0, 0x3fff); + try { + // This does not use "stable storage"; see RFC 4122, Section 4.2.1.1. + $clockSeq = random_int(0, 0x3fff); + } catch (Throwable $exception) { + throw new RandomSourceException( + $exception->getMessage(), + (int) $exception->getCode(), + $exception + ); + } } - // Create a 60-bit time value as a count of 100-nanosecond intervals - // since 00:00:00.00, 15 October 1582 - $timeOfDay = $this->timeProvider->currentTime(); - $uuidTime = $this->timeConverter->calculateTime($timeOfDay['sec'], $timeOfDay['usec']); - - $timeHi = BinaryUtils::applyVersion($uuidTime['hi'], 1); - $clockSeqHi = BinaryUtils::applyVariant($clockSeq >> 8); - - $hex = vsprintf( - '%08s%04s%04s%02s%02s%012s', - [ - $uuidTime['low'], - $uuidTime['mid'], - sprintf('%04x', $timeHi), - sprintf('%02x', $clockSeqHi), - sprintf('%02x', $clockSeq & 0xff), - $node, - ] + $time = $this->timeProvider->getTime(); + + $uuidTime = $this->timeConverter->calculateTime( + $time->getSeconds()->toString(), + $time->getMicroseconds()->toString() ); - return hex2bin($hex); + $timeHex = str_pad($uuidTime->toString(), 16, '0', STR_PAD_LEFT); + + if (strlen($timeHex) !== 16) { + throw new TimeSourceException(sprintf( + 'The generated time of \'%s\' is larger than expected', + $timeHex + )); + } + + $timeBytes = (string) hex2bin($timeHex); + + return $timeBytes[4] . $timeBytes[5] . $timeBytes[6] . $timeBytes[7] + . $timeBytes[2] . $timeBytes[3] + . $timeBytes[0] . $timeBytes[1] + . pack('n*', $clockSeq) + . $node; } /** * Uses the node provider given when constructing this instance to get * the node ID (usually a MAC address) * - * @param string|int $node A node value that may be used to override the node provider - * @return string Hexadecimal representation of the node ID + * @param string|int|null $node A node value that may be used to override the node provider + * + * @return string 6-byte binary string representation of the node + * * @throws InvalidArgumentException - * @throws Exception */ - protected function getValidNode($node) + private function getValidNode($node): string { if ($node === null) { $node = $this->nodeProvider->getNode(); } - // Convert the node to hex, if it is still an integer + // Convert the node to hex, if it is still an integer. if (is_int($node)) { - $node = sprintf('%012x', $node); + $node = dechex($node); } - if (!ctype_xdigit($node) || strlen($node) > 12) { + if (!ctype_xdigit((string) $node) || strlen((string) $node) > 12) { throw new InvalidArgumentException('Invalid node value'); } - return strtolower(sprintf('%012s', $node)); + return (string) hex2bin(str_pad((string) $node, 12, '0', STR_PAD_LEFT)); } } diff --git a/vendor/ramsey/uuid/src/Generator/MtRandGenerator.php b/vendor/ramsey/uuid/src/Generator/MtRandGenerator.php deleted file mode 100644 index 8d4b5f9b9..000000000 --- a/vendor/ramsey/uuid/src/Generator/MtRandGenerator.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php -/** - * This file is part of the ramsey/uuid library - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> - * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub - */ - -namespace Ramsey\Uuid\Generator; - -/** - * MtRandRandomGenerator provides functionality to generate strings of random - * binary data using the `mt_rand()` PHP function - * - * @deprecated The mt_rand() function is not a reliable source of randomness. - * The default RandomBytesGenerator, which uses the random_bytes() function, - * is recommended as the safest and most reliable source of randomness. - * <em>This generator will be removed in ramsey/uuid 4.0.0.</em> - * @link http://php.net/mt_rand - */ -class MtRandGenerator implements RandomGeneratorInterface -{ - /** - * Generates a string of random binary data of the specified length - * - * @param integer $length The number of bytes of random binary data to generate - * @return string A binary string - */ - public function generate($length) - { - $bytes = ''; - - for ($i = 1; $i <= $length; $i++) { - $bytes = chr(mt_rand(0, 255)) . $bytes; - } - - return $bytes; - } -} diff --git a/vendor/ramsey/uuid/src/Generator/NameGeneratorFactory.php b/vendor/ramsey/uuid/src/Generator/NameGeneratorFactory.php new file mode 100644 index 000000000..6f08e2910 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/NameGeneratorFactory.php @@ -0,0 +1,30 @@ +<?php + +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +/** + * NameGeneratorFactory retrieves a default name generator, based on the + * environment + */ +class NameGeneratorFactory +{ + /** + * Returns a default name generator, based on the current environment + */ + public function getGenerator(): NameGeneratorInterface + { + return new DefaultNameGenerator(); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/NameGeneratorInterface.php b/vendor/ramsey/uuid/src/Generator/NameGeneratorInterface.php new file mode 100644 index 000000000..cc43dd029 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/NameGeneratorInterface.php @@ -0,0 +1,38 @@ +<?php + +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\UuidInterface; + +/** + * A name generator generates strings of binary data created by hashing together + * a namespace with a name, according to a hashing algorithm + */ +interface NameGeneratorInterface +{ + /** + * Generate a binary string from a namespace and name hashed together with + * the specified hashing algorithm + * + * @param UuidInterface $ns The namespace + * @param string $name The name to use for creating a UUID + * @param string $hashAlgorithm The hashing algorithm to use + * + * @return string A binary string + * + * @psalm-pure + */ + public function generate(UuidInterface $ns, string $name, string $hashAlgorithm): string; +} diff --git a/vendor/ramsey/uuid/src/Generator/OpenSslGenerator.php b/vendor/ramsey/uuid/src/Generator/OpenSslGenerator.php deleted file mode 100644 index 47abf9bb5..000000000 --- a/vendor/ramsey/uuid/src/Generator/OpenSslGenerator.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php -/** - * This file is part of the ramsey/uuid library - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> - * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub - */ - -namespace Ramsey\Uuid\Generator; - -/** - * OpenSslRandomGenerator provides functionality to generate strings of random - * binary data using the `openssl_random_pseudo_bytes()` PHP function - * - * The use of this generator requires PHP to be compiled using the - * `--with-openssl` option. - * - * @deprecated The openssl_random_pseudo_bytes() function is not a reliable - * source of randomness. The default RandomBytesGenerator, which uses the - * random_bytes() function, is recommended as the safest and most reliable - * source of randomness. - * <em>This generator will be removed in ramsey/uuid 4.0.0.</em> - * @link http://php.net/openssl_random_pseudo_bytes - */ -class OpenSslGenerator implements RandomGeneratorInterface -{ - /** - * Generates a string of random binary data of the specified length - * - * @param integer $length The number of bytes of random binary data to generate - * @return string A binary string - */ - public function generate($length) - { - return openssl_random_pseudo_bytes($length); - } -} diff --git a/vendor/ramsey/uuid/src/Generator/PeclUuidNameGenerator.php b/vendor/ramsey/uuid/src/Generator/PeclUuidNameGenerator.php new file mode 100644 index 000000000..93b786878 --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/PeclUuidNameGenerator.php @@ -0,0 +1,54 @@ +<?php + +/** + * This file is part of the ramsey/uuid library + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> + * @license http://opensource.org/licenses/MIT MIT + */ + +declare(strict_types=1); + +namespace Ramsey\Uuid\Generator; + +use Ramsey\Uuid\Exception\NameException; +use Ramsey\Uuid\UuidInterface; + +use function sprintf; +use function uuid_generate_md5; +use function uuid_generate_sha1; +use function uuid_parse; + +/** + * PeclUuidNameGenerator generates strings of binary data from a namespace and a + * name, using ext-uuid + * + * @link https://pecl.php.net/package/uuid ext-uuid + */ +class PeclUuidNameGenerator implements NameGeneratorInterface +{ + /** @psalm-pure */ + public function generate(UuidInterface $ns, string $name, string $hashAlgorithm): string + { + switch ($hashAlgorithm) { + case 'md5': + $uuid = (string) uuid_generate_md5($ns->toString(), $name); + + break; + case 'sha1': + $uuid = (string) uuid_generate_sha1($ns->toString(), $name); + + break; + default: + throw new NameException(sprintf( + 'Unable to hash namespace and name with algorithm \'%s\'', + $hashAlgorithm + )); + } + + return (string) uuid_parse($uuid); + } +} diff --git a/vendor/ramsey/uuid/src/Generator/PeclUuidRandomGenerator.php b/vendor/ramsey/uuid/src/Generator/PeclUuidRandomGenerator.php index fc2ef7e4d..df750f6a5 100644 --- a/vendor/ramsey/uuid/src/Generator/PeclUuidRandomGenerator.php +++ b/vendor/ramsey/uuid/src/Generator/PeclUuidRandomGenerator.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,28 +8,22 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ +declare(strict_types=1); + namespace Ramsey\Uuid\Generator; +use const UUID_TYPE_RANDOM; + /** - * PeclUuidRandomGenerator provides functionality to generate strings of random - * binary data using the PECL UUID PHP extension + * PeclUuidRandomGenerator generates strings of random binary data using ext-uuid * - * @link https://pecl.php.net/package/uuid + * @link https://pecl.php.net/package/uuid ext-uuid */ class PeclUuidRandomGenerator implements RandomGeneratorInterface { - /** - * Generates a string of random binary data of the specified length - * - * @param integer $length The number of bytes of random binary data to generate - * @return string A binary string - */ - public function generate($length) + public function generate(int $length): string { $uuid = uuid_create(UUID_TYPE_RANDOM); diff --git a/vendor/ramsey/uuid/src/Generator/PeclUuidTimeGenerator.php b/vendor/ramsey/uuid/src/Generator/PeclUuidTimeGenerator.php index 7ccf16fd9..903798dd3 100644 --- a/vendor/ramsey/uuid/src/Generator/PeclUuidTimeGenerator.php +++ b/vendor/ramsey/uuid/src/Generator/PeclUuidTimeGenerator.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,29 +8,26 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ +declare(strict_types=1); + namespace Ramsey\Uuid\Generator; +use const UUID_TYPE_TIME; + /** - * PeclUuidTimeGenerator provides functionality to generate strings of binary - * data for version 1 UUIDs using the PECL UUID PHP extension + * PeclUuidTimeGenerator generates strings of binary data for time-base UUIDs, + * using ext-uuid * - * @link https://pecl.php.net/package/uuid + * @link https://pecl.php.net/package/uuid ext-uuid */ class PeclUuidTimeGenerator implements TimeGeneratorInterface { /** - * Generate a version 1 UUID using the PECL UUID extension - * - * @param int|string $node Not used in this context - * @param int $clockSeq Not used in this context - * @return string A binary string + * @inheritDoc */ - public function generate($node = null, $clockSeq = null) + public function generate($node = null, ?int $clockSeq = null): string { $uuid = uuid_create(UUID_TYPE_TIME); diff --git a/vendor/ramsey/uuid/src/Generator/RandomBytesGenerator.php b/vendor/ramsey/uuid/src/Generator/RandomBytesGenerator.php index cc3d37989..e6e9a199b 100644 --- a/vendor/ramsey/uuid/src/Generator/RandomBytesGenerator.php +++ b/vendor/ramsey/uuid/src/Generator/RandomBytesGenerator.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,33 +8,37 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ +declare(strict_types=1); + namespace Ramsey\Uuid\Generator; -use Exception; +use Ramsey\Uuid\Exception\RandomSourceException; /** - * RandomBytesGenerator provides functionality to generate strings of random - * binary data using `random_bytes()` function in PHP 7+ or paragonie/random_compat + * RandomBytesGenerator generates strings of random binary data using the + * built-in `random_bytes()` PHP function * - * @link http://php.net/random_bytes - * @link https://github.com/paragonie/random_compat + * @link http://php.net/random_bytes random_bytes() */ class RandomBytesGenerator implements RandomGeneratorInterface { /** - * Generates a string of random binary data of the specified length + * @throws RandomSourceException if random_bytes() throws an exception/error * - * @param integer $length The number of bytes of random binary data to generate - * @return string A binary string - * @throws Exception if it was not possible to gather sufficient entropy + * @inheritDoc */ - public function generate($length) + public function generate(int $length): string { - return random_bytes($length); + try { + return random_bytes($length); + } catch (\Throwable $exception) { + throw new RandomSourceException( + $exception->getMessage(), + (int) $exception->getCode(), + $exception + ); + } } } diff --git a/vendor/ramsey/uuid/src/Generator/RandomGeneratorFactory.php b/vendor/ramsey/uuid/src/Generator/RandomGeneratorFactory.php index 39110622f..b723ac29e 100644 --- a/vendor/ramsey/uuid/src/Generator/RandomGeneratorFactory.php +++ b/vendor/ramsey/uuid/src/Generator/RandomGeneratorFactory.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,24 +8,22 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ +declare(strict_types=1); + namespace Ramsey\Uuid\Generator; /** - * A factory for retrieving a random generator, based on the environment + * RandomGeneratorFactory retrieves a default random generator, based on the + * environment */ class RandomGeneratorFactory { /** * Returns a default random generator, based on the current environment - * - * @return RandomGeneratorInterface */ - public static function getGenerator() + public function getGenerator(): RandomGeneratorInterface { return new RandomBytesGenerator(); } diff --git a/vendor/ramsey/uuid/src/Generator/RandomGeneratorInterface.php b/vendor/ramsey/uuid/src/Generator/RandomGeneratorInterface.php index b791d60d4..5c83cb4d8 100644 --- a/vendor/ramsey/uuid/src/Generator/RandomGeneratorInterface.php +++ b/vendor/ramsey/uuid/src/Generator/RandomGeneratorInterface.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,31 +8,23 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ -namespace Ramsey\Uuid\Generator; +declare(strict_types=1); -use Exception; -use InvalidArgumentException; -use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; +namespace Ramsey\Uuid\Generator; /** - * RandomGeneratorInterface provides functionality to generate strings of random - * binary data + * A random generator generates strings of random binary data */ interface RandomGeneratorInterface { /** - * Generates a string of random binary data of the specified length + * Generates a string of randomized binary data + * + * @param int $length The number of bytes of random binary data to generate * - * @param integer $length The number of bytes of random binary data to generate * @return string A binary string - * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present - * @throws InvalidArgumentException - * @throws Exception if it was not possible to gather sufficient entropy */ - public function generate($length); + public function generate(int $length): string; } diff --git a/vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php b/vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php index 5aa0e8865..24ed56920 100644 --- a/vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php +++ b/vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,21 +8,20 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ +declare(strict_types=1); + namespace Ramsey\Uuid\Generator; -use RandomLib\Generator; use RandomLib\Factory; +use RandomLib\Generator; /** - * RandomLibAdapter provides functionality to generate strings of random - * binary data using the paragonie/random-lib library + * RandomLibAdapter generates strings of random binary data using the + * paragonie/random-lib library * - * @link https://packagist.org/packages/paragonie/random-lib + * @link https://packagist.org/packages/paragonie/random-lib paragonie/random-lib */ class RandomLibAdapter implements RandomGeneratorInterface { @@ -31,31 +31,24 @@ class RandomLibAdapter implements RandomGeneratorInterface private $generator; /** - * Constructs a `RandomLibAdapter` using a `RandomLib\Generator` + * Constructs a RandomLibAdapter * - * By default, if no `Generator` is passed in, this creates a high-strength + * By default, if no Generator is passed in, this creates a high-strength * generator to use when generating random binary data. * - * @param Generator $generator An paragonie/random-lib `Generator` + * @param Generator|null $generator The generator to use when generating binary data */ - public function __construct(Generator $generator = null) + public function __construct(?Generator $generator = null) { - $this->generator = $generator; - - if ($this->generator === null) { + if ($generator === null) { $factory = new Factory(); - - $this->generator = $factory->getHighStrengthGenerator(); + $generator = $factory->getHighStrengthGenerator(); } + + $this->generator = $generator; } - /** - * Generates a string of random binary data of the specified length - * - * @param integer $length The number of bytes of random binary data to generate - * @return string A binary string - */ - public function generate($length) + public function generate(int $length): string { return $this->generator->generate($length); } diff --git a/vendor/ramsey/uuid/src/Generator/SodiumRandomGenerator.php b/vendor/ramsey/uuid/src/Generator/SodiumRandomGenerator.php deleted file mode 100644 index f4ccf8593..000000000 --- a/vendor/ramsey/uuid/src/Generator/SodiumRandomGenerator.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php -/** - * This file is part of the ramsey/uuid library - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> - * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub - */ - -namespace Ramsey\Uuid\Generator; - -/** - * SodiumRandomGenerator provides functionality to generate strings of random - * binary data using the PECL libsodium extension - * - * @deprecated As of PHP 7.2.0, the libsodium extension is bundled with PHP, and - * the random_bytes() PHP function is now the recommended method for - * generating random byes. The default RandomBytesGenerator uses the - * random_bytes() function. - * <em>This generator will be removed in ramsey/uuid 4.0.0.</em> - * @link http://pecl.php.net/package/libsodium - * @link https://paragonie.com/book/pecl-libsodium - */ -class SodiumRandomGenerator implements RandomGeneratorInterface -{ - /** - * Generates a string of random binary data of the specified length - * - * @param integer $length The number of bytes of random binary data to generate - * @return string A binary string - */ - public function generate($length) - { - return \Sodium\randombytes_buf($length); - } -} diff --git a/vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php b/vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php index 24d501bbf..3d55fc4d6 100644 --- a/vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php +++ b/vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,11 +8,10 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ +declare(strict_types=1); + namespace Ramsey\Uuid\Generator; use Ramsey\Uuid\Converter\TimeConverterInterface; @@ -19,7 +19,8 @@ use Ramsey\Uuid\Provider\NodeProviderInterface; use Ramsey\Uuid\Provider\TimeProviderInterface; /** - * A factory for retrieving a time generator, based on the environment + * TimeGeneratorFactory retrieves a default time generator, based on the + * environment */ class TimeGeneratorFactory { @@ -38,14 +39,6 @@ class TimeGeneratorFactory */ private $timeProvider; - /** - * Constructs a `TimeGeneratorFactory` using a node provider, time converter, - * and time provider - * - * @param NodeProviderInterface $nodeProvider - * @param TimeConverterInterface $timeConverter - * @param TimeProviderInterface $timeProvider - */ public function __construct( NodeProviderInterface $nodeProvider, TimeConverterInterface $timeConverter, @@ -58,10 +51,8 @@ class TimeGeneratorFactory /** * Returns a default time generator, based on the current environment - * - * @return TimeGeneratorInterface */ - public function getGenerator() + public function getGenerator(): TimeGeneratorInterface { return new DefaultTimeGenerator( $this->nodeProvider, diff --git a/vendor/ramsey/uuid/src/Generator/TimeGeneratorInterface.php b/vendor/ramsey/uuid/src/Generator/TimeGeneratorInterface.php index 27c74590f..18f21c4b6 100644 --- a/vendor/ramsey/uuid/src/Generator/TimeGeneratorInterface.php +++ b/vendor/ramsey/uuid/src/Generator/TimeGeneratorInterface.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,37 +8,31 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ +declare(strict_types=1); + namespace Ramsey\Uuid\Generator; -use Exception; -use InvalidArgumentException; -use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; +use Ramsey\Uuid\Type\Hexadecimal; /** - * TimeGeneratorInterface provides functionality to generate strings of binary - * data for version 1 UUIDs based on a host ID, sequence number, and the current - * time + * A time generator generates strings of binary data based on a node ID, + * clock sequence, and the current time */ interface TimeGeneratorInterface { /** - * Generate a version 1 UUID from a host ID, sequence number, and the current time + * Generate a binary string from a node ID, clock sequence, and current time + * + * @param Hexadecimal|int|string|null $node A 48-bit number representing the + * hardware address; this number may be represented as an integer or a + * hexadecimal string + * @param int|null $clockSeq A 14-bit number used to help avoid duplicates + * that could arise when the clock is set backwards in time or if the + * node ID changes * - * @param int|string $node A 48-bit number representing the hardware address - * This number may be represented as an integer or a hexadecimal string. - * @param int $clockSeq A 14-bit number used to help avoid duplicates that - * could arise when the clock is set backwards in time or if the node ID - * changes. * @return string A binary string - * @throws UnsatisfiedDependencyException if called on a 32-bit system and - * `Moontoast\Math\BigNumber` is not present - * @throws InvalidArgumentException - * @throws Exception if it was not possible to gather sufficient entropy */ - public function generate($node = null, $clockSeq = null); + public function generate($node = null, ?int $clockSeq = null): string; } |