Beispiel #1
0
 /**
  * @param string|null $secret
  */
 private function setSecret($secret)
 {
     Assertion::nullOrString($secret, 'The secret must be a string or null.');
     if (null === $secret) {
         $secret = trim(Base32::encode(random_bytes(32)), '=');
     }
     $this->parameters['secret'] = $secret;
 }
 /**
  * EncryptedSubjectIdentifier constructor.
  *
  * @param string      $pairwise_encryption_key
  * @param string      $algorithm
  * @param null|string $iv
  * @param string      $salt
  */
 public function __construct($pairwise_encryption_key, $algorithm, $iv, $salt)
 {
     Assertion::nullOrString($iv);
     Assertion::string($salt);
     Assertion::string($pairwise_encryption_key);
     Assertion::string($algorithm);
     Assertion::inArray($algorithm, openssl_get_cipher_methods(), sprintf('The algorithm "%s" is not supported.', $algorithm));
     $this->pairwise_encryption_key = $pairwise_encryption_key;
     $this->algorithm = $algorithm;
     $this->salt = $salt;
     $this->iv = $iv;
 }
 /**
  * BaseReport constructor.
  *
  * @param BaseReportBuilder $builder
  *
  * @throws \Assert\AssertionFailedException
  */
 public function __construct(BaseReportBuilder $builder)
 {
     $id = $builder->getId();
     Assertion::uuid($id);
     $this->id = $id;
     $name = $builder->getName();
     Assertion::string($name);
     Assertion::notEmpty($name);
     $this->name = $name;
     $description = $builder->getDescription();
     Assertion::nullOrString($description);
     $this->setDescription($description);
     $gitLab = $builder->getGitLab();
     Assertion::isInstanceOf($gitLab, GitLab::class);
     $this->gitLab = $gitLab;
 }
 /**
  * @param int|null $userId
  * @param int $rightId
  * @param null|string $forObjectGroup
  * @param null|string $withId
  */
 public function __construct($userId, $rightId, $forObjectGroup, $withId)
 {
     Assertion::nullOrInteger($userId);
     Assertion::integer($rightId);
     Assertion::nullOrString($forObjectGroup);
     //If there is no object group, there can not be an id
     if ($forObjectGroup === null) {
         Assertion::same($withId, null);
     } else {
         Assertion::nullOrString($withId);
     }
     $this->userId = $userId;
     $this->rightId = $rightId;
     $this->forObjectGroup = $forObjectGroup;
     $this->withId = $withId;
 }
 /**
  * Constructor.
  *
  * @param bool $verified
  * @param \DateTimeImmutable|null $createdAt
  * @param Photo\Photo $bestPhoto
  * @param float|null $rating
  * @param string|null $url
  * @param int|null $hereNow
  * @param string[] $tags
  * @param int|null $likes
  * @param \DateTimeZone|null $timeZone
  */
 public function __construct($verified, \DateTimeImmutable $createdAt = null, Photo\Photo $bestPhoto = null, $rating = null, $url = null, $hereNow = null, $tags = [], $likes = null, \DateTimeZone $timeZone = null)
 {
     Assertion::boolean($verified);
     Assertion::isArray($tags);
     Assertion::nullOrInteger($likes);
     Assertion::nullOrFloat($rating);
     Assertion::nullOrString($url);
     Assertion::nullOrInteger($hereNow);
     $this->verified = $verified;
     $this->rating = $rating;
     $this->hereNow = $hereNow;
     $this->url = $url;
     $this->createdAt = $createdAt;
     $this->timeZone = $timeZone;
     $this->bestPhoto = $bestPhoto;
     $this->tags = $tags;
     $this->likes = $likes;
 }
 public function existsUserRight($userId, $rightId, $forObject, $withId)
 {
     Assertion::nullOrInteger($userId);
     Assertion::integer($rightId);
     Assertion::nullOrString($forObject);
     //If there is no forObject, there can not be an withId
     if ($forObject === null) {
         Assertion::same($withId, null);
     } else {
         Assertion::nullOrString($withId);
     }
     if ($userId !== null && !$this->userService->existsUserById($userId)) {
         throw new UserDoesNotExistException();
     }
     if (!$this->rightService->existsRightById($rightId)) {
         throw new RightNotFoundException();
     }
     return $this->getORMUserRight($userId, $rightId, $forObject, $withId) !== null;
 }
