@@ -15,28 +15,28 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class NotBeforeClaim extends RegisteredClaim |
| 17 | 17 | { |
| 18 | - use NumericDateClaim; |
|
| 19 | - use ReferenceTimeValidation; |
|
| 18 | + use NumericDateClaim; |
|
| 19 | + use ReferenceTimeValidation; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Constructor. |
|
| 23 | - * |
|
| 24 | - * @param int $not_before Not before time |
|
| 25 | - */ |
|
| 26 | - public function __construct(int $not_before) |
|
| 27 | - { |
|
| 28 | - // validate that claim is before or at the constraint (reference time) |
|
| 29 | - parent::__construct(self::NAME_NOT_BEFORE, $not_before, |
|
| 30 | - new LessOrEqualValidator()); |
|
| 31 | - } |
|
| 21 | + /** |
|
| 22 | + * Constructor. |
|
| 23 | + * |
|
| 24 | + * @param int $not_before Not before time |
|
| 25 | + */ |
|
| 26 | + public function __construct(int $not_before) |
|
| 27 | + { |
|
| 28 | + // validate that claim is before or at the constraint (reference time) |
|
| 29 | + parent::__construct(self::NAME_NOT_BEFORE, $not_before, |
|
| 30 | + new LessOrEqualValidator()); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Initialize with time set to current time |
|
| 35 | - * |
|
| 36 | - * @return self |
|
| 37 | - */ |
|
| 38 | - public static function now(): self |
|
| 39 | - { |
|
| 40 | - return new self(time()); |
|
| 41 | - } |
|
| 33 | + /** |
|
| 34 | + * Initialize with time set to current time |
|
| 35 | + * |
|
| 36 | + * @return self |
|
| 37 | + */ |
|
| 38 | + public static function now(): self |
|
| 39 | + { |
|
| 40 | + return new self(time()); |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -13,14 +13,14 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class IssuerClaim extends RegisteredClaim |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Constructor. |
|
| 18 | - * |
|
| 19 | - * @param string $issuer |
|
| 20 | - */ |
|
| 21 | - public function __construct(string $issuer) |
|
| 22 | - { |
|
| 23 | - parent::__construct(self::NAME_ISSUER, $issuer, |
|
| 24 | - new EqualsValidator()); |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * Constructor. |
|
| 18 | + * |
|
| 19 | + * @param string $issuer |
|
| 20 | + */ |
|
| 21 | + public function __construct(string $issuer) |
|
| 22 | + { |
|
| 23 | + parent::__construct(self::NAME_ISSUER, $issuer, |
|
| 24 | + new EqualsValidator()); |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -13,14 +13,14 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class JWTIDClaim extends RegisteredClaim |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Constructor. |
|
| 18 | - * |
|
| 19 | - * @param string $id JWT unique identifier |
|
| 20 | - */ |
|
| 21 | - public function __construct(string $id) |
|
| 22 | - { |
|
| 23 | - parent::__construct(self::NAME_JWT_ID, $id, |
|
| 24 | - new EqualsValidator()); |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * Constructor. |
|
| 18 | + * |
|
| 19 | + * @param string $id JWT unique identifier |
|
| 20 | + */ |
|
| 21 | + public function __construct(string $id) |
|
| 22 | + { |
|
| 23 | + parent::__construct(self::NAME_JWT_ID, $id, |
|
| 24 | + new EqualsValidator()); |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -13,13 +13,13 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class SubjectClaim extends RegisteredClaim |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Constructor. |
|
| 18 | - * |
|
| 19 | - * @param string $subject Subject |
|
| 20 | - */ |
|
| 21 | - public function __construct(string $subject) |
|
| 22 | - { |
|
| 23 | - parent::__construct(self::NAME_SUBJECT, $subject, new EqualsValidator()); |
|
| 24 | - } |
|
| 16 | + /** |
|
| 17 | + * Constructor. |
|
| 18 | + * |
|
| 19 | + * @param string $subject Subject |
|
| 20 | + */ |
|
| 21 | + public function __construct(string $subject) |
|
| 22 | + { |
|
| 23 | + parent::__construct(self::NAME_SUBJECT, $subject, new EqualsValidator()); |
|
| 24 | + } |
|
| 25 | 25 | } |
@@ -9,184 +9,184 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | trait TypedClaims |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Check whether the claim is present. |
|
| 14 | - * |
|
| 15 | - * @param string $name Claim name |
|
| 16 | - * @return bool |
|
| 17 | - */ |
|
| 18 | - abstract public function has(string $name): bool; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Get the claim by name. |
|
| 22 | - * |
|
| 23 | - * @param string $name Claim name |
|
| 24 | - * @return Claim |
|
| 25 | - */ |
|
| 26 | - abstract public function get(string $name): Claim; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Check whether the issuer claim is present. |
|
| 30 | - * |
|
| 31 | - * @return bool |
|
| 32 | - */ |
|
| 33 | - public function hasIssuer(): bool |
|
| 34 | - { |
|
| 35 | - return $this->has(RegisteredClaim::NAME_ISSUER); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Get the issuer claim. |
|
| 40 | - * |
|
| 41 | - * @return IssuerClaim |
|
| 42 | - */ |
|
| 43 | - public function issuer(): IssuerClaim |
|
| 44 | - { |
|
| 45 | - return self::_checkType($this->get(RegisteredClaim::NAME_ISSUER), |
|
| 46 | - IssuerClaim::class); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Check whether the subject claim is present. |
|
| 51 | - * |
|
| 52 | - * @return bool |
|
| 53 | - */ |
|
| 54 | - public function hasSubject(): bool |
|
| 55 | - { |
|
| 56 | - return $this->has(RegisteredClaim::NAME_SUBJECT); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Get the subject claim. |
|
| 61 | - * |
|
| 62 | - * @return SubjectClaim |
|
| 63 | - */ |
|
| 64 | - public function subject(): SubjectClaim |
|
| 65 | - { |
|
| 66 | - return self::_checkType($this->get(RegisteredClaim::NAME_SUBJECT), |
|
| 67 | - SubjectClaim::class); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Check whether the audience claim is present. |
|
| 72 | - * |
|
| 73 | - * @return bool |
|
| 74 | - */ |
|
| 75 | - public function hasAudience(): bool |
|
| 76 | - { |
|
| 77 | - return $this->has(RegisteredClaim::NAME_AUDIENCE); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Get the audience claim. |
|
| 82 | - * |
|
| 83 | - * @return AudienceClaim |
|
| 84 | - */ |
|
| 85 | - public function audience(): AudienceClaim |
|
| 86 | - { |
|
| 87 | - return self::_checkType($this->get(RegisteredClaim::NAME_AUDIENCE), |
|
| 88 | - AudienceClaim::class); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Check whether the expiration time claim is present. |
|
| 93 | - * |
|
| 94 | - * @return bool |
|
| 95 | - */ |
|
| 96 | - public function hasExpirationTime(): bool |
|
| 97 | - { |
|
| 98 | - return $this->has(RegisteredClaim::NAME_EXPIRATION_TIME); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Get the expiration time claim. |
|
| 103 | - * |
|
| 104 | - * @return ExpirationTimeClaim |
|
| 105 | - */ |
|
| 106 | - public function expirationTime(): ExpirationTimeClaim |
|
| 107 | - { |
|
| 108 | - return self::_checkType( |
|
| 109 | - $this->get(RegisteredClaim::NAME_EXPIRATION_TIME), |
|
| 110 | - ExpirationTimeClaim::class); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Check whether the not before claim is present. |
|
| 115 | - * |
|
| 116 | - * @return bool |
|
| 117 | - */ |
|
| 118 | - public function hasNotBefore(): bool |
|
| 119 | - { |
|
| 120 | - return $this->has(RegisteredClaim::NAME_NOT_BEFORE); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Get the not before claim. |
|
| 125 | - * |
|
| 126 | - * @return NotBeforeClaim |
|
| 127 | - */ |
|
| 128 | - public function notBefore(): NotBeforeClaim |
|
| 129 | - { |
|
| 130 | - return self::_checkType($this->get(RegisteredClaim::NAME_NOT_BEFORE), |
|
| 131 | - NotBeforeClaim::class); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Check whether the issued at claim is present. |
|
| 136 | - * |
|
| 137 | - * @return bool |
|
| 138 | - */ |
|
| 139 | - public function hasIssuedAt(): bool |
|
| 140 | - { |
|
| 141 | - return $this->has(RegisteredClaim::NAME_ISSUED_AT); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Get the issued at claim. |
|
| 146 | - * |
|
| 147 | - * @return IssuedAtClaim |
|
| 148 | - */ |
|
| 149 | - public function issuedAt(): IssuedAtClaim |
|
| 150 | - { |
|
| 151 | - return self::_checkType($this->get(RegisteredClaim::NAME_ISSUED_AT), |
|
| 152 | - IssuedAtClaim::class); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Check whether the JWT ID claim is present. |
|
| 157 | - * |
|
| 158 | - * @return bool |
|
| 159 | - */ |
|
| 160 | - public function hasJWTID(): bool |
|
| 161 | - { |
|
| 162 | - return $this->has(RegisteredClaim::NAME_JWT_ID); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Get the JWT ID claim. |
|
| 167 | - * |
|
| 168 | - * @return JWTIDClaim |
|
| 169 | - */ |
|
| 170 | - public function JWTID(): JWTIDClaim |
|
| 171 | - { |
|
| 172 | - return self::_checkType($this->get(RegisteredClaim::NAME_JWT_ID), |
|
| 173 | - JWTIDClaim::class); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Check that the claim is an instance of the given class. |
|
| 178 | - * |
|
| 179 | - * @param Claim $claim Claim object |
|
| 180 | - * @param string $cls Class name |
|
| 181 | - * @throws \UnexpectedValueException |
|
| 182 | - * @return Claim |
|
| 183 | - */ |
|
| 184 | - private static function _checkType(Claim $claim, string $cls): Claim |
|
| 185 | - { |
|
| 186 | - if (!$claim instanceof $cls) { |
|
| 187 | - throw new \UnexpectedValueException( |
|
| 188 | - "$cls expected, got " . get_class($claim)); |
|
| 189 | - } |
|
| 190 | - return $claim; |
|
| 191 | - } |
|
| 12 | + /** |
|
| 13 | + * Check whether the claim is present. |
|
| 14 | + * |
|
| 15 | + * @param string $name Claim name |
|
| 16 | + * @return bool |
|
| 17 | + */ |
|
| 18 | + abstract public function has(string $name): bool; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Get the claim by name. |
|
| 22 | + * |
|
| 23 | + * @param string $name Claim name |
|
| 24 | + * @return Claim |
|
| 25 | + */ |
|
| 26 | + abstract public function get(string $name): Claim; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Check whether the issuer claim is present. |
|
| 30 | + * |
|
| 31 | + * @return bool |
|
| 32 | + */ |
|
| 33 | + public function hasIssuer(): bool |
|
| 34 | + { |
|
| 35 | + return $this->has(RegisteredClaim::NAME_ISSUER); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Get the issuer claim. |
|
| 40 | + * |
|
| 41 | + * @return IssuerClaim |
|
| 42 | + */ |
|
| 43 | + public function issuer(): IssuerClaim |
|
| 44 | + { |
|
| 45 | + return self::_checkType($this->get(RegisteredClaim::NAME_ISSUER), |
|
| 46 | + IssuerClaim::class); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Check whether the subject claim is present. |
|
| 51 | + * |
|
| 52 | + * @return bool |
|
| 53 | + */ |
|
| 54 | + public function hasSubject(): bool |
|
| 55 | + { |
|
| 56 | + return $this->has(RegisteredClaim::NAME_SUBJECT); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Get the subject claim. |
|
| 61 | + * |
|
| 62 | + * @return SubjectClaim |
|
| 63 | + */ |
|
| 64 | + public function subject(): SubjectClaim |
|
| 65 | + { |
|
| 66 | + return self::_checkType($this->get(RegisteredClaim::NAME_SUBJECT), |
|
| 67 | + SubjectClaim::class); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Check whether the audience claim is present. |
|
| 72 | + * |
|
| 73 | + * @return bool |
|
| 74 | + */ |
|
| 75 | + public function hasAudience(): bool |
|
| 76 | + { |
|
| 77 | + return $this->has(RegisteredClaim::NAME_AUDIENCE); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Get the audience claim. |
|
| 82 | + * |
|
| 83 | + * @return AudienceClaim |
|
| 84 | + */ |
|
| 85 | + public function audience(): AudienceClaim |
|
| 86 | + { |
|
| 87 | + return self::_checkType($this->get(RegisteredClaim::NAME_AUDIENCE), |
|
| 88 | + AudienceClaim::class); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Check whether the expiration time claim is present. |
|
| 93 | + * |
|
| 94 | + * @return bool |
|
| 95 | + */ |
|
| 96 | + public function hasExpirationTime(): bool |
|
| 97 | + { |
|
| 98 | + return $this->has(RegisteredClaim::NAME_EXPIRATION_TIME); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Get the expiration time claim. |
|
| 103 | + * |
|
| 104 | + * @return ExpirationTimeClaim |
|
| 105 | + */ |
|
| 106 | + public function expirationTime(): ExpirationTimeClaim |
|
| 107 | + { |
|
| 108 | + return self::_checkType( |
|
| 109 | + $this->get(RegisteredClaim::NAME_EXPIRATION_TIME), |
|
| 110 | + ExpirationTimeClaim::class); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Check whether the not before claim is present. |
|
| 115 | + * |
|
| 116 | + * @return bool |
|
| 117 | + */ |
|
| 118 | + public function hasNotBefore(): bool |
|
| 119 | + { |
|
| 120 | + return $this->has(RegisteredClaim::NAME_NOT_BEFORE); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Get the not before claim. |
|
| 125 | + * |
|
| 126 | + * @return NotBeforeClaim |
|
| 127 | + */ |
|
| 128 | + public function notBefore(): NotBeforeClaim |
|
| 129 | + { |
|
| 130 | + return self::_checkType($this->get(RegisteredClaim::NAME_NOT_BEFORE), |
|
| 131 | + NotBeforeClaim::class); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Check whether the issued at claim is present. |
|
| 136 | + * |
|
| 137 | + * @return bool |
|
| 138 | + */ |
|
| 139 | + public function hasIssuedAt(): bool |
|
| 140 | + { |
|
| 141 | + return $this->has(RegisteredClaim::NAME_ISSUED_AT); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Get the issued at claim. |
|
| 146 | + * |
|
| 147 | + * @return IssuedAtClaim |
|
| 148 | + */ |
|
| 149 | + public function issuedAt(): IssuedAtClaim |
|
| 150 | + { |
|
| 151 | + return self::_checkType($this->get(RegisteredClaim::NAME_ISSUED_AT), |
|
| 152 | + IssuedAtClaim::class); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Check whether the JWT ID claim is present. |
|
| 157 | + * |
|
| 158 | + * @return bool |
|
| 159 | + */ |
|
| 160 | + public function hasJWTID(): bool |
|
| 161 | + { |
|
| 162 | + return $this->has(RegisteredClaim::NAME_JWT_ID); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Get the JWT ID claim. |
|
| 167 | + * |
|
| 168 | + * @return JWTIDClaim |
|
| 169 | + */ |
|
| 170 | + public function JWTID(): JWTIDClaim |
|
| 171 | + { |
|
| 172 | + return self::_checkType($this->get(RegisteredClaim::NAME_JWT_ID), |
|
| 173 | + JWTIDClaim::class); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Check that the claim is an instance of the given class. |
|
| 178 | + * |
|
| 179 | + * @param Claim $claim Claim object |
|
| 180 | + * @param string $cls Class name |
|
| 181 | + * @throws \UnexpectedValueException |
|
| 182 | + * @return Claim |
|
| 183 | + */ |
|
| 184 | + private static function _checkType(Claim $claim, string $cls): Claim |
|
| 185 | + { |
|
| 186 | + if (!$claim instanceof $cls) { |
|
| 187 | + throw new \UnexpectedValueException( |
|
| 188 | + "$cls expected, got " . get_class($claim)); |
|
| 189 | + } |
|
| 190 | + return $claim; |
|
| 191 | + } |
|
| 192 | 192 | } |
@@ -11,36 +11,36 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | trait ReferenceTimeValidation |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Validate the claim against given constraint. |
|
| 16 | - * |
|
| 17 | - * @param mixed $constraint |
|
| 18 | - * @return bool |
|
| 19 | - */ |
|
| 20 | - abstract public function validate($constraint): bool; |
|
| 14 | + /** |
|
| 15 | + * Validate the claim against given constraint. |
|
| 16 | + * |
|
| 17 | + * @param mixed $constraint |
|
| 18 | + * @return bool |
|
| 19 | + */ |
|
| 20 | + abstract public function validate($constraint): bool; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Override default Claim validation. |
|
| 24 | - * |
|
| 25 | - * Uses reference time of the validation context as a constraint. |
|
| 26 | - * |
|
| 27 | - * @see \JWX\JWT\Claim\Claim::validateWithContext() |
|
| 28 | - * @param ValidationContext $ctx |
|
| 29 | - * @return bool |
|
| 30 | - */ |
|
| 31 | - public function validateWithContext(ValidationContext $ctx): bool |
|
| 32 | - { |
|
| 33 | - if ($ctx->hasReferenceTime()) { |
|
| 34 | - // try to validate with leeway added |
|
| 35 | - if ($this->validate($ctx->referenceTime() + $ctx->leeway())) { |
|
| 36 | - return true; |
|
| 37 | - } |
|
| 38 | - // try to validate with leeway substracted |
|
| 39 | - if ($this->validate($ctx->referenceTime() - $ctx->leeway())) { |
|
| 40 | - return true; |
|
| 41 | - } |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 44 | - return true; |
|
| 45 | - } |
|
| 22 | + /** |
|
| 23 | + * Override default Claim validation. |
|
| 24 | + * |
|
| 25 | + * Uses reference time of the validation context as a constraint. |
|
| 26 | + * |
|
| 27 | + * @see \JWX\JWT\Claim\Claim::validateWithContext() |
|
| 28 | + * @param ValidationContext $ctx |
|
| 29 | + * @return bool |
|
| 30 | + */ |
|
| 31 | + public function validateWithContext(ValidationContext $ctx): bool |
|
| 32 | + { |
|
| 33 | + if ($ctx->hasReferenceTime()) { |
|
| 34 | + // try to validate with leeway added |
|
| 35 | + if ($this->validate($ctx->referenceTime() + $ctx->leeway())) { |
|
| 36 | + return true; |
|
| 37 | + } |
|
| 38 | + // try to validate with leeway substracted |
|
| 39 | + if ($this->validate($ctx->referenceTime() - $ctx->leeway())) { |
|
| 40 | + return true; |
|
| 41 | + } |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | + return true; |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -9,93 +9,93 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | trait NumericDateClaim |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Constructor. |
|
| 14 | - * |
|
| 15 | - * @param int $timestamp Unix timestamp |
|
| 16 | - */ |
|
| 17 | - abstract public function __construct(int $timestamp); |
|
| 12 | + /** |
|
| 13 | + * Constructor. |
|
| 14 | + * |
|
| 15 | + * @param int $timestamp Unix timestamp |
|
| 16 | + */ |
|
| 17 | + abstract public function __construct(int $timestamp); |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Get the parameter value. |
|
| 21 | - * |
|
| 22 | - * @return string |
|
| 23 | - */ |
|
| 24 | - abstract public function value(); |
|
| 19 | + /** |
|
| 20 | + * Get the parameter value. |
|
| 21 | + * |
|
| 22 | + * @return string |
|
| 23 | + */ |
|
| 24 | + abstract public function value(); |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Initialize instance from date/time string. |
|
| 28 | - * |
|
| 29 | - * @param string $time <code>strtotime</code> compatible time string |
|
| 30 | - * @param string $tz Default timezone |
|
| 31 | - * @throws \RuntimeException |
|
| 32 | - * @return static |
|
| 33 | - */ |
|
| 34 | - public static function fromString(string $time, string $tz = "UTC") |
|
| 35 | - { |
|
| 36 | - try { |
|
| 37 | - $dt = new \DateTimeImmutable($time, self::_createTimeZone($tz)); |
|
| 38 | - return new static($dt->getTimestamp()); |
|
| 39 | - } catch (\Exception $e) { |
|
| 40 | - throw new \RuntimeException( |
|
| 41 | - "Failed to create DateTime: " . |
|
| 42 | - self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
| 43 | - } |
|
| 44 | - } |
|
| 26 | + /** |
|
| 27 | + * Initialize instance from date/time string. |
|
| 28 | + * |
|
| 29 | + * @param string $time <code>strtotime</code> compatible time string |
|
| 30 | + * @param string $tz Default timezone |
|
| 31 | + * @throws \RuntimeException |
|
| 32 | + * @return static |
|
| 33 | + */ |
|
| 34 | + public static function fromString(string $time, string $tz = "UTC") |
|
| 35 | + { |
|
| 36 | + try { |
|
| 37 | + $dt = new \DateTimeImmutable($time, self::_createTimeZone($tz)); |
|
| 38 | + return new static($dt->getTimestamp()); |
|
| 39 | + } catch (\Exception $e) { |
|
| 40 | + throw new \RuntimeException( |
|
| 41 | + "Failed to create DateTime: " . |
|
| 42 | + self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Get date as a unix timestamp. |
|
| 48 | - * |
|
| 49 | - * @return int |
|
| 50 | - */ |
|
| 51 | - public function timestamp(): int |
|
| 52 | - { |
|
| 53 | - return (int) $this->value(); |
|
| 54 | - } |
|
| 46 | + /** |
|
| 47 | + * Get date as a unix timestamp. |
|
| 48 | + * |
|
| 49 | + * @return int |
|
| 50 | + */ |
|
| 51 | + public function timestamp(): int |
|
| 52 | + { |
|
| 53 | + return (int) $this->value(); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Get date as a datetime object. |
|
| 58 | - * |
|
| 59 | - * @param string $tz Timezone |
|
| 60 | - * @throws \RuntimeException |
|
| 61 | - * @return \DateTimeImmutable |
|
| 62 | - */ |
|
| 63 | - public function dateTime(string $tz = "UTC"): \DateTimeImmutable |
|
| 64 | - { |
|
| 65 | - $dt = \DateTimeImmutable::createFromFormat("!U", strval($this->value()), |
|
| 66 | - self::_createTimeZone($tz)); |
|
| 67 | - if (false === $dt) { |
|
| 68 | - throw new \RuntimeException( |
|
| 69 | - "Failed to create DateTime: " . |
|
| 70 | - self::_getLastDateTimeImmutableErrorsStr()); |
|
| 71 | - } |
|
| 72 | - return $dt; |
|
| 73 | - } |
|
| 56 | + /** |
|
| 57 | + * Get date as a datetime object. |
|
| 58 | + * |
|
| 59 | + * @param string $tz Timezone |
|
| 60 | + * @throws \RuntimeException |
|
| 61 | + * @return \DateTimeImmutable |
|
| 62 | + */ |
|
| 63 | + public function dateTime(string $tz = "UTC"): \DateTimeImmutable |
|
| 64 | + { |
|
| 65 | + $dt = \DateTimeImmutable::createFromFormat("!U", strval($this->value()), |
|
| 66 | + self::_createTimeZone($tz)); |
|
| 67 | + if (false === $dt) { |
|
| 68 | + throw new \RuntimeException( |
|
| 69 | + "Failed to create DateTime: " . |
|
| 70 | + self::_getLastDateTimeImmutableErrorsStr()); |
|
| 71 | + } |
|
| 72 | + return $dt; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Create DateTimeZone object from string. |
|
| 77 | - * |
|
| 78 | - * @param string $tz |
|
| 79 | - * @throws \UnexpectedValueException |
|
| 80 | - * @return \DateTimeZone |
|
| 81 | - */ |
|
| 82 | - private static function _createTimeZone(string $tz): \DateTimeZone |
|
| 83 | - { |
|
| 84 | - try { |
|
| 85 | - return new \DateTimeZone($tz); |
|
| 86 | - } catch (\Exception $e) { |
|
| 87 | - throw new \UnexpectedValueException("Invalid timezone.", 0, $e); |
|
| 88 | - } |
|
| 89 | - } |
|
| 75 | + /** |
|
| 76 | + * Create DateTimeZone object from string. |
|
| 77 | + * |
|
| 78 | + * @param string $tz |
|
| 79 | + * @throws \UnexpectedValueException |
|
| 80 | + * @return \DateTimeZone |
|
| 81 | + */ |
|
| 82 | + private static function _createTimeZone(string $tz): \DateTimeZone |
|
| 83 | + { |
|
| 84 | + try { |
|
| 85 | + return new \DateTimeZone($tz); |
|
| 86 | + } catch (\Exception $e) { |
|
| 87 | + throw new \UnexpectedValueException("Invalid timezone.", 0, $e); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Get last error caused by DateTimeImmutable. |
|
| 93 | - * |
|
| 94 | - * @return string |
|
| 95 | - */ |
|
| 96 | - private static function _getLastDateTimeImmutableErrorsStr(): string |
|
| 97 | - { |
|
| 98 | - $errors = \DateTimeImmutable::getLastErrors()["errors"]; |
|
| 99 | - return implode(", ", $errors); |
|
| 100 | - } |
|
| 91 | + /** |
|
| 92 | + * Get last error caused by DateTimeImmutable. |
|
| 93 | + * |
|
| 94 | + * @return string |
|
| 95 | + */ |
|
| 96 | + private static function _getLastDateTimeImmutableErrorsStr(): string |
|
| 97 | + { |
|
| 98 | + $errors = \DateTimeImmutable::getLastErrors()["errors"]; |
|
| 99 | + return implode(", ", $errors); |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -9,10 +9,10 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | interface HeaderParameters |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Get an array of JOSE header parameters representing this object. |
|
| 14 | - * |
|
| 15 | - * @return \JWX\JWT\Parameter\JWTParameter[] |
|
| 16 | - */ |
|
| 17 | - public function headerParameters(): array; |
|
| 12 | + /** |
|
| 13 | + * Get an array of JOSE header parameters representing this object. |
|
| 14 | + * |
|
| 15 | + * @return \JWX\JWT\Parameter\JWTParameter[] |
|
| 16 | + */ |
|
| 17 | + public function headerParameters(): array; |
|
| 18 | 18 | } |
@@ -13,453 +13,453 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | trait TypedHeader |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Whether parameters are present. |
|
| 18 | - * |
|
| 19 | - * @param string ...$names Parameter names |
|
| 20 | - * @return bool |
|
| 21 | - */ |
|
| 22 | - abstract public function has(string ...$names): bool; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Get a parameter. |
|
| 26 | - * |
|
| 27 | - * @param string $name Parameter name |
|
| 28 | - * @throws \LogicException If the parameter is not present |
|
| 29 | - * @return JWTParameter |
|
| 30 | - */ |
|
| 31 | - abstract public function get(string $name): JWTParameter; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Check whether the algorithm parameter is present. |
|
| 35 | - * |
|
| 36 | - * @return bool |
|
| 37 | - */ |
|
| 38 | - public function hasAlgorithm(): bool |
|
| 39 | - { |
|
| 40 | - return $this->has(Parameter\JWTParameter::P_ALG); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Get the algorithm parameter. |
|
| 45 | - * |
|
| 46 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 47 | - * @throws \LogicException If the parameter is not present |
|
| 48 | - * @return \JWX\JWT\Parameter\AlgorithmParameter |
|
| 49 | - */ |
|
| 50 | - public function algorithm(): Parameter\AlgorithmParameter |
|
| 51 | - { |
|
| 52 | - return self::_checkType($this->get(Parameter\JWTParameter::P_ALG), |
|
| 53 | - Parameter\AlgorithmParameter::class); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Check whether the authentication tag parameter is present. |
|
| 58 | - * |
|
| 59 | - * @return bool |
|
| 60 | - */ |
|
| 61 | - public function hasAuthenticationTag(): bool |
|
| 62 | - { |
|
| 63 | - return $this->has(Parameter\JWTParameter::P_TAG); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Get the authentication tag parameter. |
|
| 68 | - * |
|
| 69 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 70 | - * @throws \LogicException If the parameter is not present |
|
| 71 | - * @return \JWX\JWT\Parameter\AuthenticationTagParameter |
|
| 72 | - */ |
|
| 73 | - public function authenticationTag(): Parameter\AuthenticationTagParameter |
|
| 74 | - { |
|
| 75 | - return self::_checkType($this->get(Parameter\JWTParameter::P_TAG), |
|
| 76 | - Parameter\AuthenticationTagParameter::class); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Check whether the 'base64url-encode payload' parameter is present. |
|
| 81 | - * |
|
| 82 | - * @return bool |
|
| 83 | - */ |
|
| 84 | - public function hasB64Payload(): bool |
|
| 85 | - { |
|
| 86 | - return $this->has(Parameter\JWTParameter::P_B64); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Get the 'base64url-encode payload' parameter. |
|
| 91 | - * |
|
| 92 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 93 | - * @throws \LogicException If the parameter is not present |
|
| 94 | - * @return \JWX\JWT\Parameter\B64PayloadParameter |
|
| 95 | - */ |
|
| 96 | - public function B64Payload(): Parameter\B64PayloadParameter |
|
| 97 | - { |
|
| 98 | - return self::_checkType($this->get(Parameter\JWTParameter::P_B64), |
|
| 99 | - Parameter\B64PayloadParameter::class); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Check whether the compression algorithm parameter is present. |
|
| 104 | - * |
|
| 105 | - * @return bool |
|
| 106 | - */ |
|
| 107 | - public function hasCompressionAlgorithm(): bool |
|
| 108 | - { |
|
| 109 | - return $this->has(Parameter\JWTParameter::P_ZIP); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Get the compression algorithm parameter. |
|
| 114 | - * |
|
| 115 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 116 | - * @throws \LogicException If the parameter is not present |
|
| 117 | - * @return \JWX\JWT\Parameter\CompressionAlgorithmParameter |
|
| 118 | - */ |
|
| 119 | - public function compressionAlgorithm(): Parameter\CompressionAlgorithmParameter |
|
| 120 | - { |
|
| 121 | - return self::_checkType($this->get(Parameter\JWTParameter::P_ZIP), |
|
| 122 | - Parameter\CompressionAlgorithmParameter::class); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Check whether the content type parameter is present. |
|
| 127 | - * |
|
| 128 | - * @return bool |
|
| 129 | - */ |
|
| 130 | - public function hasContentType(): bool |
|
| 131 | - { |
|
| 132 | - return $this->has(Parameter\JWTParameter::P_CTY); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Get the content type parameter. |
|
| 137 | - * |
|
| 138 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 139 | - * @throws \LogicException If the parameter is not present |
|
| 140 | - * @return \JWX\JWT\Parameter\ContentTypeParameter |
|
| 141 | - */ |
|
| 142 | - public function contentType(): Parameter\ContentTypeParameter |
|
| 143 | - { |
|
| 144 | - return self::_checkType($this->get(Parameter\JWTParameter::P_CTY), |
|
| 145 | - Parameter\ContentTypeParameter::class); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Check whether the critical parameter is present. |
|
| 150 | - * |
|
| 151 | - * @return bool |
|
| 152 | - */ |
|
| 153 | - public function hasCritical(): bool |
|
| 154 | - { |
|
| 155 | - return $this->has(Parameter\JWTParameter::P_CRIT); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Get the critical parameter. |
|
| 160 | - * |
|
| 161 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 162 | - * @throws \LogicException If the parameter is not present |
|
| 163 | - * @return \JWX\JWT\Parameter\CriticalParameter |
|
| 164 | - */ |
|
| 165 | - public function critical(): Parameter\CriticalParameter |
|
| 166 | - { |
|
| 167 | - return self::_checkType($this->get(Parameter\JWTParameter::P_CRIT), |
|
| 168 | - Parameter\CriticalParameter::class); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Check whether the encryption algorithm parameter is present. |
|
| 173 | - * |
|
| 174 | - * @return bool |
|
| 175 | - */ |
|
| 176 | - public function hasEncryptionAlgorithm(): bool |
|
| 177 | - { |
|
| 178 | - return $this->has(Parameter\JWTParameter::P_ENC); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Get the encryption algorithm parameter. |
|
| 183 | - * |
|
| 184 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 185 | - * @throws \LogicException If the parameter is not present |
|
| 186 | - * @return \JWX\JWT\Parameter\EncryptionAlgorithmParameter |
|
| 187 | - */ |
|
| 188 | - public function encryptionAlgorithm(): Parameter\EncryptionAlgorithmParameter |
|
| 189 | - { |
|
| 190 | - return self::_checkType($this->get(Parameter\JWTParameter::P_ENC), |
|
| 191 | - Parameter\EncryptionAlgorithmParameter::class); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Check whether the initialization vector parameter is present. |
|
| 196 | - * |
|
| 197 | - * @return bool |
|
| 198 | - */ |
|
| 199 | - public function hasInitializationVector(): bool |
|
| 200 | - { |
|
| 201 | - return $this->has(Parameter\JWTParameter::P_IV); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Get the initialization vector parameter. |
|
| 206 | - * |
|
| 207 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 208 | - * @throws \LogicException If the parameter is not present |
|
| 209 | - * @return \JWX\JWT\Parameter\InitializationVectorParameter |
|
| 210 | - */ |
|
| 211 | - public function initializationVector(): Parameter\InitializationVectorParameter |
|
| 212 | - { |
|
| 213 | - return self::_checkType($this->get(Parameter\JWTParameter::P_IV), |
|
| 214 | - Parameter\InitializationVectorParameter::class); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Check whether the JSON web key parameter is present. |
|
| 219 | - * |
|
| 220 | - * @return bool |
|
| 221 | - */ |
|
| 222 | - public function hasJSONWebKey(): bool |
|
| 223 | - { |
|
| 224 | - return $this->has(Parameter\JWTParameter::P_JWK); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Get the JSON web key parameter. |
|
| 229 | - * |
|
| 230 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 231 | - * @throws \LogicException If the parameter is not present |
|
| 232 | - * @return \JWX\JWT\Parameter\JSONWebKeyParameter |
|
| 233 | - */ |
|
| 234 | - public function JSONWebKey(): Parameter\JSONWebKeyParameter |
|
| 235 | - { |
|
| 236 | - return self::_checkType($this->get(Parameter\JWTParameter::P_JWK), |
|
| 237 | - Parameter\JSONWebKeyParameter::class); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Check whether the JWK set URL parameter is present. |
|
| 242 | - * |
|
| 243 | - * @return bool |
|
| 244 | - */ |
|
| 245 | - public function hasJWKSetURL(): bool |
|
| 246 | - { |
|
| 247 | - return $this->has(Parameter\JWTParameter::P_JKU); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Get the JWK set URL parameter. |
|
| 252 | - * |
|
| 253 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 254 | - * @throws \LogicException If the parameter is not present |
|
| 255 | - * @return \JWX\JWT\Parameter\JWKSetURLParameter |
|
| 256 | - */ |
|
| 257 | - public function JWKSetURL(): Parameter\JWKSetURLParameter |
|
| 258 | - { |
|
| 259 | - return self::_checkType($this->get(Parameter\JWTParameter::P_JKU), |
|
| 260 | - Parameter\JWKSetURLParameter::class); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Check whether the key ID parameter is present. |
|
| 265 | - * |
|
| 266 | - * @return bool |
|
| 267 | - */ |
|
| 268 | - public function hasKeyID(): bool |
|
| 269 | - { |
|
| 270 | - return $this->has(Parameter\JWTParameter::P_KID); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Get the key ID parameter. |
|
| 275 | - * |
|
| 276 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 277 | - * @throws \LogicException If the parameter is not present |
|
| 278 | - * @return \JWX\JWT\Parameter\KeyIDParameter |
|
| 279 | - */ |
|
| 280 | - public function keyID(): Parameter\KeyIDParameter |
|
| 281 | - { |
|
| 282 | - return self::_checkType($this->get(Parameter\JWTParameter::P_KID), |
|
| 283 | - Parameter\KeyIDParameter::class); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Check whether the PBES2 count parameter is present. |
|
| 288 | - * |
|
| 289 | - * @return bool |
|
| 290 | - */ |
|
| 291 | - public function hasPBES2Count(): bool |
|
| 292 | - { |
|
| 293 | - return $this->has(Parameter\JWTParameter::P_P2C); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Get the PBES2 count parameter. |
|
| 298 | - * |
|
| 299 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 300 | - * @throws \LogicException If the parameter is not present |
|
| 301 | - * @return \JWX\JWT\Parameter\PBES2CountParameter |
|
| 302 | - */ |
|
| 303 | - public function PBES2Count(): Parameter\PBES2CountParameter |
|
| 304 | - { |
|
| 305 | - return self::_checkType($this->get(Parameter\JWTParameter::P_P2C), |
|
| 306 | - Parameter\PBES2CountParameter::class); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * Check whether the PBES2 salt input parameter is present. |
|
| 311 | - * |
|
| 312 | - * @return bool |
|
| 313 | - */ |
|
| 314 | - public function hasPBES2SaltInput(): bool |
|
| 315 | - { |
|
| 316 | - return $this->has(Parameter\JWTParameter::P_P2S); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Get the PBES2 salt input parameter. |
|
| 321 | - * |
|
| 322 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 323 | - * @throws \LogicException If the parameter is not present |
|
| 324 | - * @return \JWX\JWT\Parameter\PBES2SaltInputParameter |
|
| 325 | - */ |
|
| 326 | - public function PBES2SaltInput(): Parameter\PBES2SaltInputParameter |
|
| 327 | - { |
|
| 328 | - return self::_checkType($this->get(Parameter\JWTParameter::P_P2S), |
|
| 329 | - Parameter\PBES2SaltInputParameter::class); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Check whether the type parameter is present. |
|
| 334 | - * |
|
| 335 | - * @return bool |
|
| 336 | - */ |
|
| 337 | - public function hasType(): bool |
|
| 338 | - { |
|
| 339 | - return $this->has(Parameter\JWTParameter::P_TYP); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Get the type parameter. |
|
| 344 | - * |
|
| 345 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 346 | - * @throws \LogicException If the parameter is not present |
|
| 347 | - * @return \JWX\JWT\Parameter\TypeParameter |
|
| 348 | - */ |
|
| 349 | - public function type(): Parameter\TypeParameter |
|
| 350 | - { |
|
| 351 | - return self::_checkType($this->get(Parameter\JWTParameter::P_TYP), |
|
| 352 | - Parameter\TypeParameter::class); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Check whether the X.509 certificate chain parameter is present. |
|
| 357 | - * |
|
| 358 | - * @return bool |
|
| 359 | - */ |
|
| 360 | - public function hasX509CertificateChain(): bool |
|
| 361 | - { |
|
| 362 | - return $this->has(Parameter\JWTParameter::P_X5C); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Get the X.509 certificate chain parameter. |
|
| 367 | - * |
|
| 368 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 369 | - * @throws \LogicException If the parameter is not present |
|
| 370 | - * @return \JWX\JWT\Parameter\X509CertificateChainParameter |
|
| 371 | - */ |
|
| 372 | - public function X509CertificateChain(): Parameter\X509CertificateChainParameter |
|
| 373 | - { |
|
| 374 | - return self::_checkType($this->get(Parameter\JWTParameter::P_X5C), |
|
| 375 | - Parameter\X509CertificateChainParameter::class); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * Check whether the X.509 certificate SHA-1 thumbprint parameter is |
|
| 380 | - * present. |
|
| 381 | - * |
|
| 382 | - * @return bool |
|
| 383 | - */ |
|
| 384 | - public function hasX509CertificateSHA1Thumbprint(): bool |
|
| 385 | - { |
|
| 386 | - return $this->has(Parameter\JWTParameter::P_X5T); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Get the X.509 certificate SHA-1 thumbprint parameter. |
|
| 391 | - * |
|
| 392 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 393 | - * @throws \LogicException If the parameter is not present |
|
| 394 | - * @return \JWX\JWT\Parameter\X509CertificateSHA1ThumbprintParameter |
|
| 395 | - */ |
|
| 396 | - public function X509CertificateSHA1Thumbprint(): Parameter\X509CertificateSHA1ThumbprintParameter |
|
| 397 | - { |
|
| 398 | - return self::_checkType($this->get(Parameter\JWTParameter::P_X5T), |
|
| 399 | - Parameter\X509CertificateSHA1ThumbprintParameter::class); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * Check whether the X.509 certificate SHA-256 thumbprint parameter is |
|
| 404 | - * present. |
|
| 405 | - * |
|
| 406 | - * @return bool |
|
| 407 | - */ |
|
| 408 | - public function hasX509CertificateSHA256Thumbprint(): bool |
|
| 409 | - { |
|
| 410 | - return $this->has(Parameter\JWTParameter::P_X5TS256); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Get the X.509 certificate SHA-256 thumbprint parameter. |
|
| 415 | - * |
|
| 416 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 417 | - * @throws \LogicException If the parameter is not present |
|
| 418 | - * @return \JWX\JWT\Parameter\X509CertificateSHA256ThumbprintParameter |
|
| 419 | - */ |
|
| 420 | - public function X509CertificateSHA256Thumbprint(): Parameter\X509CertificateSHA256ThumbprintParameter |
|
| 421 | - { |
|
| 422 | - return self::_checkType($this->get(Parameter\JWTParameter::P_X5TS256), |
|
| 423 | - Parameter\X509CertificateSHA256ThumbprintParameter::class); |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Check whether the X.509 URL parameter is present. |
|
| 428 | - * |
|
| 429 | - * @return bool |
|
| 430 | - */ |
|
| 431 | - public function hasX509URL(): bool |
|
| 432 | - { |
|
| 433 | - return $this->has(Parameter\JWTParameter::P_X5U); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Get the X.509 URL parameter. |
|
| 438 | - * |
|
| 439 | - * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 440 | - * @throws \LogicException If the parameter is not present |
|
| 441 | - * @return \JWX\JWT\Parameter\X509URLParameter |
|
| 442 | - */ |
|
| 443 | - public function X509URL(): Parameter\X509URLParameter |
|
| 444 | - { |
|
| 445 | - return self::_checkType($this->get(Parameter\JWTParameter::P_X5U), |
|
| 446 | - Parameter\X509URLParameter::class); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * Check that the parameter is an instance of the given class. |
|
| 451 | - * |
|
| 452 | - * @param \JWX\JWT\Parameter\JWTParameter $param Parameter |
|
| 453 | - * @param string $cls Class name |
|
| 454 | - * @throws \UnexpectedValueException |
|
| 455 | - * @return \JWX\JWT\Parameter\JWTParameter |
|
| 456 | - */ |
|
| 457 | - private static function _checkType(Parameter\JWTParameter $param, string $cls): Parameter\JWTParameter |
|
| 458 | - { |
|
| 459 | - if (!$param instanceof $cls) { |
|
| 460 | - throw new \UnexpectedValueException( |
|
| 461 | - "$cls expected, got " . get_class($param)); |
|
| 462 | - } |
|
| 463 | - return $param; |
|
| 464 | - } |
|
| 16 | + /** |
|
| 17 | + * Whether parameters are present. |
|
| 18 | + * |
|
| 19 | + * @param string ...$names Parameter names |
|
| 20 | + * @return bool |
|
| 21 | + */ |
|
| 22 | + abstract public function has(string ...$names): bool; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Get a parameter. |
|
| 26 | + * |
|
| 27 | + * @param string $name Parameter name |
|
| 28 | + * @throws \LogicException If the parameter is not present |
|
| 29 | + * @return JWTParameter |
|
| 30 | + */ |
|
| 31 | + abstract public function get(string $name): JWTParameter; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Check whether the algorithm parameter is present. |
|
| 35 | + * |
|
| 36 | + * @return bool |
|
| 37 | + */ |
|
| 38 | + public function hasAlgorithm(): bool |
|
| 39 | + { |
|
| 40 | + return $this->has(Parameter\JWTParameter::P_ALG); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Get the algorithm parameter. |
|
| 45 | + * |
|
| 46 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 47 | + * @throws \LogicException If the parameter is not present |
|
| 48 | + * @return \JWX\JWT\Parameter\AlgorithmParameter |
|
| 49 | + */ |
|
| 50 | + public function algorithm(): Parameter\AlgorithmParameter |
|
| 51 | + { |
|
| 52 | + return self::_checkType($this->get(Parameter\JWTParameter::P_ALG), |
|
| 53 | + Parameter\AlgorithmParameter::class); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Check whether the authentication tag parameter is present. |
|
| 58 | + * |
|
| 59 | + * @return bool |
|
| 60 | + */ |
|
| 61 | + public function hasAuthenticationTag(): bool |
|
| 62 | + { |
|
| 63 | + return $this->has(Parameter\JWTParameter::P_TAG); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Get the authentication tag parameter. |
|
| 68 | + * |
|
| 69 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 70 | + * @throws \LogicException If the parameter is not present |
|
| 71 | + * @return \JWX\JWT\Parameter\AuthenticationTagParameter |
|
| 72 | + */ |
|
| 73 | + public function authenticationTag(): Parameter\AuthenticationTagParameter |
|
| 74 | + { |
|
| 75 | + return self::_checkType($this->get(Parameter\JWTParameter::P_TAG), |
|
| 76 | + Parameter\AuthenticationTagParameter::class); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Check whether the 'base64url-encode payload' parameter is present. |
|
| 81 | + * |
|
| 82 | + * @return bool |
|
| 83 | + */ |
|
| 84 | + public function hasB64Payload(): bool |
|
| 85 | + { |
|
| 86 | + return $this->has(Parameter\JWTParameter::P_B64); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Get the 'base64url-encode payload' parameter. |
|
| 91 | + * |
|
| 92 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 93 | + * @throws \LogicException If the parameter is not present |
|
| 94 | + * @return \JWX\JWT\Parameter\B64PayloadParameter |
|
| 95 | + */ |
|
| 96 | + public function B64Payload(): Parameter\B64PayloadParameter |
|
| 97 | + { |
|
| 98 | + return self::_checkType($this->get(Parameter\JWTParameter::P_B64), |
|
| 99 | + Parameter\B64PayloadParameter::class); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Check whether the compression algorithm parameter is present. |
|
| 104 | + * |
|
| 105 | + * @return bool |
|
| 106 | + */ |
|
| 107 | + public function hasCompressionAlgorithm(): bool |
|
| 108 | + { |
|
| 109 | + return $this->has(Parameter\JWTParameter::P_ZIP); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Get the compression algorithm parameter. |
|
| 114 | + * |
|
| 115 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 116 | + * @throws \LogicException If the parameter is not present |
|
| 117 | + * @return \JWX\JWT\Parameter\CompressionAlgorithmParameter |
|
| 118 | + */ |
|
| 119 | + public function compressionAlgorithm(): Parameter\CompressionAlgorithmParameter |
|
| 120 | + { |
|
| 121 | + return self::_checkType($this->get(Parameter\JWTParameter::P_ZIP), |
|
| 122 | + Parameter\CompressionAlgorithmParameter::class); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Check whether the content type parameter is present. |
|
| 127 | + * |
|
| 128 | + * @return bool |
|
| 129 | + */ |
|
| 130 | + public function hasContentType(): bool |
|
| 131 | + { |
|
| 132 | + return $this->has(Parameter\JWTParameter::P_CTY); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Get the content type parameter. |
|
| 137 | + * |
|
| 138 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 139 | + * @throws \LogicException If the parameter is not present |
|
| 140 | + * @return \JWX\JWT\Parameter\ContentTypeParameter |
|
| 141 | + */ |
|
| 142 | + public function contentType(): Parameter\ContentTypeParameter |
|
| 143 | + { |
|
| 144 | + return self::_checkType($this->get(Parameter\JWTParameter::P_CTY), |
|
| 145 | + Parameter\ContentTypeParameter::class); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Check whether the critical parameter is present. |
|
| 150 | + * |
|
| 151 | + * @return bool |
|
| 152 | + */ |
|
| 153 | + public function hasCritical(): bool |
|
| 154 | + { |
|
| 155 | + return $this->has(Parameter\JWTParameter::P_CRIT); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Get the critical parameter. |
|
| 160 | + * |
|
| 161 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 162 | + * @throws \LogicException If the parameter is not present |
|
| 163 | + * @return \JWX\JWT\Parameter\CriticalParameter |
|
| 164 | + */ |
|
| 165 | + public function critical(): Parameter\CriticalParameter |
|
| 166 | + { |
|
| 167 | + return self::_checkType($this->get(Parameter\JWTParameter::P_CRIT), |
|
| 168 | + Parameter\CriticalParameter::class); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Check whether the encryption algorithm parameter is present. |
|
| 173 | + * |
|
| 174 | + * @return bool |
|
| 175 | + */ |
|
| 176 | + public function hasEncryptionAlgorithm(): bool |
|
| 177 | + { |
|
| 178 | + return $this->has(Parameter\JWTParameter::P_ENC); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Get the encryption algorithm parameter. |
|
| 183 | + * |
|
| 184 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 185 | + * @throws \LogicException If the parameter is not present |
|
| 186 | + * @return \JWX\JWT\Parameter\EncryptionAlgorithmParameter |
|
| 187 | + */ |
|
| 188 | + public function encryptionAlgorithm(): Parameter\EncryptionAlgorithmParameter |
|
| 189 | + { |
|
| 190 | + return self::_checkType($this->get(Parameter\JWTParameter::P_ENC), |
|
| 191 | + Parameter\EncryptionAlgorithmParameter::class); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Check whether the initialization vector parameter is present. |
|
| 196 | + * |
|
| 197 | + * @return bool |
|
| 198 | + */ |
|
| 199 | + public function hasInitializationVector(): bool |
|
| 200 | + { |
|
| 201 | + return $this->has(Parameter\JWTParameter::P_IV); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Get the initialization vector parameter. |
|
| 206 | + * |
|
| 207 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 208 | + * @throws \LogicException If the parameter is not present |
|
| 209 | + * @return \JWX\JWT\Parameter\InitializationVectorParameter |
|
| 210 | + */ |
|
| 211 | + public function initializationVector(): Parameter\InitializationVectorParameter |
|
| 212 | + { |
|
| 213 | + return self::_checkType($this->get(Parameter\JWTParameter::P_IV), |
|
| 214 | + Parameter\InitializationVectorParameter::class); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Check whether the JSON web key parameter is present. |
|
| 219 | + * |
|
| 220 | + * @return bool |
|
| 221 | + */ |
|
| 222 | + public function hasJSONWebKey(): bool |
|
| 223 | + { |
|
| 224 | + return $this->has(Parameter\JWTParameter::P_JWK); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Get the JSON web key parameter. |
|
| 229 | + * |
|
| 230 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 231 | + * @throws \LogicException If the parameter is not present |
|
| 232 | + * @return \JWX\JWT\Parameter\JSONWebKeyParameter |
|
| 233 | + */ |
|
| 234 | + public function JSONWebKey(): Parameter\JSONWebKeyParameter |
|
| 235 | + { |
|
| 236 | + return self::_checkType($this->get(Parameter\JWTParameter::P_JWK), |
|
| 237 | + Parameter\JSONWebKeyParameter::class); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Check whether the JWK set URL parameter is present. |
|
| 242 | + * |
|
| 243 | + * @return bool |
|
| 244 | + */ |
|
| 245 | + public function hasJWKSetURL(): bool |
|
| 246 | + { |
|
| 247 | + return $this->has(Parameter\JWTParameter::P_JKU); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Get the JWK set URL parameter. |
|
| 252 | + * |
|
| 253 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 254 | + * @throws \LogicException If the parameter is not present |
|
| 255 | + * @return \JWX\JWT\Parameter\JWKSetURLParameter |
|
| 256 | + */ |
|
| 257 | + public function JWKSetURL(): Parameter\JWKSetURLParameter |
|
| 258 | + { |
|
| 259 | + return self::_checkType($this->get(Parameter\JWTParameter::P_JKU), |
|
| 260 | + Parameter\JWKSetURLParameter::class); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Check whether the key ID parameter is present. |
|
| 265 | + * |
|
| 266 | + * @return bool |
|
| 267 | + */ |
|
| 268 | + public function hasKeyID(): bool |
|
| 269 | + { |
|
| 270 | + return $this->has(Parameter\JWTParameter::P_KID); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Get the key ID parameter. |
|
| 275 | + * |
|
| 276 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 277 | + * @throws \LogicException If the parameter is not present |
|
| 278 | + * @return \JWX\JWT\Parameter\KeyIDParameter |
|
| 279 | + */ |
|
| 280 | + public function keyID(): Parameter\KeyIDParameter |
|
| 281 | + { |
|
| 282 | + return self::_checkType($this->get(Parameter\JWTParameter::P_KID), |
|
| 283 | + Parameter\KeyIDParameter::class); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Check whether the PBES2 count parameter is present. |
|
| 288 | + * |
|
| 289 | + * @return bool |
|
| 290 | + */ |
|
| 291 | + public function hasPBES2Count(): bool |
|
| 292 | + { |
|
| 293 | + return $this->has(Parameter\JWTParameter::P_P2C); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Get the PBES2 count parameter. |
|
| 298 | + * |
|
| 299 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 300 | + * @throws \LogicException If the parameter is not present |
|
| 301 | + * @return \JWX\JWT\Parameter\PBES2CountParameter |
|
| 302 | + */ |
|
| 303 | + public function PBES2Count(): Parameter\PBES2CountParameter |
|
| 304 | + { |
|
| 305 | + return self::_checkType($this->get(Parameter\JWTParameter::P_P2C), |
|
| 306 | + Parameter\PBES2CountParameter::class); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * Check whether the PBES2 salt input parameter is present. |
|
| 311 | + * |
|
| 312 | + * @return bool |
|
| 313 | + */ |
|
| 314 | + public function hasPBES2SaltInput(): bool |
|
| 315 | + { |
|
| 316 | + return $this->has(Parameter\JWTParameter::P_P2S); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Get the PBES2 salt input parameter. |
|
| 321 | + * |
|
| 322 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 323 | + * @throws \LogicException If the parameter is not present |
|
| 324 | + * @return \JWX\JWT\Parameter\PBES2SaltInputParameter |
|
| 325 | + */ |
|
| 326 | + public function PBES2SaltInput(): Parameter\PBES2SaltInputParameter |
|
| 327 | + { |
|
| 328 | + return self::_checkType($this->get(Parameter\JWTParameter::P_P2S), |
|
| 329 | + Parameter\PBES2SaltInputParameter::class); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Check whether the type parameter is present. |
|
| 334 | + * |
|
| 335 | + * @return bool |
|
| 336 | + */ |
|
| 337 | + public function hasType(): bool |
|
| 338 | + { |
|
| 339 | + return $this->has(Parameter\JWTParameter::P_TYP); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Get the type parameter. |
|
| 344 | + * |
|
| 345 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 346 | + * @throws \LogicException If the parameter is not present |
|
| 347 | + * @return \JWX\JWT\Parameter\TypeParameter |
|
| 348 | + */ |
|
| 349 | + public function type(): Parameter\TypeParameter |
|
| 350 | + { |
|
| 351 | + return self::_checkType($this->get(Parameter\JWTParameter::P_TYP), |
|
| 352 | + Parameter\TypeParameter::class); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Check whether the X.509 certificate chain parameter is present. |
|
| 357 | + * |
|
| 358 | + * @return bool |
|
| 359 | + */ |
|
| 360 | + public function hasX509CertificateChain(): bool |
|
| 361 | + { |
|
| 362 | + return $this->has(Parameter\JWTParameter::P_X5C); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Get the X.509 certificate chain parameter. |
|
| 367 | + * |
|
| 368 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 369 | + * @throws \LogicException If the parameter is not present |
|
| 370 | + * @return \JWX\JWT\Parameter\X509CertificateChainParameter |
|
| 371 | + */ |
|
| 372 | + public function X509CertificateChain(): Parameter\X509CertificateChainParameter |
|
| 373 | + { |
|
| 374 | + return self::_checkType($this->get(Parameter\JWTParameter::P_X5C), |
|
| 375 | + Parameter\X509CertificateChainParameter::class); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * Check whether the X.509 certificate SHA-1 thumbprint parameter is |
|
| 380 | + * present. |
|
| 381 | + * |
|
| 382 | + * @return bool |
|
| 383 | + */ |
|
| 384 | + public function hasX509CertificateSHA1Thumbprint(): bool |
|
| 385 | + { |
|
| 386 | + return $this->has(Parameter\JWTParameter::P_X5T); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Get the X.509 certificate SHA-1 thumbprint parameter. |
|
| 391 | + * |
|
| 392 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 393 | + * @throws \LogicException If the parameter is not present |
|
| 394 | + * @return \JWX\JWT\Parameter\X509CertificateSHA1ThumbprintParameter |
|
| 395 | + */ |
|
| 396 | + public function X509CertificateSHA1Thumbprint(): Parameter\X509CertificateSHA1ThumbprintParameter |
|
| 397 | + { |
|
| 398 | + return self::_checkType($this->get(Parameter\JWTParameter::P_X5T), |
|
| 399 | + Parameter\X509CertificateSHA1ThumbprintParameter::class); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * Check whether the X.509 certificate SHA-256 thumbprint parameter is |
|
| 404 | + * present. |
|
| 405 | + * |
|
| 406 | + * @return bool |
|
| 407 | + */ |
|
| 408 | + public function hasX509CertificateSHA256Thumbprint(): bool |
|
| 409 | + { |
|
| 410 | + return $this->has(Parameter\JWTParameter::P_X5TS256); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Get the X.509 certificate SHA-256 thumbprint parameter. |
|
| 415 | + * |
|
| 416 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 417 | + * @throws \LogicException If the parameter is not present |
|
| 418 | + * @return \JWX\JWT\Parameter\X509CertificateSHA256ThumbprintParameter |
|
| 419 | + */ |
|
| 420 | + public function X509CertificateSHA256Thumbprint(): Parameter\X509CertificateSHA256ThumbprintParameter |
|
| 421 | + { |
|
| 422 | + return self::_checkType($this->get(Parameter\JWTParameter::P_X5TS256), |
|
| 423 | + Parameter\X509CertificateSHA256ThumbprintParameter::class); |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Check whether the X.509 URL parameter is present. |
|
| 428 | + * |
|
| 429 | + * @return bool |
|
| 430 | + */ |
|
| 431 | + public function hasX509URL(): bool |
|
| 432 | + { |
|
| 433 | + return $this->has(Parameter\JWTParameter::P_X5U); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Get the X.509 URL parameter. |
|
| 438 | + * |
|
| 439 | + * @throws \UnexpectedValueException If the parameter has a wrong class |
|
| 440 | + * @throws \LogicException If the parameter is not present |
|
| 441 | + * @return \JWX\JWT\Parameter\X509URLParameter |
|
| 442 | + */ |
|
| 443 | + public function X509URL(): Parameter\X509URLParameter |
|
| 444 | + { |
|
| 445 | + return self::_checkType($this->get(Parameter\JWTParameter::P_X5U), |
|
| 446 | + Parameter\X509URLParameter::class); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * Check that the parameter is an instance of the given class. |
|
| 451 | + * |
|
| 452 | + * @param \JWX\JWT\Parameter\JWTParameter $param Parameter |
|
| 453 | + * @param string $cls Class name |
|
| 454 | + * @throws \UnexpectedValueException |
|
| 455 | + * @return \JWX\JWT\Parameter\JWTParameter |
|
| 456 | + */ |
|
| 457 | + private static function _checkType(Parameter\JWTParameter $param, string $cls): Parameter\JWTParameter |
|
| 458 | + { |
|
| 459 | + if (!$param instanceof $cls) { |
|
| 460 | + throw new \UnexpectedValueException( |
|
| 461 | + "$cls expected, got " . get_class($param)); |
|
| 462 | + } |
|
| 463 | + return $param; |
|
| 464 | + } |
|
| 465 | 465 | } |