@@ -32,7 +32,7 @@ |
||
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * @param Key $management_key |
| 35 | - * @param $key_management_mode |
|
| 35 | + * @param string $key_management_mode |
|
| 36 | 36 | * @param ContentEncryptionAlgorithm $enc |
| 37 | 37 | * @return Key |
| 38 | 38 | * @throws \Exception |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * The CEK MUST have a length equal to that required for the |
| 58 | 58 | * content encryption algorithm. |
| 59 | 59 | */ |
| 60 | - $rnd = $generator->invoke($enc->getMinKeyLen()/8); |
|
| 60 | + $rnd = $generator->invoke($enc->getMinKeyLen() / 8); |
|
| 61 | 61 | $cek = new _ContentEncryptionKey($enc->getName(), 'RAW', $rnd); |
| 62 | 62 | } |
| 63 | 63 | break; |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @param EncryptionAlgorithm $alg |
| 86 | 86 | * @return Key |
| 87 | 87 | */ |
| 88 | - static public function fromRaw($value, EncryptionAlgorithm $alg){ |
|
| 88 | + static public function fromRaw($value, EncryptionAlgorithm $alg) { |
|
| 89 | 89 | return new _ContentEncryptionKey($alg->getName(), 'RAW', $value); |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | \ 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 | |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | final class IVFactory { |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | - * @param $size |
|
| 26 | + * @param integer $size |
|
| 27 | 27 | * @return string |
| 28 | 28 | */ |
| 29 | 29 | static public function build($size){ |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | * @param $size |
| 27 | 27 | * @return string |
| 28 | 28 | */ |
| 29 | - static public function build($size){ |
|
| 29 | + static public function build($size) { |
|
| 30 | 30 | |
| 31 | 31 | $generator = Utils_Registry::getInstance()->get(Utils_Registry::RandomNumberGeneratorService); |
| 32 | 32 | return $generator->invoke($size / 8); |
@@ -144,7 +144,7 @@ |
||
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | 146 | * @param PrivateKey $private_key |
| 147 | - * @return IAsymmetricJWK|null |
|
| 147 | + * @return RSAJWK |
|
| 148 | 148 | * @throws InvalidJWKType |
| 149 | 149 | */ |
| 150 | 150 | static public function fromPrivateKey(PrivateKey $private_key) |
@@ -112,10 +112,10 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | static public function fromKeys(KeyPair $keys) |
| 114 | 114 | { |
| 115 | - if(!($keys->getPrivate() instanceof RSAPrivateKey)) |
|
| 115 | + if (!($keys->getPrivate() instanceof RSAPrivateKey)) |
|
| 116 | 116 | throw new \RuntimeException('Private key of invalid type!'); |
| 117 | 117 | |
| 118 | - if(!($keys->getPublic() instanceof RSAPublicKey)) |
|
| 118 | + if (!($keys->getPublic() instanceof RSAPublicKey)) |
|
| 119 | 119 | throw new \RuntimeException('Public key of invalid type!'); |
| 120 | 120 | |
| 121 | 121 | $jwk = new RSAJWK(); |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | public function getKey($key_op = JSONWebKeyKeyOperationsValues::ComputeDigitalSignatureOrMAC) |
| 167 | 167 | { |
| 168 | - switch($key_op){ |
|
| 168 | + switch ($key_op) { |
|
| 169 | 169 | case JSONWebKeyKeyOperationsValues::ComputeDigitalSignatureOrMAC: |
| 170 | 170 | case JSONWebKeyKeyOperationsValues::DecryptContentAndValidateDecryption: { |
| 171 | 171 | return $this->getPrivateKey(); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | } |
| 178 | 178 | break; |
| 179 | 179 | default:{ |
| 180 | - throw new InvalidJWKUseException(sprintf('key_op %s', $key_op)); |
|
| 180 | + throw new InvalidJWKUseException(sprintf('key_op %s', $key_op)); |
|
| 181 | 181 | } |
| 182 | 182 | break; |
| 183 | 183 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | public function toArray() |
| 191 | 191 | { |
| 192 | 192 | $res = parent::toArray(); |
| 193 | - if($this->visibility === JSONWebKeyVisibility::PublicOnly){ |
|
| 193 | + if ($this->visibility === JSONWebKeyVisibility::PublicOnly) { |
|
| 194 | 194 | //remove private attributes |
| 195 | 195 | unset($res[RSAKeysParameters::PrivateExponent]); |
| 196 | 196 | unset($res[RSAKeysParameters::FirstPrimeFactor]); |
@@ -53,11 +53,14 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | parent::__construct($headers); |
| 55 | 55 | |
| 56 | - if (count($headers) === 0) return; |
|
| 56 | + if (count($headers) === 0) { |
|
| 57 | + return; |
|
| 58 | + } |
|
| 57 | 59 | |
| 58 | 60 | foreach (RSAKeysParameters::$public_key_params as $p) { |
| 59 | - if (!array_key_exists($p, $headers)) |
|
| 60 | - throw new RSAJWKMissingPublicKeyParamException(); |
|
| 61 | + if (!array_key_exists($p, $headers)) { |
|
| 62 | + throw new RSAJWKMissingPublicKeyParamException(); |
|
| 63 | + } |
|
| 61 | 64 | $this->set[$p] = new Base64urlUInt($headers[$p]); |
| 62 | 65 | } |
| 63 | 66 | |
@@ -74,8 +77,9 @@ discard block |
||
| 74 | 77 | //its has one private param, must have all ... |
| 75 | 78 | if (in_array(RSAKeysParameters::FirstPrimeFactor, $headers)) { |
| 76 | 79 | foreach (RSAKeysParameters::$producers_private_key_params as $p) { |
| 77 | - if (!array_key_exists($p, $headers)) |
|
| 78 | - throw new RSAJWKMissingPrivateKeyParamException(); |
|
| 80 | + if (!array_key_exists($p, $headers)) { |
|
| 81 | + throw new RSAJWKMissingPrivateKeyParamException(); |
|
| 82 | + } |
|
| 79 | 83 | $this->set[$p] = new Base64urlUInt($headers[$p]); |
| 80 | 84 | } |
| 81 | 85 | $this->private_key = RSAFacade::getInstance()->buildPrivateKey( |
@@ -112,11 +116,13 @@ discard block |
||
| 112 | 116 | */ |
| 113 | 117 | static public function fromKeys(KeyPair $keys) |
| 114 | 118 | { |
| 115 | - if(!($keys->getPrivate() instanceof RSAPrivateKey)) |
|
| 116 | - throw new \RuntimeException('Private key of invalid type!'); |
|
| 119 | + if(!($keys->getPrivate() instanceof RSAPrivateKey)) { |
|
| 120 | + throw new \RuntimeException('Private key of invalid type!'); |
|
| 121 | + } |
|
| 117 | 122 | |
| 118 | - if(!($keys->getPublic() instanceof RSAPublicKey)) |
|
| 119 | - throw new \RuntimeException('Public key of invalid type!'); |
|
| 123 | + if(!($keys->getPublic() instanceof RSAPublicKey)) { |
|
| 124 | + throw new \RuntimeException('Public key of invalid type!'); |
|
| 125 | + } |
|
| 120 | 126 | |
| 121 | 127 | $jwk = new RSAJWK(); |
| 122 | 128 | $jwk->public_key = $keys->getPublic(); |
@@ -134,7 +140,9 @@ discard block |
||
| 134 | 140 | */ |
| 135 | 141 | static public function fromPublicKey(PublicKey $public_key) |
| 136 | 142 | { |
| 137 | - if (!($public_key instanceof RSAPublicKey)) throw new InvalidJWKType(); |
|
| 143 | + if (!($public_key instanceof RSAPublicKey)) { |
|
| 144 | + throw new InvalidJWKType(); |
|
| 145 | + } |
|
| 138 | 146 | $jwk = new RSAJWK(); |
| 139 | 147 | $jwk->public_key = $public_key; |
| 140 | 148 | $jwk->set[RSAKeysParameters::Exponent] = Base64urlUInt::fromBigInt($public_key->getPublicExponent()); |
@@ -149,7 +157,9 @@ discard block |
||
| 149 | 157 | */ |
| 150 | 158 | static public function fromPrivateKey(PrivateKey $private_key) |
| 151 | 159 | { |
| 152 | - if (!($private_key instanceof RSAPrivateKey)) throw new InvalidJWKType(); |
|
| 160 | + if (!($private_key instanceof RSAPrivateKey)) { |
|
| 161 | + throw new InvalidJWKType(); |
|
| 162 | + } |
|
| 153 | 163 | $jwk = new RSAJWK(); |
| 154 | 164 | $jwk->private_key = $private_key; |
| 155 | 165 | $jwk->set[RSAKeysParameters::Exponent] = Base64urlUInt::fromBigInt($private_key->getPublicExponent()); |
@@ -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 | |
@@ -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 |
@@ -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 | |
@@ -64,7 +64,9 @@ |
||
| 64 | 64 | * @return null|CompressionAlgorithm |
| 65 | 65 | */ |
| 66 | 66 | public function get($alg){ |
| 67 | - if(!$this->isSupported($alg)) return null; |
|
| 67 | + if(!$this->isSupported($alg)) { |
|
| 68 | + return null; |
|
| 69 | + } |
|
| 68 | 70 | return $this->algorithms[$alg]; |
| 69 | 71 | } |
| 70 | 72 | } |
| 71 | 73 | \ 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 | } |
@@ -37,8 +37,9 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 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 | 44 | return hash_hmac($this->getHashingAlgorithm(), $message, $key->getSecret(), true); |
| 44 | 45 | } |
@@ -52,7 +53,9 @@ discard block |
||
| 52 | 53 | * @throws InvalidKeyTypeAlgorithmException |
| 53 | 54 | */ |
| 54 | 55 | public function verify(Key $key, $message, $digest){ |
| 55 | - if(!($key instanceof SharedKey)) throw new InvalidKeyTypeAlgorithmException; |
|
| 56 | + if(!($key instanceof SharedKey)) { |
|
| 57 | + throw new InvalidKeyTypeAlgorithmException; |
|
| 58 | + } |
|
| 56 | 59 | |
| 57 | 60 | return $digest === $this->digest($key, $message); |
| 58 | 61 | } |
@@ -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 | |
@@ -68,7 +68,9 @@ |
||
| 68 | 68 | * @return null|ContentEncryptionAlgorithm |
| 69 | 69 | */ |
| 70 | 70 | public function get($alg) { |
| 71 | - if (!$this->isSupported($alg)) return null; |
|
| 71 | + if (!$this->isSupported($alg)) { |
|
| 72 | + return null; |
|
| 73 | + } |
|
| 72 | 74 | return $this->algorithms[$alg]; |
| 73 | 75 | } |
| 74 | 76 | } |
| 75 | 77 | \ 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 | |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function sign(PrivateKey $private_key, $message) |
| 47 | 47 | { |
| 48 | - if(!($private_key instanceof RSAPrivateKey)) throw new InvalidKeyTypeAlgorithmException; |
|
| 48 | + if (!($private_key instanceof RSAPrivateKey)) throw new InvalidKeyTypeAlgorithmException; |
|
| 49 | 49 | |
| 50 | - if($this->getMinKeyLen() > $private_key->getBitLength()) |
|
| 51 | - throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.',$this->getMinKeyLen(), $private_key->getBitLength())); |
|
| 50 | + if ($this->getMinKeyLen() > $private_key->getBitLength()) |
|
| 51 | + throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.', $this->getMinKeyLen(), $private_key->getBitLength())); |
|
| 52 | 52 | |
| 53 | 53 | $res = $this->rsa_impl->loadKey($private_key->getEncoded()); |
| 54 | 54 | |
| 55 | - if(!$res) throw new InvalidKeyTypeAlgorithmException; |
|
| 55 | + if (!$res) throw new InvalidKeyTypeAlgorithmException; |
|
| 56 | 56 | |
| 57 | 57 | $this->rsa_impl->setHash($this->getHashingAlgorithm()); |
| 58 | 58 | $this->rsa_impl->setMGFHash($this->getHashingAlgorithm()); |
@@ -70,14 +70,14 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | public function verify(Key $key, $message, $signature) |
| 72 | 72 | { |
| 73 | - if(!($key instanceof RSAPublicKey)) throw new InvalidKeyTypeAlgorithmException; |
|
| 73 | + if (!($key instanceof RSAPublicKey)) throw new InvalidKeyTypeAlgorithmException; |
|
| 74 | 74 | |
| 75 | - if($this->getMinKeyLen() > $key->getBitLength()) |
|
| 76 | - throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.',$this->getMinKeyLen(), $key->getBitLength())); |
|
| 75 | + if ($this->getMinKeyLen() > $key->getBitLength()) |
|
| 76 | + throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.', $this->getMinKeyLen(), $key->getBitLength())); |
|
| 77 | 77 | |
| 78 | 78 | $res = $this->rsa_impl->loadKey($key->getEncoded()); |
| 79 | 79 | |
| 80 | - if(!$res) throw new InvalidKeyTypeAlgorithmException; |
|
| 80 | + if (!$res) throw new InvalidKeyTypeAlgorithmException; |
|
| 81 | 81 | |
| 82 | 82 | $this->rsa_impl->setHash($this->getHashingAlgorithm()); |
| 83 | 83 | $this->rsa_impl->setMGFHash($this->getHashingAlgorithm()); |
@@ -45,14 +45,19 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function sign(PrivateKey $private_key, $message) |
| 47 | 47 | { |
| 48 | - if(!($private_key instanceof RSAPrivateKey)) throw new InvalidKeyTypeAlgorithmException; |
|
| 48 | + if(!($private_key instanceof RSAPrivateKey)) { |
|
| 49 | + throw new InvalidKeyTypeAlgorithmException; |
|
| 50 | + } |
|
| 49 | 51 | |
| 50 | - if($this->getMinKeyLen() > $private_key->getBitLength()) |
|
| 51 | - throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.',$this->getMinKeyLen(), $private_key->getBitLength())); |
|
| 52 | + if($this->getMinKeyLen() > $private_key->getBitLength()) { |
|
| 53 | + throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.',$this->getMinKeyLen(), $private_key->getBitLength())); |
|
| 54 | + } |
|
| 52 | 55 | |
| 53 | 56 | $res = $this->rsa_impl->loadKey($private_key->getEncoded()); |
| 54 | 57 | |
| 55 | - if(!$res) throw new InvalidKeyTypeAlgorithmException; |
|
| 58 | + if(!$res) { |
|
| 59 | + throw new InvalidKeyTypeAlgorithmException; |
|
| 60 | + } |
|
| 56 | 61 | |
| 57 | 62 | $this->rsa_impl->setHash($this->getHashingAlgorithm()); |
| 58 | 63 | $this->rsa_impl->setMGFHash($this->getHashingAlgorithm()); |
@@ -70,14 +75,19 @@ discard block |
||
| 70 | 75 | */ |
| 71 | 76 | public function verify(Key $key, $message, $signature) |
| 72 | 77 | { |
| 73 | - if(!($key instanceof RSAPublicKey)) throw new InvalidKeyTypeAlgorithmException; |
|
| 78 | + if(!($key instanceof RSAPublicKey)) { |
|
| 79 | + throw new InvalidKeyTypeAlgorithmException; |
|
| 80 | + } |
|
| 74 | 81 | |
| 75 | - if($this->getMinKeyLen() > $key->getBitLength()) |
|
| 76 | - throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.',$this->getMinKeyLen(), $key->getBitLength())); |
|
| 82 | + if($this->getMinKeyLen() > $key->getBitLength()) { |
|
| 83 | + throw new InvalidKeyLengthAlgorithmException(sprintf('min len %s - cur len %s.',$this->getMinKeyLen(), $key->getBitLength())); |
|
| 84 | + } |
|
| 77 | 85 | |
| 78 | 86 | $res = $this->rsa_impl->loadKey($key->getEncoded()); |
| 79 | 87 | |
| 80 | - if(!$res) throw new InvalidKeyTypeAlgorithmException; |
|
| 88 | + if(!$res) { |
|
| 89 | + throw new InvalidKeyTypeAlgorithmException; |
|
| 90 | + } |
|
| 81 | 91 | |
| 82 | 92 | $this->rsa_impl->setHash($this->getHashingAlgorithm()); |
| 83 | 93 | $this->rsa_impl->setMGFHash($this->getHashingAlgorithm()); |
@@ -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 | |
@@ -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); |
@@ -47,19 +47,23 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function encrypt(Key $key, $message) |
| 49 | 49 | { |
| 50 | - if(!($key instanceof RSAPublicKey)) |
|
| 51 | - throw new InvalidKeyTypeAlgorithmException('key is not public'); |
|
| 50 | + if(!($key instanceof RSAPublicKey)) { |
|
| 51 | + throw new InvalidKeyTypeAlgorithmException('key is not public'); |
|
| 52 | + } |
|
| 52 | 53 | |
| 53 | - if($key->getFormat() !== 'PKCS8') |
|
| 54 | - throw new InvalidKeyTypeAlgorithmException('keys is not on PKCS1 format'); |
|
| 54 | + if($key->getFormat() !== 'PKCS8') { |
|
| 55 | + throw new InvalidKeyTypeAlgorithmException('keys is not on PKCS1 format'); |
|
| 56 | + } |
|
| 55 | 57 | |
| 56 | 58 | $res = $this->rsa_impl->loadKey($key->getEncoded()); |
| 57 | 59 | |
| 58 | - if(!$res) |
|
| 59 | - throw new InvalidKeyTypeAlgorithmException('could not parse the key'); |
|
| 60 | + if(!$res) { |
|
| 61 | + throw new InvalidKeyTypeAlgorithmException('could not parse the key'); |
|
| 62 | + } |
|
| 60 | 63 | |
| 61 | - if($this->rsa_impl->getSize() < $this->getMinKeyLen()) |
|
| 62 | - throw new InvalidKeyTypeAlgorithmException('len is invalid'); |
|
| 64 | + if($this->rsa_impl->getSize() < $this->getMinKeyLen()) { |
|
| 65 | + throw new InvalidKeyTypeAlgorithmException('len is invalid'); |
|
| 66 | + } |
|
| 63 | 67 | |
| 64 | 68 | return $this->rsa_impl->encrypt($message); |
| 65 | 69 | } |
@@ -72,20 +76,24 @@ discard block |
||
| 72 | 76 | */ |
| 73 | 77 | public function decrypt(Key $key, $enc_message){ |
| 74 | 78 | |
| 75 | - if(!($key instanceof RSAPrivateKey)) |
|
| 76 | - throw new InvalidKeyTypeAlgorithmException('key is not private'); |
|
| 79 | + if(!($key instanceof RSAPrivateKey)) { |
|
| 80 | + throw new InvalidKeyTypeAlgorithmException('key is not private'); |
|
| 81 | + } |
|
| 77 | 82 | |
| 78 | 83 | |
| 79 | - if($key->getFormat() !== 'PKCS1') |
|
| 80 | - throw new InvalidKeyTypeAlgorithmException('keys is not on PKCS1 format'); |
|
| 84 | + if($key->getFormat() !== 'PKCS1') { |
|
| 85 | + throw new InvalidKeyTypeAlgorithmException('keys is not on PKCS1 format'); |
|
| 86 | + } |
|
| 81 | 87 | |
| 82 | 88 | $res = $this->rsa_impl->loadKey($key->getEncoded()); |
| 83 | 89 | |
| 84 | - if(!$res) |
|
| 85 | - throw new InvalidKeyTypeAlgorithmException('could not parse the key'); |
|
| 90 | + if(!$res) { |
|
| 91 | + throw new InvalidKeyTypeAlgorithmException('could not parse the key'); |
|
| 92 | + } |
|
| 86 | 93 | |
| 87 | - if($this->rsa_impl->getSize() < $this->getMinKeyLen()) |
|
| 88 | - throw new InvalidKeyTypeAlgorithmException('len is invalid'); |
|
| 94 | + if($this->rsa_impl->getSize() < $this->getMinKeyLen()) { |
|
| 95 | + throw new InvalidKeyTypeAlgorithmException('len is invalid'); |
|
| 96 | + } |
|
| 89 | 97 | |
| 90 | 98 | return $this->rsa_impl->decrypt($enc_message); |
| 91 | 99 | } |
@@ -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 | |
@@ -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 jwa\cryptographic_algorithms\content_encryption\AES_CBC_HS; |
| 16 | 16 | |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | // MAC_KEY = initial MAC_KEY_LEN octets of K |
| 91 | 91 | $mac_key = substr($key, 0, $mac_key_len); |
| 92 | 92 | /** |
| 93 | - * The octet string AL is equal to the number of bits in the |
|
| 94 | - * Additional Authenticated Data ($aad) expressed as a 64-bit unsigned |
|
| 95 | - * big-endian integer |
|
| 96 | - */ |
|
| 93 | + * The octet string AL is equal to the number of bits in the |
|
| 94 | + * Additional Authenticated Data ($aad) expressed as a 64-bit unsigned |
|
| 95 | + * big-endian integer |
|
| 96 | + */ |
|
| 97 | 97 | $al = ByteUtil::convert2UnsignedLongBE(strlen($aad) * 8); |
| 98 | 98 | // M = MAC(MAC_KEY, A || IV || E || AL) |
| 99 | 99 | $secured_input = implode('', array( |
@@ -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; |
@@ -60,8 +60,9 @@ discard block |
||
| 60 | 60 | { |
| 61 | 61 | $key_len = strlen($key); |
| 62 | 62 | |
| 63 | - if($this->getMinKeyLen() > ByteUtil::bitLength($key_len)) |
|
| 64 | - throw new InvalidKeyLengthAlgorithmException; |
|
| 63 | + if($this->getMinKeyLen() > ByteUtil::bitLength($key_len)) { |
|
| 64 | + throw new InvalidKeyLengthAlgorithmException; |
|
| 65 | + } |
|
| 65 | 66 | |
| 66 | 67 | $enc_key_len = $key_len / 2; |
| 67 | 68 | // ENC_KEY = final ENC_KEY_LEN octets of K |
@@ -133,8 +134,9 @@ discard block |
||
| 133 | 134 | */ |
| 134 | 135 | public function decrypt($cypher_text, $key, $iv, $aad, $tag) |
| 135 | 136 | { |
| 136 | - if(!$this->checkAuthenticationTag($cypher_text, $key, $iv, $aad, $tag)) |
|
| 137 | - throw new InvalidAuthenticationTagException; |
|
| 137 | + if(!$this->checkAuthenticationTag($cypher_text, $key, $iv, $aad, $tag)) { |
|
| 138 | + throw new InvalidAuthenticationTagException; |
|
| 139 | + } |
|
| 138 | 140 | |
| 139 | 141 | $enc_key_len = strlen($key) / 2; |
| 140 | 142 | // ENC_KEY = final ENC_KEY_LEN octets of K |