Beispiel #7
0
 /**
  * Constructor
  *
  * @param AMQPQueue $queue
  * @param float $idleTimeout in seconds
  * @param int $waitTimeout in microseconds
  * @param string|null $appId
  */
 public function __construct(AMQPQueue $queue, $idleTimeout, $waitTimeout, $appId = null)
 {
     Assertion::float($idleTimeout);
     Assertion::integer($waitTimeout);
     Assertion::nullOrString($appId);
     if (function_exists('pcntl_signal_dispatch')) {
         $this->usePcntlSignalDispatch = true;
     }
     if (function_exists('pcntl_signal')) {
         pcntl_signal(SIGTERM, [$this, 'shutdown']);
         pcntl_signal(SIGINT, [$this, 'shutdown']);
         pcntl_signal(SIGHUP, [$this, 'shutdown']);
     }
     $this->blockSize = $queue->getChannel()->getPrefetchCount();
     $this->idleTimeout = (double) $idleTimeout;
     $this->waitTimeout = (int) $waitTimeout;
     $this->queues = new InfiniteIterator(new ArrayIterator([$queue]));
     $this->appId = $appId;
 }
 public function __construct($filters, $offset, $limit, $sortField, $sortOrder, $isPaginated)
 {
     Assertion::isArray($filters, "Invalid filters");
     Assertion::integerish($limit, "Invalid limit");
     Assertion::integerish($offset, "Invalid offset");
     Assertion::nullOrString($sortField, "Invalid sort field");
     Assertion::choice($sortOrder, [null, self::ORDER_ASC, self::ORDER_DESC], "Invalid sort order");
     Assertion::boolean($isPaginated, "Invalid value for isPaginated");
     if ($limit < 0) {
         throw new \InvalidArgumentException("Invalid limit");
     }
     if ($offset < 0) {
         throw new \InvalidArgumentException("Invalid offset");
     }
     $this->filters = $filters;
     $this->offset = (int) $offset;
     $this->limit = (int) $limit;
     $this->sortField = $sortField;
     $this->sortOrder = $sortOrder;
     $this->isPaginated = (bool) $isPaginated;
 }
 /**
  * Sets the description
  *
  * @param string $description
  */
 public function setDescription($description)
 {
     Assertion::nullOrString($description);
     $this->description = $description;
 }
 /**
  * {@inheritdoc}
  */
 public function setRefreshToken($refresh_token)
 {
     Assertion::nullOrString($refresh_token);
     $this->refresh_token = $refresh_token;
 }
Beispiel #11
0
 /**
  * @param array $config
  */
 private function getConfig(array $config)
 {
     $config = array_merge(self::DEFAULT_CONFIG, $config);
     Assertion::boolean($config['returnResponse']);
     Assertion::boolean($config['validateRequest']);
     Assertion::boolean($config['validateResponse']);
     Assertion::nullOrString($config['baseUri']);
     return array_intersect_key($config, self::DEFAULT_CONFIG);
 }
Beispiel #12
0
 /**
  * @param null|string $value
  */
 public function setRememberToken($value)
 {
     Assertion::nullOrString($value);
     $oldValue = $this->rememberToken;
     if ($oldValue !== $value) {
         $this->rememberToken = $value;
         $this->onPropertyChanged('rememberToken', $oldValue, $value);
     }
 }
Beispiel #13
0
 private function setSerializedMessage($serializedMessage)
 {
     Assertion::nullOrString($serializedMessage);
     $this->serializedMessage = $serializedMessage;
 }
 private function validate()
 {
     Assertion::nullOrString($this->logMessageRegExp);
     Assertion::nullOrString($this->logMessageInString);
     Assertion::nullOrString($this->logContextFuzzy);
     Assertion::nullOrIsInstanceOf($this->logTimeLowerBounds, DateTimeInterface::class);
     Assertion::nullOrIsInstanceOf($this->logTimeUpperBounds, DateTimeInterface::class);
     Assertion::nullOrIsArray($this->logLevelList);
     if (!is_null($this->logLevelList)) {
         Assertion::notEmpty($this->logLevelList);
         Assertion::allInArray($this->logLevelList, array_values((new ReflectionClass(LogLevel::class))->getConstants()));
     }
     if (!is_null($this->logMessageRegExp)) {
         Assertion::true(RegexGuardFactory::getGuard()->isRegexValid($this->logMessageRegExp));
     }
     if (!is_null($this->logTimeLowerBounds) && !is_null($this->logTimeUpperBounds)) {
         Assertion::false($this->logTimeLowerBounds->diff($this->logTimeUpperBounds)->invert);
     }
 }
