@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | $this->algorithms[JSONWebSignatureAndEncryptionAlgorithms::Dir] = new DirAlgorithm; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - private function __clone(){} |
|
| 46 | + private function __clone() {} |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * @return KeyManagementAlgorithms_Registry |
| 50 | 50 | */ |
| 51 | 51 | public static function getInstance() |
| 52 | 52 | { |
| 53 | - if(!is_object(self::$instance)) |
|
| 53 | + if (!is_object(self::$instance)) |
|
| 54 | 54 | { |
| 55 | 55 | self::$instance = new KeyManagementAlgorithms_Registry(); |
| 56 | 56 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function get($alg) |
| 74 | 74 | { |
| 75 | - if(!$this->isSupported($alg)) return null; |
|
| 75 | + if (!$this->isSupported($alg)) return null; |
|
| 76 | 76 | return $this->algorithms[$alg]; |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | \ No newline at end of file |
@@ -35,10 +35,10 @@ discard block |
||
| 35 | 35 | * @return string |
| 36 | 36 | * @throws InvalidKeyLengthAlgorithmException |
| 37 | 37 | */ |
| 38 | - public function digest(SharedKey $key, $message){ |
|
| 38 | + public function digest(SharedKey $key, $message) { |
|
| 39 | 39 | |
| 40 | - if($this->getMinKeyLen() > $key->getBitLength()) |
|
| 41 | - throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.',$this->getMinKeyLen(), $key->getBitLength())); |
|
| 40 | + if ($this->getMinKeyLen() > $key->getBitLength()) |
|
| 41 | + throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.', $this->getMinKeyLen(), $key->getBitLength())); |
|
| 42 | 42 | |
| 43 | 43 | return hash_hmac($this->getHashingAlgorithm(), $message, $key->getSecret(), true); |
| 44 | 44 | } |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | * @throws InvalidKeyLengthAlgorithmException |
| 52 | 52 | * @throws InvalidKeyTypeAlgorithmException |
| 53 | 53 | */ |
| 54 | - public function verify(Key $key, $message, $digest){ |
|
| 55 | - if(!($key instanceof SharedKey)) throw new InvalidKeyTypeAlgorithmException; |
|
| 54 | + public function verify(Key $key, $message, $digest) { |
|
| 55 | + if (!($key instanceof SharedKey)) throw new InvalidKeyTypeAlgorithmException; |
|
| 56 | 56 | |
| 57 | 57 | return $digest === $this->digest($key, $message); |
| 58 | 58 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | extends Abstract_RSA_Algorithm |
| 31 | 31 | implements EncryptionAlgorithm, KeyEncryption { |
| 32 | 32 | |
| 33 | - public function __construct(){ |
|
| 33 | + public function __construct() { |
|
| 34 | 34 | |
| 35 | 35 | parent::__construct(); |
| 36 | 36 | //configuration ... |
@@ -47,18 +47,18 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function encrypt(Key $key, $message) |
| 49 | 49 | { |
| 50 | - if(!($key instanceof RSAPublicKey)) |
|
| 50 | + if (!($key instanceof RSAPublicKey)) |
|
| 51 | 51 | throw new InvalidKeyTypeAlgorithmException('key is not public'); |
| 52 | 52 | |
| 53 | - if($key->getFormat() !== 'PKCS8') |
|
| 53 | + if ($key->getFormat() !== 'PKCS8') |
|
| 54 | 54 | throw new InvalidKeyTypeAlgorithmException('keys is not on PKCS1 format'); |
| 55 | 55 | |
| 56 | 56 | $res = $this->rsa_impl->loadKey($key->getEncoded()); |
| 57 | 57 | |
| 58 | - if(!$res) |
|
| 58 | + if (!$res) |
|
| 59 | 59 | throw new InvalidKeyTypeAlgorithmException('could not parse the key'); |
| 60 | 60 | |
| 61 | - if($this->rsa_impl->getSize() < $this->getMinKeyLen()) |
|
| 61 | + if ($this->rsa_impl->getSize() < $this->getMinKeyLen()) |
|
| 62 | 62 | throw new InvalidKeyTypeAlgorithmException('len is invalid'); |
| 63 | 63 | |
| 64 | 64 | return $this->rsa_impl->encrypt($message); |
@@ -70,21 +70,21 @@ discard block |
||
| 70 | 70 | * @return string |
| 71 | 71 | * @throws InvalidKeyTypeAlgorithmException |
| 72 | 72 | */ |
| 73 | - public function decrypt(Key $key, $enc_message){ |
|
| 73 | + public function decrypt(Key $key, $enc_message) { |
|
| 74 | 74 | |
| 75 | - if(!($key instanceof RSAPrivateKey)) |
|
| 75 | + if (!($key instanceof RSAPrivateKey)) |
|
| 76 | 76 | throw new InvalidKeyTypeAlgorithmException('key is not private'); |
| 77 | 77 | |
| 78 | 78 | |
| 79 | - if($key->getFormat() !== 'PKCS1') |
|
| 79 | + if ($key->getFormat() !== 'PKCS1') |
|
| 80 | 80 | throw new InvalidKeyTypeAlgorithmException('keys is not on PKCS1 format'); |
| 81 | 81 | |
| 82 | 82 | $res = $this->rsa_impl->loadKey($key->getEncoded()); |
| 83 | 83 | |
| 84 | - if(!$res) |
|
| 84 | + if (!$res) |
|
| 85 | 85 | throw new InvalidKeyTypeAlgorithmException('could not parse the key'); |
| 86 | 86 | |
| 87 | - if($this->rsa_impl->getSize() < $this->getMinKeyLen()) |
|
| 87 | + if ($this->rsa_impl->getSize() < $this->getMinKeyLen()) |
|
| 88 | 88 | throw new InvalidKeyTypeAlgorithmException('len is invalid'); |
| 89 | 89 | |
| 90 | 90 | return $this->rsa_impl->decrypt($enc_message); |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | { |
| 61 | 61 | $key_len = strlen($key); |
| 62 | 62 | |
| 63 | - if($this->getMinKeyLen() > ByteUtil::bitLength($key_len)) |
|
| 63 | + if ($this->getMinKeyLen() > ByteUtil::bitLength($key_len)) |
|
| 64 | 64 | throw new InvalidKeyLengthAlgorithmException; |
| 65 | 65 | |
| 66 | 66 | $enc_key_len = $key_len / 2; |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | public function decrypt($cypher_text, $key, $iv, $aad, $tag) |
| 135 | 135 | { |
| 136 | - if(!$this->checkAuthenticationTag($cypher_text, $key, $iv, $aad, $tag)) |
|
| 136 | + if (!$this->checkAuthenticationTag($cypher_text, $key, $iv, $aad, $tag)) |
|
| 137 | 137 | throw new InvalidAuthenticationTagException; |
| 138 | 138 | |
| 139 | 139 | $enc_key_len = strlen($key) / 2; |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param string $name |
| 45 | 45 | * @param JsonValue $value |
| 46 | 46 | */ |
| 47 | - public function __construct($name , $value){ |
|
| 47 | + public function __construct($name, $value) { |
|
| 48 | 48 | $this->name = $name; |
| 49 | 49 | $this->value = $value; |
| 50 | 50 | } |
@@ -53,21 +53,21 @@ discard block |
||
| 53 | 53 | /** |
| 54 | 54 | * @return string |
| 55 | 55 | */ |
| 56 | - public function getName(){ |
|
| 56 | + public function getName() { |
|
| 57 | 57 | return $this->name; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * @return JsonValue |
| 62 | 62 | */ |
| 63 | - public function getValue(){ |
|
| 63 | + public function getValue() { |
|
| 64 | 64 | return $this->value; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * @return array|bool|int|string|\utils\json_types\IJsonObject |
| 69 | 69 | */ |
| 70 | - public function getRawValue(){ |
|
| 70 | + public function getRawValue() { |
|
| 71 | 71 | return $this->getValue()->getValue(); |
| 72 | 72 | } |
| 73 | 73 | |
@@ -105,9 +105,8 @@ discard block |
||
| 105 | 105 | * @var array |
| 106 | 106 | * @see jwt/impl/JWTClaimSet.php constructor |
| 107 | 107 | */ |
| 108 | - public static $registered_claim_set = array |
|
| 109 | - ( |
|
| 110 | - self::Issuer , |
|
| 108 | + public static $registered_claim_set = array( |
|
| 109 | + self::Issuer, |
|
| 111 | 110 | self::Subject, |
| 112 | 111 | self::Audience, |
| 113 | 112 | self::IssuedAt, |
@@ -119,8 +118,7 @@ discard block |
||
| 119 | 118 | /** |
| 120 | 119 | * @var array |
| 121 | 120 | */ |
| 122 | - public static $registered_claim_set_types = array |
|
| 123 | - ( |
|
| 121 | + public static $registered_claim_set_types = array( |
|
| 124 | 122 | self::Issuer => JsonTypes::StringOrURI, |
| 125 | 123 | self::Audience => JsonTypes::StringOrURI, |
| 126 | 124 | self::Subject => JsonTypes::StringOrURI, |
@@ -91,9 +91,8 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function take() |
| 93 | 93 | { |
| 94 | - $payload = ($this->header->getType()->getString() === 'JWT') ? $this->claim_set : ''; |
|
| 95 | - return array |
|
| 96 | - ( |
|
| 94 | + $payload = ($this->header->getType()->getString() === 'JWT') ? $this->claim_set : ''; |
|
| 95 | + return array( |
|
| 97 | 96 | $this->header, |
| 98 | 97 | $payload, |
| 99 | 98 | $this->signature |
@@ -108,9 +107,9 @@ discard block |
||
| 108 | 107 | { |
| 109 | 108 | $now = new \DateTime(); |
| 110 | 109 | $exp = $this->getClaimSet()->getExpirationTime()->getDateTime(); |
| 111 | - if($exp < $now) return true; |
|
| 110 | + if ($exp < $now) return true; |
|
| 112 | 111 | $iat = $this->getClaimSet()->getIssuedAt()->getDateTime(); |
| 113 | - if($iat > $now) return true; |
|
| 112 | + if ($iat > $now) return true; |
|
| 114 | 113 | $diff = $now->getTimestamp() - $iat->getTimestamp(); |
| 115 | 114 | return $diff > $tolerance; |
| 116 | 115 | } |
@@ -40,8 +40,7 @@ discard block |
||
| 40 | 40 | * @param JsonValue $id |
| 41 | 41 | * @param NumericDate $nbf |
| 42 | 42 | */ |
| 43 | - public function __construct |
|
| 44 | - ( |
|
| 43 | + public function __construct( |
|
| 45 | 44 | StringOrURI $issuer = null, |
| 46 | 45 | StringOrURI $subject = null, |
| 47 | 46 | StringOrURI $audience = null, |
@@ -135,7 +134,7 @@ discard block |
||
| 135 | 134 | public function getClaims() |
| 136 | 135 | { |
| 137 | 136 | $claims = array(); |
| 138 | - foreach($this->set as $k => $v) |
|
| 137 | + foreach ($this->set as $k => $v) |
|
| 139 | 138 | { |
| 140 | 139 | array_push($claims, new JWTClaim($k, $v)); |
| 141 | 140 | } |
@@ -260,7 +259,6 @@ discard block |
||
| 260 | 259 | public function getClaimByName($claim_name) |
| 261 | 260 | { |
| 262 | 261 | return isset($this->set[$claim_name]) ? |
| 263 | - $this->set[$claim_name] : |
|
| 264 | - null; |
|
| 262 | + $this->set[$claim_name] : null; |
|
| 265 | 263 | } |
| 266 | 264 | } |
| 267 | 265 | \ No newline at end of file |
@@ -33,8 +33,7 @@ discard block |
||
| 33 | 33 | * @param JsonValue|null $kid |
| 34 | 34 | * @param StringOrURI|null $cty |
| 35 | 35 | */ |
| 36 | - public function __construct |
|
| 37 | - ( |
|
| 36 | + public function __construct( |
|
| 38 | 37 | StringOrURI $alg, |
| 39 | 38 | StringOrURI $type = null, |
| 40 | 39 | JsonValue $kid = null, |
@@ -96,7 +95,7 @@ discard block |
||
| 96 | 95 | public function getHeaderByName($name) |
| 97 | 96 | { |
| 98 | 97 | $value = $this[$name]; |
| 99 | - if(is_null($value)) return null; |
|
| 98 | + if (is_null($value)) return null; |
|
| 100 | 99 | return new JOSEHeaderParam($name, $value); |
| 101 | 100 | } |
| 102 | 101 | } |
| 103 | 102 | \ No newline at end of file |