@@ -95,8 +95,9 @@ discard block |
||
95 | 95 | foreach($this->set as $key => $val){ |
96 | 96 | if($val instanceof JsonValue){ |
97 | 97 | $res[$key] = $val->getValue(); |
98 | - if($res[$key] instanceof JsonObject) |
|
99 | - $res[$key] = $res[$key]->toArray(); |
|
98 | + if($res[$key] instanceof JsonObject) { |
|
99 | + $res[$key] = $res[$key]->toArray(); |
|
100 | + } |
|
100 | 101 | if(is_array($res[$key])){ |
101 | 102 | $res[$key] = $this->processArray($res[$key]); |
102 | 103 | } |
@@ -109,8 +110,9 @@ discard block |
||
109 | 110 | private function processArray($original){ |
110 | 111 | $temp = array(); |
111 | 112 | foreach($original as $k => $val){ |
112 | - if($val instanceof JsonObject) |
|
113 | - $val = $val->toArray(); |
|
113 | + if($val instanceof JsonObject) { |
|
114 | + $val = $val->toArray(); |
|
115 | + } |
|
114 | 116 | $temp[$k] = $val; |
115 | 117 | } |
116 | 118 | return $temp; |
@@ -40,7 +40,9 @@ |
||
40 | 40 | $type = @RegisteredJWEJOSEHeaderNames::$registered_basic_headers_set_types[$header_name]; |
41 | 41 | if(!is_null($value)) |
42 | 42 | { |
43 | - if(is_null($type)) continue; |
|
43 | + if(is_null($type)) { |
|
44 | + continue; |
|
45 | + } |
|
44 | 46 | $class = new \ReflectionClass($type); |
45 | 47 | $value = $class->newInstanceArgs(array($value)); |
46 | 48 | } |
@@ -50,8 +50,9 @@ |
||
50 | 50 | |
51 | 51 | $this->set[RegisteredJWEJOSEHeaderNames::EncryptionAlgorithm] = $enc; |
52 | 52 | |
53 | - if(!is_null($zip) && CompressionAlgorithms_Registry::getInstance()->get($zip->getValue())) |
|
54 | - $this->set[RegisteredJWEJOSEHeaderNames::CompressionAlgorithm] = $zip; |
|
53 | + if(!is_null($zip) && CompressionAlgorithms_Registry::getInstance()->get($zip->getValue())) { |
|
54 | + $this->set[RegisteredJWEJOSEHeaderNames::CompressionAlgorithm] = $zip; |
|
55 | + } |
|
55 | 56 | } |
56 | 57 | |
57 | 58 | /** |
@@ -66,11 +66,13 @@ |
||
66 | 66 | public function __construct(IJWK $key, StringOrURI $alg, StringOrURI $enc, $payload, JsonValue $zip = null) |
67 | 67 | { |
68 | 68 | |
69 | - if(is_null($key)) |
|
70 | - throw new JWEInvalidRecipientKeyException(); |
|
69 | + if(is_null($key)) { |
|
70 | + throw new JWEInvalidRecipientKeyException(); |
|
71 | + } |
|
71 | 72 | |
72 | - if(is_null($payload)) |
|
73 | - throw new JWEInvalidPayloadException('missing payload'); |
|
73 | + if(is_null($payload)) { |
|
74 | + throw new JWEInvalidPayloadException('missing payload'); |
|
75 | + } |
|
74 | 76 | |
75 | 77 | $this->key = $key; |
76 | 78 | $this->alg = $alg; |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | if($spec instanceof IJWE_ParamsSpecification) |
41 | 41 | { |
42 | 42 | |
43 | - if($spec->getRecipientKey()->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Encryption) |
|
44 | - throw new InvalidJWKType |
|
43 | + if($spec->getRecipientKey()->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Encryption) { |
|
44 | + throw new InvalidJWKType |
|
45 | 45 | ( |
46 | 46 | sprintf |
47 | 47 | ( |
@@ -49,9 +49,10 @@ discard block |
||
49 | 49 | $spec->getRecipientKey()->getKeyUse()->getString() |
50 | 50 | ) |
51 | 51 | ); |
52 | + } |
|
52 | 53 | |
53 | - if($spec->getAlg()->getString() !== $spec->getRecipientKey()->getAlgorithm()->getString()) |
|
54 | - throw new InvalidJWKAlgorithm |
|
54 | + if($spec->getAlg()->getString() !== $spec->getRecipientKey()->getAlgorithm()->getString()) { |
|
55 | + throw new InvalidJWKAlgorithm |
|
55 | 56 | ( |
56 | 57 | sprintf |
57 | 58 | ( |
@@ -60,6 +61,7 @@ discard block |
||
60 | 61 | $spec->getRecipientKey()->getAlgorithm()->getString() |
61 | 62 | ) |
62 | 63 | ); |
64 | + } |
|
63 | 65 | |
64 | 66 | $header = new JWEJOSEHeader |
65 | 67 | ( |
@@ -71,8 +73,9 @@ discard block |
||
71 | 73 | //set zip alg |
72 | 74 | $zip = $spec->getZip(); |
73 | 75 | |
74 | - if(!is_null($zip)) |
|
75 | - $header->setCompressionAlgorithm($zip); |
|
76 | + if(!is_null($zip)) { |
|
77 | + $header->setCompressionAlgorithm($zip); |
|
78 | + } |
|
76 | 79 | |
77 | 80 | $jwe = JWE::fromHeaderAndPayload($header, $spec->getPayload()); |
78 | 81 |
@@ -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 |
@@ -40,14 +40,17 @@ |
||
40 | 40 | protected function __construct(Key $secret, $headers = array()) |
41 | 41 | { |
42 | 42 | |
43 | - if(empty($secret)) |
|
44 | - throw new InvalidOctetSequenceJWKException('secret is not set!.'); |
|
43 | + if(empty($secret)) { |
|
44 | + throw new InvalidOctetSequenceJWKException('secret is not set!.'); |
|
45 | + } |
|
45 | 46 | |
46 | 47 | $this->set[JSONWebKeyParameters::KeyType] = new StringOrURI(JSONWebKeyTypes::OctetSequence); |
47 | 48 | |
48 | 49 | parent::__construct($headers); |
49 | 50 | |
50 | - if(count($headers) === 0 ) return; |
|
51 | + if(count($headers) === 0 ) { |
|
52 | + return; |
|
53 | + } |
|
51 | 54 | |
52 | 55 | $b64 = new Base64UrlRepresentation(); |
53 | 56 |
@@ -41,37 +41,42 @@ 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 |
47 | 49 | ( |
48 | 50 | $spec->getAlg() |
49 | 51 | ); |
50 | 52 | |
51 | - if(is_null($algorithm)) |
|
52 | - $algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get |
|
53 | + if(is_null($algorithm)) { |
|
54 | + $algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get |
|
53 | 55 | ( |
54 | 56 | $spec->getAlg() |
55 | 57 | ); |
58 | + } |
|
56 | 59 | |
57 | - if(is_null($algorithm)) |
|
58 | - $algorithm = KeyManagementAlgorithms_Registry::getInstance()->get |
|
60 | + if(is_null($algorithm)) { |
|
61 | + $algorithm = KeyManagementAlgorithms_Registry::getInstance()->get |
|
59 | 62 | ( |
60 | 63 | $spec->getAlg() |
61 | 64 | ); |
65 | + } |
|
62 | 66 | |
63 | - if(is_null($algorithm)) |
|
64 | - throw new InvalidJWKAlgorithm |
|
67 | + if(is_null($algorithm)) { |
|
68 | + throw new InvalidJWKAlgorithm |
|
65 | 69 | ( |
66 | 70 | sprintf( |
67 | 71 | 'alg %s not supported!', |
68 | 72 | $spec->getAlg() |
69 | 73 | ) |
70 | 74 | ); |
75 | + } |
|
71 | 76 | |
72 | 77 | |
73 | - if($algorithm->getKeyType() !== JSONWebKeyTypes::OctetSequence) |
|
74 | - throw new InvalidJWKAlgorithm |
|
78 | + if($algorithm->getKeyType() !== JSONWebKeyTypes::OctetSequence) { |
|
79 | + throw new InvalidJWKAlgorithm |
|
75 | 80 | ( |
76 | 81 | sprintf |
77 | 82 | ( |
@@ -79,8 +84,11 @@ discard block |
||
79 | 84 | $algorithm->getKeyType() |
80 | 85 | ) |
81 | 86 | ); |
87 | + } |
|
82 | 88 | |
83 | - if(!($spec instanceof OctetSequenceJWKSpecification)) throw new JWKInvalidSpecException; |
|
89 | + if(!($spec instanceof OctetSequenceJWKSpecification)) { |
|
90 | + throw new JWKInvalidSpecException; |
|
91 | + } |
|
84 | 92 | |
85 | 93 | $shared_secret = $spec->getSharedSecret(); |
86 | 94 | $secret_len = strlen($shared_secret); |
@@ -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]; |