Beispiel #15
0
 /**
  * @param string      $K  Key encryption key
  * @param string      $IV Initialization vector
  * @param string|null $C  Data to encrypt (null for authentication)
  * @param string|null $A  Additional Authentication Data
  * @param string      $T  Tag
  *
  * @return string
  */
 public static function decrypt($K, $IV, $C, $A, $T)
 {
     Assertion::string($K, 'The key encryption key must be a binary string.');
     $key_length = mb_strlen($K, '8bit') * 8;
     Assertion::inArray($key_length, [128, 192, 256], 'Bad key encryption key length.');
     Assertion::string($IV, 'The Initialization Vector must be a binary string.');
     Assertion::nullOrString($C, 'The data to encrypt must be null or a binary string.');
     Assertion::nullOrString($A, 'The Additional Authentication Data must be null or a binary string.');
     $tag_length = self::getLength($T);
     Assertion::integer($tag_length, 'Invalid tag length. Supported values are: 128, 120, 112, 104 and 96.');
     Assertion::inArray($tag_length, [128, 120, 112, 104, 96], 'Invalid tag length. Supported values are: 128, 120, 112, 104 and 96.');
     if (version_compare(PHP_VERSION, '7.1.0RC5') >= 0 && null !== $C) {
         return self::decryptWithPHP71($K, $key_length, $IV, $C, $A, $T);
     } elseif (class_exists('\\Crypto\\Cipher')) {
         return self::decryptWithCryptoExtension($K, $key_length, $IV, $C, $A, $T, $tag_length);
     }
     return self::decryptWithPHP($K, $key_length, $IV, $C, $A, $T, $tag_length);
 }
Beispiel #16
0
 /**
  * @param string      $type
  * @param null|string $algorithm
  * @param array       $restrictions
  *
  * @return null|\Jose\Object\JWKInterface
  */
 public function selectKey($type, $algorithm = null, array $restrictions = [])
 {
     Assertion::inArray($type, ['enc', 'sig']);
     Assertion::nullOrString($algorithm);
     $result = [];
     foreach ($this->getKeys() as $key) {
         $ind = 0;
         // Check usage
         $can_use = $this->canKeyBeUsedFor($type, $key);
         if (false === $can_use) {
             continue;
         }
         $ind += $can_use;
         // Check algorithm
         $alg = $this->canKeyBeUsedWithAlgorithm($algorithm, $key);
         if (false === $alg) {
             continue;
         }
         $ind += $alg;
         // Validate restrictions
         if (false === $this->doesKeySatisfyRestrictions($restrictions, $key)) {
             continue;
         }
         // Add to the list with trust indicator
         $result[] = ['key' => $key, 'ind' => $ind];
     }
     //Return null if no key
     if (empty($result)) {
         return;
     }
     //Sort by trust indicator
     usort($result, [$this, 'sortKeys']);
     //Return the highest trust indicator (first key)
     return $result[0]['key'];
 }
 /**
  * @param string      $name
  * @param string      $verifier
  * @param string      $checker
  * @param string|null $decrypter
  * @param bool        $is_public
  *
  * @return array
  */
 private static function getJWTLoaderConfiguration($name, $verifier, $checker, $decrypter = null, $is_public = true)
 {
     self::checkParameters($name, $is_public);
     Assertion::string($verifier);
     Assertion::notEmpty($verifier);
     Assertion::string($checker);
     Assertion::notEmpty($checker);
     Assertion::nullOrString($decrypter);
     return [self::BUNDLE_ALIAS => ['jwt_loaders' => [$name => ['is_public' => $is_public, 'verifier' => $verifier, 'checker' => $checker, 'decrypter' => $decrypter]]]];
 }
 /**
  * RpcClientRequest constructor.
  *
  * @param array|string|integer|float|bool $payload
  * @param string $server
  * @param string $requestId
  * @param string|null $routingKey
  * @param int $expiration
  * @param string|null $userId
  * @param string|null $messageId
  * @param string|null $timestamp
  * @param string|null $type
  */
 public function __construct($payload, $server, $requestId, $routingKey = null, $expiration = 0, $userId = null, $messageId = null, $timestamp = null, $type = null)
 {
     if (!is_array($payload) && !is_scalar($payload)) {
         throw new Exception\InvalidArgumentException('$payload must be of type array or scalar');
     }
     Assertion::minLength($server, 1);
     Assertion::minLength($requestId, 1);
     Assertion::nullOrString($routingKey);
     Assertion::min($expiration, 0);
     Assertion::nullOrString($userId);
     Assertion::nullOrString($messageId);
     Assertion::nullOrString($timestamp);
     Assertion::nullOrString($type);
     $this->payload = $payload;
     $this->server = $server;
     $this->requestId = $requestId;
     $this->routingKey = $routingKey;
     $this->expiration = $expiration;
     $this->userId = $userId;
     $this->messageId = $messageId;
     $this->timestamp = $timestamp;
     $this->type = $type;
 }
 /**
  * @param string $note
  */
 public function setNote($note)
 {
     Assertion::nullOrString($note, 'Note should be null or a string', null);
     $this->note = (string) $note;
 }