@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | * @param JWK[] $keys |
43 | 43 | * @throws JWKInvalidIdentifierException |
44 | 44 | */ |
45 | - public function __construct(array $keys = array()){ |
|
45 | + public function __construct(array $keys = array()) { |
|
46 | 46 | |
47 | 47 | $this->set[JWKSetParameters::Keys] = new JsonArray(array()); |
48 | 48 | |
49 | - foreach($keys as $k){ |
|
49 | + foreach ($keys as $k) { |
|
50 | 50 | $this->addKey($k); |
51 | 51 | } |
52 | 52 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function getKeys() |
58 | 58 | { |
59 | - if(isset($this->set[JWKSetParameters::Keys])) |
|
59 | + if (isset($this->set[JWKSetParameters::Keys])) |
|
60 | 60 | return $this->set[JWKSetParameters::Keys]->getValue(); |
61 | 61 | return array(); |
62 | 62 | } |
@@ -70,18 +70,18 @@ discard block |
||
70 | 70 | { |
71 | 71 | $id = $key->getId(); |
72 | 72 | |
73 | - if(empty($id)) |
|
73 | + if (empty($id)) |
|
74 | 74 | throw new JWKInvalidIdentifierException('key id is empty!'); |
75 | 75 | |
76 | - if(array_key_exists($id->getValue(), $this->keys_ids)) |
|
76 | + if (array_key_exists($id->getValue(), $this->keys_ids)) |
|
77 | 77 | throw new JWKInvalidIdentifierException(sprintf('id %s already exists!'), $key->getId()->getValue()); |
78 | 78 | |
79 | - if(!isset($this->set[JWKSetParameters::Keys])) |
|
79 | + if (!isset($this->set[JWKSetParameters::Keys])) |
|
80 | 80 | $this->set[JWKSetParameters::Keys] = new JsonArray(array()); |
81 | 81 | |
82 | 82 | $keys = $this->set[JWKSetParameters::Keys]; |
83 | 83 | $keys->append($key); |
84 | - $this->set[JWKSetParameters::Keys] = $keys ; |
|
84 | + $this->set[JWKSetParameters::Keys] = $keys; |
|
85 | 85 | $this->keys_ids[$id->getValue()] = $key; |
86 | 86 | } |
87 | 87 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function getKeyById($kid) |
93 | 93 | { |
94 | - if(!array_key_exists($kid, $this->keys_ids)) return null; |
|
94 | + if (!array_key_exists($kid, $this->keys_ids)) return null; |
|
95 | 95 | return $this->keys_ids[$kid]; |
96 | 96 | } |
97 | 97 | |
@@ -101,27 +101,27 @@ discard block |
||
101 | 101 | * @throws InvalidJWKAlgorithm |
102 | 102 | * @throws JWKInvalidIdentifierException |
103 | 103 | */ |
104 | - static public function fromJson($json){ |
|
105 | - $json = str_replace( array("\n","\r","\t"), '', trim($json)); |
|
104 | + static public function fromJson($json) { |
|
105 | + $json = str_replace(array("\n", "\r", "\t"), '', trim($json)); |
|
106 | 106 | $res = json_decode($json, true); |
107 | - if(!isset($res[JWKSetParameters::Keys])) throw new JWKInvalidIdentifierException; |
|
107 | + if (!isset($res[JWKSetParameters::Keys])) throw new JWKInvalidIdentifierException; |
|
108 | 108 | $keys = $res[JWKSetParameters::Keys]; |
109 | 109 | $jwk_set = new JWKSet; |
110 | - foreach($keys as $key){ |
|
110 | + foreach ($keys as $key) { |
|
111 | 111 | $kty = @$key[JSONWebKeyParameters::KeyType]; |
112 | 112 | $kid = @$key[JSONWebKeyParameters::KeyId]; |
113 | 113 | $use = @$key[JSONWebKeyParameters::PublicKeyUse]; |
114 | 114 | $alg = @$key[JSONWebKeyParameters::Algorithm]; |
115 | - if(empty($alg)) $alg = JSONWebSignatureAndEncryptionAlgorithms::RS256; |
|
115 | + if (empty($alg)) $alg = JSONWebSignatureAndEncryptionAlgorithms::RS256; |
|
116 | 116 | |
117 | - if(empty($kty) || empty($kid) || empty($use)) continue; |
|
117 | + if (empty($kty) || empty($kid) || empty($use)) continue; |
|
118 | 118 | |
119 | - if(!in_array($kty, JSONWebKeyTypes::$supported_keys)) continue; |
|
119 | + if (!in_array($kty, JSONWebKeyTypes::$supported_keys)) continue; |
|
120 | 120 | |
121 | 121 | $n = @$key[RSAKeysParameters::Modulus]; |
122 | 122 | $e = @$key[RSAKeysParameters::Exponent]; |
123 | 123 | $x5c = @$key[PublicJSONWebKeyParameters::X_509CertificateChain]; |
124 | - if(is_null($x5c)) $x5c = array(); |
|
124 | + if (is_null($x5c)) $x5c = array(); |
|
125 | 125 | $x5u = @$key[PublicJSONWebKeyParameters::X_509Url]; |
126 | 126 | $x5t = @$key[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint]; |
127 | 127 | $x5t_S256 = @$key[PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint]; |
@@ -56,8 +56,9 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function getKeys() |
58 | 58 | { |
59 | - if(isset($this->set[JWKSetParameters::Keys])) |
|
60 | - return $this->set[JWKSetParameters::Keys]->getValue(); |
|
59 | + if(isset($this->set[JWKSetParameters::Keys])) { |
|
60 | + return $this->set[JWKSetParameters::Keys]->getValue(); |
|
61 | + } |
|
61 | 62 | return array(); |
62 | 63 | } |
63 | 64 | |
@@ -70,14 +71,17 @@ discard block |
||
70 | 71 | { |
71 | 72 | $id = $key->getId(); |
72 | 73 | |
73 | - if(empty($id)) |
|
74 | - throw new JWKInvalidIdentifierException('key id is empty!'); |
|
74 | + if(empty($id)) { |
|
75 | + throw new JWKInvalidIdentifierException('key id is empty!'); |
|
76 | + } |
|
75 | 77 | |
76 | - if(array_key_exists($id->getValue(), $this->keys_ids)) |
|
77 | - throw new JWKInvalidIdentifierException(sprintf('id %s already exists!'), $key->getId()->getValue()); |
|
78 | + if(array_key_exists($id->getValue(), $this->keys_ids)) { |
|
79 | + throw new JWKInvalidIdentifierException(sprintf('id %s already exists!'), $key->getId()->getValue()); |
|
80 | + } |
|
78 | 81 | |
79 | - if(!isset($this->set[JWKSetParameters::Keys])) |
|
80 | - $this->set[JWKSetParameters::Keys] = new JsonArray(array()); |
|
82 | + if(!isset($this->set[JWKSetParameters::Keys])) { |
|
83 | + $this->set[JWKSetParameters::Keys] = new JsonArray(array()); |
|
84 | + } |
|
81 | 85 | |
82 | 86 | $keys = $this->set[JWKSetParameters::Keys]; |
83 | 87 | $keys->append($key); |
@@ -91,7 +95,9 @@ discard block |
||
91 | 95 | */ |
92 | 96 | public function getKeyById($kid) |
93 | 97 | { |
94 | - if(!array_key_exists($kid, $this->keys_ids)) return null; |
|
98 | + if(!array_key_exists($kid, $this->keys_ids)) { |
|
99 | + return null; |
|
100 | + } |
|
95 | 101 | return $this->keys_ids[$kid]; |
96 | 102 | } |
97 | 103 | |
@@ -104,7 +110,9 @@ discard block |
||
104 | 110 | static public function fromJson($json){ |
105 | 111 | $json = str_replace( array("\n","\r","\t"), '', trim($json)); |
106 | 112 | $res = json_decode($json, true); |
107 | - if(!isset($res[JWKSetParameters::Keys])) throw new JWKInvalidIdentifierException; |
|
113 | + if(!isset($res[JWKSetParameters::Keys])) { |
|
114 | + throw new JWKInvalidIdentifierException; |
|
115 | + } |
|
108 | 116 | $keys = $res[JWKSetParameters::Keys]; |
109 | 117 | $jwk_set = new JWKSet; |
110 | 118 | foreach($keys as $key){ |
@@ -112,16 +120,24 @@ discard block |
||
112 | 120 | $kid = @$key[JSONWebKeyParameters::KeyId]; |
113 | 121 | $use = @$key[JSONWebKeyParameters::PublicKeyUse]; |
114 | 122 | $alg = @$key[JSONWebKeyParameters::Algorithm]; |
115 | - if(empty($alg)) $alg = JSONWebSignatureAndEncryptionAlgorithms::RS256; |
|
123 | + if(empty($alg)) { |
|
124 | + $alg = JSONWebSignatureAndEncryptionAlgorithms::RS256; |
|
125 | + } |
|
116 | 126 | |
117 | - if(empty($kty) || empty($kid) || empty($use)) continue; |
|
127 | + if(empty($kty) || empty($kid) || empty($use)) { |
|
128 | + continue; |
|
129 | + } |
|
118 | 130 | |
119 | - if(!in_array($kty, JSONWebKeyTypes::$supported_keys)) continue; |
|
131 | + if(!in_array($kty, JSONWebKeyTypes::$supported_keys)) { |
|
132 | + continue; |
|
133 | + } |
|
120 | 134 | |
121 | 135 | $n = @$key[RSAKeysParameters::Modulus]; |
122 | 136 | $e = @$key[RSAKeysParameters::Exponent]; |
123 | 137 | $x5c = @$key[PublicJSONWebKeyParameters::X_509CertificateChain]; |
124 | - if(is_null($x5c)) $x5c = array(); |
|
138 | + if(is_null($x5c)) { |
|
139 | + $x5c = array(); |
|
140 | + } |
|
125 | 141 | $x5u = @$key[PublicJSONWebKeyParameters::X_509Url]; |
126 | 142 | $x5t = @$key[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint]; |
127 | 143 | $x5t_S256 = @$key[PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint]; |
@@ -41,30 +41,26 @@ discard block |
||
41 | 41 | static public function build(IJWKSpecification $spec) |
42 | 42 | { |
43 | 43 | |
44 | - if(is_null($spec)) throw new \InvalidArgumentException('missing spec param'); |
|
44 | + if (is_null($spec)) throw new \InvalidArgumentException('missing spec param'); |
|
45 | 45 | |
46 | 46 | $algorithm = DigitalSignatures_MACs_Registry::getInstance()->get($spec->getAlg()); |
47 | 47 | |
48 | - if(is_null($algorithm)) |
|
48 | + if (is_null($algorithm)) |
|
49 | 49 | { |
50 | 50 | $algorithm = KeyManagementAlgorithms_Registry::getInstance()->get($spec->getAlg()); |
51 | 51 | } |
52 | 52 | |
53 | - if(is_null($algorithm)) |
|
54 | - throw new InvalidJWKAlgorithm |
|
55 | - ( |
|
56 | - sprintf |
|
57 | - ( |
|
53 | + if (is_null($algorithm)) |
|
54 | + throw new InvalidJWKAlgorithm( |
|
55 | + sprintf( |
|
58 | 56 | 'alg %s not supported!', |
59 | 57 | $spec->getAlg() |
60 | 58 | ) |
61 | 59 | ); |
62 | 60 | |
63 | - if($algorithm->getKeyType() !== JSONWebKeyTypes::RSA) |
|
64 | - throw new InvalidJWKAlgorithm |
|
65 | - ( |
|
66 | - sprintf |
|
67 | - ( |
|
61 | + if ($algorithm->getKeyType() !== JSONWebKeyTypes::RSA) |
|
62 | + throw new InvalidJWKAlgorithm( |
|
63 | + sprintf( |
|
68 | 64 | 'key type %s not supported!', |
69 | 65 | $algorithm->getKeyType() |
70 | 66 | ) |
@@ -79,11 +75,10 @@ discard block |
||
79 | 75 | $jwk->setKeyUse($spec->getUse()); |
80 | 76 | return $jwk; |
81 | 77 | } |
82 | - if($spec instanceof RSAJWKParamsPublicKeySpecification) |
|
78 | + if ($spec instanceof RSAJWKParamsPublicKeySpecification) |
|
83 | 79 | { |
84 | 80 | |
85 | - $public_key = RSAFacade::getInstance()->buildPublicKey |
|
86 | - ( |
|
81 | + $public_key = RSAFacade::getInstance()->buildPublicKey( |
|
87 | 82 | $spec->getModulus()->toBigInt(), |
88 | 83 | $spec->getExponent()->toBigInt() |
89 | 84 | ); |
@@ -96,7 +91,7 @@ discard block |
||
96 | 91 | |
97 | 92 | return $jwk; |
98 | 93 | } |
99 | - if($spec instanceof RSAJWKPEMPublicKeySpecification) |
|
94 | + if ($spec instanceof RSAJWKPEMPublicKeySpecification) |
|
100 | 95 | { |
101 | 96 | $public_key = RSAFacade::getInstance()->buildPublicKeyFromPEM($spec->getPEM()); |
102 | 97 | $jwk = RSAJWK::fromPublicKey($public_key); |
@@ -41,7 +41,9 @@ discard block |
||
41 | 41 | static public function build(IJWKSpecification $spec) |
42 | 42 | { |
43 | 43 | |
44 | - if(is_null($spec)) throw new \InvalidArgumentException('missing spec param'); |
|
44 | + if(is_null($spec)) { |
|
45 | + throw new \InvalidArgumentException('missing spec param'); |
|
46 | + } |
|
45 | 47 | |
46 | 48 | $algorithm = DigitalSignatures_MACs_Registry::getInstance()->get($spec->getAlg()); |
47 | 49 | |
@@ -50,8 +52,8 @@ discard block |
||
50 | 52 | $algorithm = KeyManagementAlgorithms_Registry::getInstance()->get($spec->getAlg()); |
51 | 53 | } |
52 | 54 | |
53 | - if(is_null($algorithm)) |
|
54 | - throw new InvalidJWKAlgorithm |
|
55 | + if(is_null($algorithm)) { |
|
56 | + throw new InvalidJWKAlgorithm |
|
55 | 57 | ( |
56 | 58 | sprintf |
57 | 59 | ( |
@@ -59,9 +61,10 @@ discard block |
||
59 | 61 | $spec->getAlg() |
60 | 62 | ) |
61 | 63 | ); |
64 | + } |
|
62 | 65 | |
63 | - if($algorithm->getKeyType() !== JSONWebKeyTypes::RSA) |
|
64 | - throw new InvalidJWKAlgorithm |
|
66 | + if($algorithm->getKeyType() !== JSONWebKeyTypes::RSA) { |
|
67 | + throw new InvalidJWKAlgorithm |
|
65 | 68 | ( |
66 | 69 | sprintf |
67 | 70 | ( |
@@ -69,6 +72,7 @@ discard block |
||
69 | 72 | $algorithm->getKeyType() |
70 | 73 | ) |
71 | 74 | ); |
75 | + } |
|
72 | 76 | |
73 | 77 | if ($spec instanceof RSAJWKPEMPrivateKeySpecification) |
74 | 78 | { |
@@ -92,42 +92,42 @@ |
||
92 | 92 | /** |
93 | 93 | * @return Base64urlUInt |
94 | 94 | */ |
95 | - public function getModulus(){ |
|
95 | + public function getModulus() { |
|
96 | 96 | return new Base64urlUInt($this->n_b64); |
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
100 | 100 | * @return Base64urlUInt |
101 | 101 | */ |
102 | - public function getExponent(){ |
|
102 | + public function getExponent() { |
|
103 | 103 | return new Base64urlUInt($this->e_b64); |
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @return array |
108 | 108 | */ |
109 | - public function getX509CertificateChain(){ |
|
109 | + public function getX509CertificateChain() { |
|
110 | 110 | return $this->x5c; |
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
114 | 114 | * @return null|string |
115 | 115 | */ |
116 | - public function getX509Url(){ |
|
116 | + public function getX509Url() { |
|
117 | 117 | return $this->x5u; |
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | 121 | * @return null|string |
122 | 122 | */ |
123 | - public function getX509CertificateSHA_1_Thumbprint(){ |
|
123 | + public function getX509CertificateSHA_1_Thumbprint() { |
|
124 | 124 | return $this->x5t; |
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | 128 | * @return null|string |
129 | 129 | */ |
130 | - public function getX509CertificateSHA_256_Thumbprint(){ |
|
130 | + public function getX509CertificateSHA_256_Thumbprint() { |
|
131 | 131 | return $this->x5t_S256; |
132 | 132 | } |
133 | 133 | } |
134 | 134 | \ No newline at end of file |
@@ -1,16 +1,16 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Copyright 2015 OpenStack Foundation |
|
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | - * you may not use this file except in compliance with the License. |
|
6 | - * You may obtain a copy of the License at |
|
7 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | - * Unless required by applicable law or agreed to in writing, software |
|
9 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | - * See the License for the specific language governing permissions and |
|
12 | - * limitations under the License. |
|
13 | - **/ |
|
3 | + * Copyright 2015 OpenStack Foundation |
|
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | + * you may not use this file except in compliance with the License. |
|
6 | + * You may obtain a copy of the License at |
|
7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | + * Unless required by applicable law or agreed to in writing, software |
|
9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | + * See the License for the specific language governing permissions and |
|
12 | + * limitations under the License. |
|
13 | + **/ |
|
14 | 14 | |
15 | 15 | namespace jwk; |
16 | 16 |
@@ -34,8 +34,7 @@ |
||
34 | 34 | * @param string $alg |
35 | 35 | * @param string $use |
36 | 36 | */ |
37 | - public function __construct |
|
38 | - ( |
|
37 | + public function __construct( |
|
39 | 38 | $key_pem, |
40 | 39 | $alg = JSONWebSignatureAndEncryptionAlgorithms::RS256, |
41 | 40 | $use = JSONWebKeyPublicKeyUseValues::Signature |
@@ -1,16 +1,16 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Copyright 2015 OpenStack Foundation |
|
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | - * you may not use this file except in compliance with the License. |
|
6 | - * You may obtain a copy of the License at |
|
7 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | - * Unless required by applicable law or agreed to in writing, software |
|
9 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | - * See the License for the specific language governing permissions and |
|
12 | - * limitations under the License. |
|
13 | - **/ |
|
3 | + * Copyright 2015 OpenStack Foundation |
|
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | + * you may not use this file except in compliance with the License. |
|
6 | + * You may obtain a copy of the License at |
|
7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | + * Unless required by applicable law or agreed to in writing, software |
|
9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | + * See the License for the specific language governing permissions and |
|
12 | + * limitations under the License. |
|
13 | + **/ |
|
14 | 14 | |
15 | 15 | namespace jwk; |
16 | 16 |
@@ -32,14 +32,13 @@ |
||
32 | 32 | * @param string $kid |
33 | 33 | * @throws InvalidJWKAlgorithm |
34 | 34 | */ |
35 | - public function __construct |
|
36 | - ( |
|
35 | + public function __construct( |
|
37 | 36 | $alg = JSONWebSignatureAndEncryptionAlgorithms::RS256, |
38 | 37 | $use = JSONWebKeyPublicKeyUseValues::Signature, |
39 | 38 | $kid = null |
40 | 39 | ) |
41 | 40 | { |
42 | - if(!empty($alg) && !in_array($alg, RSAKeysParameters::$valid_algorithms_values)) |
|
41 | + if (!empty($alg) && !in_array($alg, RSAKeysParameters::$valid_algorithms_values)) |
|
43 | 42 | throw new InvalidJWKAlgorithm(sprintf('alg %s', $alg)); |
44 | 43 | |
45 | 44 | parent::__construct($alg, $use, $kid); |
@@ -39,8 +39,9 @@ |
||
39 | 39 | $kid = null |
40 | 40 | ) |
41 | 41 | { |
42 | - if(!empty($alg) && !in_array($alg, RSAKeysParameters::$valid_algorithms_values)) |
|
43 | - throw new InvalidJWKAlgorithm(sprintf('alg %s', $alg)); |
|
42 | + if(!empty($alg) && !in_array($alg, RSAKeysParameters::$valid_algorithms_values)) { |
|
43 | + throw new InvalidJWKAlgorithm(sprintf('alg %s', $alg)); |
|
44 | + } |
|
44 | 45 | |
45 | 46 | parent::__construct($alg, $use, $kid); |
46 | 47 | } |
@@ -1,16 +1,16 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Copyright 2015 OpenStack Foundation |
|
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | - * you may not use this file except in compliance with the License. |
|
6 | - * You may obtain a copy of the License at |
|
7 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | - * Unless required by applicable law or agreed to in writing, software |
|
9 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | - * See the License for the specific language governing permissions and |
|
12 | - * limitations under the License. |
|
13 | - **/ |
|
3 | + * Copyright 2015 OpenStack Foundation |
|
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | + * you may not use this file except in compliance with the License. |
|
6 | + * You may obtain a copy of the License at |
|
7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | + * Unless required by applicable law or agreed to in writing, software |
|
9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | + * See the License for the specific language governing permissions and |
|
12 | + * limitations under the License. |
|
13 | + **/ |
|
14 | 14 | |
15 | 15 | namespace jwk; |
16 | 16 |
@@ -38,14 +38,13 @@ |
||
38 | 38 | * @param string $use |
39 | 39 | * @throws InvalidJWKAlgorithm |
40 | 40 | */ |
41 | - public function __construct |
|
42 | - ( |
|
41 | + public function __construct( |
|
43 | 42 | $shared_secret = self::GenerateSecret, |
44 | 43 | $alg = JSONWebSignatureAndEncryptionAlgorithms::HS256, |
45 | 44 | $use = JSONWebKeyPublicKeyUseValues::Signature |
46 | 45 | ) |
47 | 46 | { |
48 | - if(!in_array($alg, OctetSequenceKeysParameters::$valid_algorithms_values)) |
|
47 | + if (!in_array($alg, OctetSequenceKeysParameters::$valid_algorithms_values)) |
|
49 | 48 | throw new InvalidJWKAlgorithm(sprintf('alg %s', $alg)); |
50 | 49 | |
51 | 50 | parent::__construct($alg, $use); |
@@ -45,8 +45,9 @@ |
||
45 | 45 | $use = JSONWebKeyPublicKeyUseValues::Signature |
46 | 46 | ) |
47 | 47 | { |
48 | - if(!in_array($alg, OctetSequenceKeysParameters::$valid_algorithms_values)) |
|
49 | - throw new InvalidJWKAlgorithm(sprintf('alg %s', $alg)); |
|
48 | + if(!in_array($alg, OctetSequenceKeysParameters::$valid_algorithms_values)) { |
|
49 | + throw new InvalidJWKAlgorithm(sprintf('alg %s', $alg)); |
|
50 | + } |
|
50 | 51 | |
51 | 52 | parent::__construct($alg, $use); |
52 | 53 |
@@ -63,33 +63,33 @@ discard block |
||
63 | 63 | { |
64 | 64 | parent::__construct($headers); |
65 | 65 | |
66 | - if(count($headers) === 0 ) return; |
|
66 | + if (count($headers) === 0) return; |
|
67 | 67 | |
68 | 68 | // certificates |
69 | - if(in_array(PublicJSONWebKeyParameters::X_509CertificateChain, $headers) && is_array($headers[PublicJSONWebKeyParameters::X_509CertificateChain])){ |
|
69 | + if (in_array(PublicJSONWebKeyParameters::X_509CertificateChain, $headers) && is_array($headers[PublicJSONWebKeyParameters::X_509CertificateChain])) { |
|
70 | 70 | |
71 | 71 | // json array |
72 | - foreach($headers[PublicJSONWebKeyParameters::X_509CertificateChain] as $x509_pem){ |
|
72 | + foreach ($headers[PublicJSONWebKeyParameters::X_509CertificateChain] as $x509_pem) { |
|
73 | 73 | array_push($this->x509_certificates_chain, X509CertificateFactory::buildFromPEM($x509_pem)); |
74 | 74 | |
75 | 75 | } |
76 | 76 | |
77 | - if($this->checkX509CertMismatch()){ |
|
77 | + if ($this->checkX509CertMismatch()) { |
|
78 | 78 | throw new X509CertMismatchException; |
79 | 79 | } |
80 | 80 | |
81 | 81 | $this->set[PublicJSONWebKeyParameters::X_509CertificateChain] = new JsonArray($headers[PublicJSONWebKeyParameters::X_509CertificateChain]); |
82 | 82 | } |
83 | 83 | |
84 | - if(in_array(PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint, $headers)){ |
|
85 | - $this->set[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint] = new StringOrURI($headers[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint]) ; |
|
84 | + if (in_array(PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint, $headers)) { |
|
85 | + $this->set[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint] = new StringOrURI($headers[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint]); |
|
86 | 86 | } |
87 | 87 | |
88 | - if(in_array(PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint, $headers)){ |
|
88 | + if (in_array(PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint, $headers)) { |
|
89 | 89 | $this->set[PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint] = new StringOrURI($headers[PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint]); |
90 | 90 | } |
91 | 91 | |
92 | - if(in_array(PublicJSONWebKeyParameters::X_509Url, $headers)){ |
|
92 | + if (in_array(PublicJSONWebKeyParameters::X_509Url, $headers)) { |
|
93 | 93 | $this->set[PublicJSONWebKeyParameters::X_509Url] = new StringOrURI($headers[PublicJSONWebKeyParameters::X_509Url]); |
94 | 94 | } |
95 | 95 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function setVisibility($visibility) |
111 | 111 | { |
112 | - if(!in_array($visibility, JSONWebKeyVisibility::$valid_values)) |
|
112 | + if (!in_array($visibility, JSONWebKeyVisibility::$valid_values)) |
|
113 | 113 | throw new InvalidJWKVisibilityException; |
114 | 114 | $this->visibility = $visibility; |
115 | 115 | return $this; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | /** |
135 | 135 | * @return null | X509Certificate |
136 | 136 | */ |
137 | - public function getX509LeafCertificate(){ |
|
137 | + public function getX509LeafCertificate() { |
|
138 | 138 | return count($this->x509_certificates_chain) > 0 ? $this->x509_certificates_chain[0] : null; |
139 | 139 | } |
140 | 140 | |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function getX509CertificateSha1Thumbprint($fallback_on_x5c = false) |
155 | 155 | { |
156 | - $res = is_null($this[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint])? null : $this[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint]->getString(); |
|
157 | - if(empty($res) && $fallback_on_x5c){ |
|
156 | + $res = is_null($this[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint]) ? null : $this[PublicJSONWebKeyParameters::X_509CertificateSHA_1_Thumbprint]->getString(); |
|
157 | + if (empty($res) && $fallback_on_x5c) { |
|
158 | 158 | $x509 = $this->getX509LeafCertificate(); |
159 | - if(!is_null($x509)){ |
|
159 | + if (!is_null($x509)) { |
|
160 | 160 | return $x509->getSHA_1_Thumbprint(); |
161 | 161 | } |
162 | 162 | } |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function getX509CertificateSha256Thumbprint($fallback_on_x5c = false) |
171 | 171 | { |
172 | - $res = is_null($this[PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint])? null : $this[PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint]->getString(); |
|
173 | - if(empty($res) && $fallback_on_x5c){ |
|
172 | + $res = is_null($this[PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint]) ? null : $this[PublicJSONWebKeyParameters::X_509CertificateSHA_256_Thumbprint]->getString(); |
|
173 | + if (empty($res) && $fallback_on_x5c) { |
|
174 | 174 | $x509 = $this->getX509LeafCertificate(); |
175 | - if(!is_null($x509)){ |
|
175 | + if (!is_null($x509)) { |
|
176 | 176 | return $x509->getSHA_256_Thumbprint(); |
177 | 177 | } |
178 | 178 | } |
@@ -184,13 +184,13 @@ discard block |
||
184 | 184 | */ |
185 | 185 | public function getX509Url() |
186 | 186 | { |
187 | - return is_null($this[PublicJSONWebKeyParameters::X_509Url])? null : $this[PublicJSONWebKeyParameters::X_509Url]->getString(); |
|
187 | + return is_null($this[PublicJSONWebKeyParameters::X_509Url]) ? null : $this[PublicJSONWebKeyParameters::X_509Url]->getString(); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | 191 | * @return bool |
192 | 192 | */ |
193 | - protected function checkX509CertMismatch(){ |
|
193 | + protected function checkX509CertMismatch() { |
|
194 | 194 | $x509 = $this->getX509LeafCertificate(); |
195 | 195 | return !is_null($x509) && $x509->getPublicKey() !== $this->public_key->getEncoded(); |
196 | 196 | } |
@@ -200,13 +200,13 @@ discard block |
||
200 | 200 | * @return $this |
201 | 201 | * @throws X509CertMismatchException |
202 | 202 | */ |
203 | - public function setX509CertificateChain(array $x5c){ |
|
203 | + public function setX509CertificateChain(array $x5c) { |
|
204 | 204 | // json array |
205 | - foreach($x5c as $x509_pem){ |
|
205 | + foreach ($x5c as $x509_pem) { |
|
206 | 206 | array_push($this->x509_certificates_chain, X509CertificateFactory::buildFromPEM($x509_pem)); |
207 | 207 | } |
208 | 208 | |
209 | - if($this->checkX509CertMismatch()){ |
|
209 | + if ($this->checkX509CertMismatch()) { |
|
210 | 210 | throw new X509CertMismatchException; |
211 | 211 | } |
212 | 212 |
@@ -63,7 +63,9 @@ discard block |
||
63 | 63 | { |
64 | 64 | parent::__construct($headers); |
65 | 65 | |
66 | - if(count($headers) === 0 ) return; |
|
66 | + if(count($headers) === 0 ) { |
|
67 | + return; |
|
68 | + } |
|
67 | 69 | |
68 | 70 | // certificates |
69 | 71 | if(in_array(PublicJSONWebKeyParameters::X_509CertificateChain, $headers) && is_array($headers[PublicJSONWebKeyParameters::X_509CertificateChain])){ |
@@ -109,8 +111,9 @@ discard block |
||
109 | 111 | */ |
110 | 112 | public function setVisibility($visibility) |
111 | 113 | { |
112 | - if(!in_array($visibility, JSONWebKeyVisibility::$valid_values)) |
|
113 | - throw new InvalidJWKVisibilityException; |
|
114 | + if(!in_array($visibility, JSONWebKeyVisibility::$valid_values)) { |
|
115 | + throw new InvalidJWKVisibilityException; |
|
116 | + } |
|
114 | 117 | $this->visibility = $visibility; |
115 | 118 | return $this; |
116 | 119 | } |
@@ -1,16 +1,16 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Copyright 2015 OpenStack Foundation |
|
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | - * you may not use this file except in compliance with the License. |
|
6 | - * You may obtain a copy of the License at |
|
7 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | - * Unless required by applicable law or agreed to in writing, software |
|
9 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | - * See the License for the specific language governing permissions and |
|
12 | - * limitations under the License. |
|
13 | - **/ |
|
3 | + * Copyright 2015 OpenStack Foundation |
|
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | + * you may not use this file except in compliance with the License. |
|
6 | + * You may obtain a copy of the License at |
|
7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | + * Unless required by applicable law or agreed to in writing, software |
|
9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | + * See the License for the specific language governing permissions and |
|
12 | + * limitations under the License. |
|
13 | + **/ |
|
14 | 14 | |
15 | 15 | namespace jwk\impl; |
16 | 16 | |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
98 | - * @return int |
|
99 | - */ |
|
98 | + * @return int |
|
99 | + */ |
|
100 | 100 | public function getVisibility() |
101 | 101 | { |
102 | 102 | return $this->visibility; |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | * @throws InvalidJWKType |
41 | 41 | * @throws InvalidJWKUseException |
42 | 42 | */ |
43 | - protected function __construct(array $headers = array()){ |
|
43 | + protected function __construct(array $headers = array()) { |
|
44 | 44 | |
45 | - if(count($headers) === 0 ) return; |
|
45 | + if (count($headers) === 0) return; |
|
46 | 46 | |
47 | 47 | $alg = @$headers[JSONWebKeyParameters::Algorithm]; |
48 | 48 | $this->setAlgorithm($alg); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function setId($kid) |
86 | 86 | { |
87 | - if(!empty($kid)) |
|
87 | + if (!empty($kid)) |
|
88 | 88 | $this->set[JSONWebKeyParameters::KeyId] = new JsonValue($kid); |
89 | 89 | return $this; |
90 | 90 | } |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function setAlgorithm($alg) |
98 | 98 | { |
99 | - if(!in_array($alg, JSONWebSignatureAndEncryptionAlgorithms::$header_location_alg)) |
|
100 | - throw new InvalidJWKAlgorithm (sprintf('alg %s', $alg)); |
|
99 | + if (!in_array($alg, JSONWebSignatureAndEncryptionAlgorithms::$header_location_alg)) |
|
100 | + throw new InvalidJWKAlgorithm(sprintf('alg %s', $alg)); |
|
101 | 101 | |
102 | 102 | $this->set[JSONWebKeyParameters::Algorithm] = new StringOrURI($alg); |
103 | 103 | return $this; |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function setKeyUse($use) |
112 | 112 | { |
113 | - if(empty($use)) return $this; |
|
114 | - if(!in_array($use, JSONWebKeyPublicKeyUseValues::$valid_uses)) |
|
113 | + if (empty($use)) return $this; |
|
114 | + if (!in_array($use, JSONWebKeyPublicKeyUseValues::$valid_uses)) |
|
115 | 115 | throw new InvalidJWKUseException(sprintf('use %s', $use)); |
116 | 116 | |
117 | 117 | $this->set[JSONWebKeyParameters::PublicKeyUse] = new StringOrURI($use); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function setType($type) |
127 | 127 | { |
128 | - if(!in_array($type, JSONWebKeyTypes::$valid_keys_set)) |
|
128 | + if (!in_array($type, JSONWebKeyTypes::$valid_keys_set)) |
|
129 | 129 | throw new InvalidJWKType(sprintf('use %s', $type)); |
130 | 130 | |
131 | 131 | $this->set[JSONWebKeyParameters::KeyType] = new StringOrURI($type); |
@@ -42,7 +42,9 @@ discard block |
||
42 | 42 | */ |
43 | 43 | protected function __construct(array $headers = array()){ |
44 | 44 | |
45 | - if(count($headers) === 0 ) return; |
|
45 | + if(count($headers) === 0 ) { |
|
46 | + return; |
|
47 | + } |
|
46 | 48 | |
47 | 49 | $alg = @$headers[JSONWebKeyParameters::Algorithm]; |
48 | 50 | $this->setAlgorithm($alg); |
@@ -84,8 +86,9 @@ discard block |
||
84 | 86 | */ |
85 | 87 | public function setId($kid) |
86 | 88 | { |
87 | - if(!empty($kid)) |
|
88 | - $this->set[JSONWebKeyParameters::KeyId] = new JsonValue($kid); |
|
89 | + if(!empty($kid)) { |
|
90 | + $this->set[JSONWebKeyParameters::KeyId] = new JsonValue($kid); |
|
91 | + } |
|
89 | 92 | return $this; |
90 | 93 | } |
91 | 94 | |
@@ -96,8 +99,9 @@ discard block |
||
96 | 99 | */ |
97 | 100 | public function setAlgorithm($alg) |
98 | 101 | { |
99 | - if(!in_array($alg, JSONWebSignatureAndEncryptionAlgorithms::$header_location_alg)) |
|
100 | - throw new InvalidJWKAlgorithm (sprintf('alg %s', $alg)); |
|
102 | + if(!in_array($alg, JSONWebSignatureAndEncryptionAlgorithms::$header_location_alg)) { |
|
103 | + throw new InvalidJWKAlgorithm (sprintf('alg %s', $alg)); |
|
104 | + } |
|
101 | 105 | |
102 | 106 | $this->set[JSONWebKeyParameters::Algorithm] = new StringOrURI($alg); |
103 | 107 | return $this; |
@@ -110,9 +114,12 @@ discard block |
||
110 | 114 | */ |
111 | 115 | public function setKeyUse($use) |
112 | 116 | { |
113 | - if(empty($use)) return $this; |
|
114 | - if(!in_array($use, JSONWebKeyPublicKeyUseValues::$valid_uses)) |
|
115 | - throw new InvalidJWKUseException(sprintf('use %s', $use)); |
|
117 | + if(empty($use)) { |
|
118 | + return $this; |
|
119 | + } |
|
120 | + if(!in_array($use, JSONWebKeyPublicKeyUseValues::$valid_uses)) { |
|
121 | + throw new InvalidJWKUseException(sprintf('use %s', $use)); |
|
122 | + } |
|
116 | 123 | |
117 | 124 | $this->set[JSONWebKeyParameters::PublicKeyUse] = new StringOrURI($use); |
118 | 125 | return $this; |
@@ -125,8 +132,9 @@ discard block |
||
125 | 132 | */ |
126 | 133 | public function setType($type) |
127 | 134 | { |
128 | - if(!in_array($type, JSONWebKeyTypes::$valid_keys_set)) |
|
129 | - throw new InvalidJWKType(sprintf('use %s', $type)); |
|
135 | + if(!in_array($type, JSONWebKeyTypes::$valid_keys_set)) { |
|
136 | + throw new InvalidJWKType(sprintf('use %s', $type)); |
|
137 | + } |
|
130 | 138 | |
131 | 139 | $this->set[JSONWebKeyParameters::KeyType] = new StringOrURI($type); |
132 | 140 | return $this; |
@@ -1,16 +1,16 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Copyright 2015 OpenStack Foundation |
|
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | - * you may not use this file except in compliance with the License. |
|
6 | - * You may obtain a copy of the License at |
|
7 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | - * Unless required by applicable law or agreed to in writing, software |
|
9 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | - * See the License for the specific language governing permissions and |
|
12 | - * limitations under the License. |
|
13 | - **/ |
|
3 | + * Copyright 2015 OpenStack Foundation |
|
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | + * you may not use this file except in compliance with the License. |
|
6 | + * You may obtain a copy of the License at |
|
7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | + * Unless required by applicable law or agreed to in writing, software |
|
9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11 | + * See the License for the specific language governing permissions and |
|
12 | + * limitations under the License. |
|
13 | + **/ |
|
14 | 14 | |
15 | 15 | namespace jwk; |
16 | 16 |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * |
25 | 25 | */ |
26 | - const PublicOnly = 1; |
|
26 | + const PublicOnly = 1; |
|
27 | 27 | /** |
28 | 28 | * |
29 | 29 | */ |
30 | - const IncludePrivate = 2; |
|
30 | + const IncludePrivate = 2; |
|
31 | 31 | /** |
32 | 32 | * |
33 | 33 | */ |
@@ -36,5 +36,5 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * @var array |
38 | 38 | */ |
39 | - static public $valid_values = array ( self::IncludePrivate, self::IncludeSymmetric, self::PublicOnly); |
|
39 | + static public $valid_values = array(self::IncludePrivate, self::IncludeSymmetric, self::PublicOnly); |
|
40 | 40 | } |
41 | 41 | \ No newline at end of file |