@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | * @throws InvalidJWKType |
37 | 37 | * @throws InvalidJWKUseException |
38 | 38 | */ |
39 | - protected function __construct(array $headers = []){ |
|
39 | + protected function __construct(array $headers = []) { |
|
40 | 40 | |
41 | - if(count($headers) === 0 ) return; |
|
41 | + if (count($headers) === 0) return; |
|
42 | 42 | |
43 | 43 | $alg = @$headers[JSONWebKeyParameters::Algorithm]; |
44 | 44 | $this->setAlgorithm($alg); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function setId($kid) |
82 | 82 | { |
83 | - if(!empty($kid)) |
|
83 | + if (!empty($kid)) |
|
84 | 84 | $this->set[JSONWebKeyParameters::KeyId] = new JsonValue($kid); |
85 | 85 | return $this; |
86 | 86 | } |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function setAlgorithm($alg) |
94 | 94 | { |
95 | - if(!in_array($alg, JSONWebSignatureAndEncryptionAlgorithms::$header_location_alg)) |
|
96 | - throw new InvalidJWKAlgorithm (sprintf('alg %s', $alg)); |
|
95 | + if (!in_array($alg, JSONWebSignatureAndEncryptionAlgorithms::$header_location_alg)) |
|
96 | + throw new InvalidJWKAlgorithm(sprintf('alg %s', $alg)); |
|
97 | 97 | |
98 | 98 | $this->set[JSONWebKeyParameters::Algorithm] = new StringOrURI($alg); |
99 | 99 | return $this; |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function setKeyUse($use) |
108 | 108 | { |
109 | - if(empty($use)) return $this; |
|
110 | - if(!in_array($use, JSONWebKeyPublicKeyUseValues::$valid_uses)) |
|
109 | + if (empty($use)) return $this; |
|
110 | + if (!in_array($use, JSONWebKeyPublicKeyUseValues::$valid_uses)) |
|
111 | 111 | throw new InvalidJWKUseException(sprintf('use %s', $use)); |
112 | 112 | |
113 | 113 | $this->set[JSONWebKeyParameters::PublicKeyUse] = new StringOrURI($use); |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function setType($type) |
123 | 123 | { |
124 | - if(!in_array($type, JSONWebKeyTypes::$valid_keys_set)) |
|
124 | + if (!in_array($type, JSONWebKeyTypes::$valid_keys_set)) |
|
125 | 125 | throw new InvalidJWKType(sprintf('use %s', $type)); |
126 | 126 | |
127 | 127 | $this->set[JSONWebKeyParameters::KeyType] = new StringOrURI($type); |
@@ -38,7 +38,9 @@ discard block |
||
38 | 38 | */ |
39 | 39 | protected function __construct(array $headers = []){ |
40 | 40 | |
41 | - if(count($headers) === 0 ) return; |
|
41 | + if(count($headers) === 0 ) { |
|
42 | + return; |
|
43 | + } |
|
42 | 44 | |
43 | 45 | $alg = @$headers[JSONWebKeyParameters::Algorithm]; |
44 | 46 | $this->setAlgorithm($alg); |
@@ -80,8 +82,9 @@ discard block |
||
80 | 82 | */ |
81 | 83 | public function setId($kid) |
82 | 84 | { |
83 | - if(!empty($kid)) |
|
84 | - $this->set[JSONWebKeyParameters::KeyId] = new JsonValue($kid); |
|
85 | + if(!empty($kid)) { |
|
86 | + $this->set[JSONWebKeyParameters::KeyId] = new JsonValue($kid); |
|
87 | + } |
|
85 | 88 | return $this; |
86 | 89 | } |
87 | 90 | |
@@ -92,8 +95,9 @@ discard block |
||
92 | 95 | */ |
93 | 96 | public function setAlgorithm($alg) |
94 | 97 | { |
95 | - if(!in_array($alg, JSONWebSignatureAndEncryptionAlgorithms::$header_location_alg)) |
|
96 | - throw new InvalidJWKAlgorithm (sprintf('alg %s', $alg)); |
|
98 | + if(!in_array($alg, JSONWebSignatureAndEncryptionAlgorithms::$header_location_alg)) { |
|
99 | + throw new InvalidJWKAlgorithm (sprintf('alg %s', $alg)); |
|
100 | + } |
|
97 | 101 | |
98 | 102 | $this->set[JSONWebKeyParameters::Algorithm] = new StringOrURI($alg); |
99 | 103 | return $this; |
@@ -106,9 +110,12 @@ discard block |
||
106 | 110 | */ |
107 | 111 | public function setKeyUse($use) |
108 | 112 | { |
109 | - if(empty($use)) return $this; |
|
110 | - if(!in_array($use, JSONWebKeyPublicKeyUseValues::$valid_uses)) |
|
111 | - throw new InvalidJWKUseException(sprintf('use %s', $use)); |
|
113 | + if(empty($use)) { |
|
114 | + return $this; |
|
115 | + } |
|
116 | + if(!in_array($use, JSONWebKeyPublicKeyUseValues::$valid_uses)) { |
|
117 | + throw new InvalidJWKUseException(sprintf('use %s', $use)); |
|
118 | + } |
|
112 | 119 | |
113 | 120 | $this->set[JSONWebKeyParameters::PublicKeyUse] = new StringOrURI($use); |
114 | 121 | return $this; |
@@ -121,8 +128,9 @@ discard block |
||
121 | 128 | */ |
122 | 129 | public function setType($type) |
123 | 130 | { |
124 | - if(!in_array($type, JSONWebKeyTypes::$valid_keys_set)) |
|
125 | - throw new InvalidJWKType(sprintf('use %s', $type)); |
|
131 | + if(!in_array($type, JSONWebKeyTypes::$valid_keys_set)) { |
|
132 | + throw new InvalidJWKType(sprintf('use %s', $type)); |
|
133 | + } |
|
126 | 134 | |
127 | 135 | $this->set[JSONWebKeyParameters::KeyType] = new StringOrURI($type); |
128 | 136 | return $this; |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @param int $byte_len |
23 | 23 | * @return int |
24 | 24 | */ |
25 | - static public function bitLength($byte_len){ |
|
25 | + static public function bitLength($byte_len) { |
|
26 | 26 | return $byte_len * 8; |
27 | 27 | } |
28 | 28 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param int $byte_len |
31 | 31 | * @return String |
32 | 32 | */ |
33 | - static public function randomBytes($byte_len){ |
|
33 | + static public function randomBytes($byte_len) { |
|
34 | 34 | return Random::string($byte_len); |
35 | 35 | } |
36 | 36 | |
@@ -38,10 +38,10 @@ discard block |
||
38 | 38 | * @param array $oct |
39 | 39 | * @return string |
40 | 40 | */ |
41 | - static public function convertHalfWordArrayToBin(array $oct){ |
|
41 | + static public function convertHalfWordArrayToBin(array $oct) { |
|
42 | 42 | $hex = ''; |
43 | - foreach($oct as $b){ |
|
44 | - $hex .= str_pad(dechex($b),2,'0',STR_PAD_LEFT); |
|
43 | + foreach ($oct as $b) { |
|
44 | + $hex .= str_pad(dechex($b), 2, '0', STR_PAD_LEFT); |
|
45 | 45 | } |
46 | 46 | return self::hex2bin($hex); |
47 | 47 | } |
@@ -50,15 +50,15 @@ discard block |
||
50 | 50 | * @param int $nbr |
51 | 51 | * @return string |
52 | 52 | */ |
53 | - static public function convert2UnsignedLongBE($nbr){ |
|
54 | - $hex = str_pad(dechex($nbr),16,'0',STR_PAD_LEFT); |
|
53 | + static public function convert2UnsignedLongBE($nbr) { |
|
54 | + $hex = str_pad(dechex($nbr), 16, '0', STR_PAD_LEFT); |
|
55 | 55 | return self::hex2bin($hex); |
56 | 56 | } |
57 | 57 | |
58 | - static public function hex2bin($hex_string){ |
|
59 | - if ( function_exists( 'hex2bin' ) ){ |
|
58 | + static public function hex2bin($hex_string) { |
|
59 | + if (function_exists('hex2bin')) { |
|
60 | 60 | return hex2bin($hex_string); |
61 | 61 | } |
62 | - return pack("H*" , $hex_string); |
|
62 | + return pack("H*", $hex_string); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | \ No newline at end of file |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @return BigInteger |
24 | 24 | */ |
25 | - public function toBigInt(){ |
|
25 | + public function toBigInt() { |
|
26 | 26 | $b64 = new Base64UrlRepresentation(); |
27 | 27 | $hex = bin2hex($b64->decode($this->value)); |
28 | 28 | return new BigInteger('0x'.$hex, 16); |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @param BigInteger $big_int |
33 | 33 | * @return Base64urlUInt |
34 | 34 | */ |
35 | - public static function fromBigInt(BigInteger $big_int){ |
|
35 | + public static function fromBigInt(BigInteger $big_int) { |
|
36 | 36 | $b64 = new Base64UrlRepresentation(); |
37 | 37 | $input = $big_int->toBytes(); |
38 | 38 | return new Base64urlUInt($b64->encode($input)); |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class JOSEHeaderFactory { |
23 | 23 | |
24 | - static protected function getProductClass(){ |
|
24 | + static protected function getProductClass() { |
|
25 | 25 | return '\jwt\impl\JOSEHeader'; |
26 | 26 | } |
27 | 27 | |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | |
36 | 36 | $args = []; |
37 | 37 | |
38 | - foreach(RegisteredJOSEHeaderNames::$registered_basic_headers_set as $header_name){ |
|
38 | + foreach (RegisteredJOSEHeaderNames::$registered_basic_headers_set as $header_name) { |
|
39 | 39 | $value = isset($raw_headers[$header_name]) ? $raw_headers[$header_name] : null; |
40 | 40 | $type = @RegisteredJOSEHeaderNames::$registered_basic_headers_set_types[$header_name]; |
41 | - if(!is_null($value)) |
|
41 | + if (!is_null($value)) |
|
42 | 42 | { |
43 | - if(is_null($type)) continue; |
|
43 | + if (is_null($type)) continue; |
|
44 | 44 | $class = new \ReflectionClass($type); |
45 | 45 | $value = $class->newInstanceArgs(array($value)); |
46 | 46 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | // unregistered headers |
56 | 56 | |
57 | - foreach($raw_headers as $k => $v){ |
|
57 | + foreach ($raw_headers as $k => $v) { |
|
58 | 58 | $basic_header->addHeader(new JOSEHeaderParam($k, new JsonValue($v))); |
59 | 59 | } |
60 | 60 |
@@ -46,7 +46,7 @@ |
||
46 | 46 | * @return array |
47 | 47 | * @throws JWEInvalidCompactFormatException |
48 | 48 | */ |
49 | - static public function deserialize($input){ |
|
49 | + static public function deserialize($input) { |
|
50 | 50 | $parts = explode(IBasicJWT::SegmentSeparator, $input); |
51 | 51 | if (count($parts) !== 5) throw new JWEInvalidCompactFormatException; |
52 | 52 |
@@ -48,7 +48,9 @@ |
||
48 | 48 | */ |
49 | 49 | static public function deserialize($input){ |
50 | 50 | $parts = explode(IBasicJWT::SegmentSeparator, $input); |
51 | - if (count($parts) !== 5) throw new JWEInvalidCompactFormatException; |
|
51 | + if (count($parts) !== 5) { |
|
52 | + throw new JWEInvalidCompactFormatException; |
|
53 | + } |
|
52 | 54 | |
53 | 55 | $header = JWEJOSEHeaderSerializer::deserialize($parts[0]); |
54 | 56 | $enc_cek = JWTRawSerializer::deserialize($parts[1]); |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | final class JWEJOSEHeaderFactory { |
23 | 23 | |
24 | - static protected function getProductClass(){ |
|
24 | + static protected function getProductClass() { |
|
25 | 25 | return '\jwe\impl\JWEJOSEHeader'; |
26 | 26 | } |
27 | 27 | |
@@ -30,16 +30,16 @@ discard block |
||
30 | 30 | * @return IJWEJOSEHeader |
31 | 31 | * @throws \ReflectionException |
32 | 32 | */ |
33 | - public static function build(array $raw_headers){ |
|
33 | + public static function build(array $raw_headers) { |
|
34 | 34 | |
35 | 35 | $args = array(); |
36 | 36 | |
37 | - foreach(RegisteredJWEJOSEHeaderNames::$registered_basic_headers_set as $header_name){ |
|
37 | + foreach (RegisteredJWEJOSEHeaderNames::$registered_basic_headers_set as $header_name) { |
|
38 | 38 | $value = isset($raw_headers[$header_name]) ? $raw_headers[$header_name] : null; |
39 | 39 | $type = @RegisteredJWEJOSEHeaderNames::$registered_basic_headers_set_types[$header_name]; |
40 | - if(!is_null($value)) |
|
40 | + if (!is_null($value)) |
|
41 | 41 | { |
42 | - if(is_null($type)) continue; |
|
42 | + if (is_null($type)) continue; |
|
43 | 43 | $class = new \ReflectionClass($type); |
44 | 44 | $value = $class->newInstanceArgs(array($value)); |
45 | 45 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | // unregistered headers |
55 | 55 | |
56 | - foreach($raw_headers as $k => $v){ |
|
56 | + foreach ($raw_headers as $k => $v) { |
|
57 | 57 | $basic_header->addHeader(new JOSEHeaderParam($k, new JsonValue($v))); |
58 | 58 | } |
59 | 59 |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | private $algorithms = []; |
29 | 29 | |
30 | - private function __construct(){ |
|
30 | + private function __construct() { |
|
31 | 31 | |
32 | 32 | $this->algorithms[CompressionAlgorithmsNames::Deflate] = new Deflate; |
33 | 33 | $this->algorithms[CompressionAlgorithmsNames::GZip] = new GZip; |
@@ -35,13 +35,13 @@ discard block |
||
35 | 35 | |
36 | 36 | } |
37 | 37 | |
38 | - private function __clone(){} |
|
38 | + private function __clone() {} |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * @return CompressionAlgorithms_Registry |
42 | 42 | */ |
43 | - public static function getInstance(){ |
|
44 | - if(!is_object(self::$instance)){ |
|
43 | + public static function getInstance() { |
|
44 | + if (!is_object(self::$instance)) { |
|
45 | 45 | self::$instance = new CompressionAlgorithms_Registry(); |
46 | 46 | } |
47 | 47 | return self::$instance; |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @param string $alg |
52 | 52 | * @return bool |
53 | 53 | */ |
54 | - public function isSupported($alg){ |
|
54 | + public function isSupported($alg) { |
|
55 | 55 | return array_key_exists($alg, $this->algorithms); |
56 | 56 | } |
57 | 57 | |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | * @param $alg |
60 | 60 | * @return null|CompressionAlgorithm |
61 | 61 | */ |
62 | - public function get($alg){ |
|
63 | - if(!$this->isSupported($alg)) return null; |
|
62 | + public function get($alg) { |
|
63 | + if (!$this->isSupported($alg)) return null; |
|
64 | 64 | return $this->algorithms[$alg]; |
65 | 65 | } |
66 | 66 | } |
67 | 67 | \ No newline at end of file |
@@ -24,6 +24,6 @@ |
||
24 | 24 | */ |
25 | 25 | public function getPaddingMode() |
26 | 26 | { |
27 | - return RSA::SIGNATURE_PKCS1 ; |
|
27 | + return RSA::SIGNATURE_PKCS1; |
|
28 | 28 | } |
29 | 29 | } |
30 | 30 | \ No newline at end of file |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | private $algorithms = []; |
38 | 38 | |
39 | - private function __construct(){ |
|
39 | + private function __construct() { |
|
40 | 40 | |
41 | 41 | $this->algorithms[JSONWebSignatureAndEncryptionAlgorithms::HS256] = new HS256_Algorithm; |
42 | 42 | $this->algorithms[JSONWebSignatureAndEncryptionAlgorithms::HS384] = new HS384_Algorithm; |
@@ -52,13 +52,13 @@ discard block |
||
52 | 52 | |
53 | 53 | } |
54 | 54 | |
55 | - private function __clone(){} |
|
55 | + private function __clone() {} |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @return DigitalSignatures_MACs_Registry |
59 | 59 | */ |
60 | - public static function getInstance(){ |
|
61 | - if(!is_object(self::$instance)){ |
|
60 | + public static function getInstance() { |
|
61 | + if (!is_object(self::$instance)) { |
|
62 | 62 | self::$instance = new DigitalSignatures_MACs_Registry(); |
63 | 63 | } |
64 | 64 | return self::$instance; |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @param string $alg |
69 | 69 | * @return bool |
70 | 70 | */ |
71 | - public function isSupported($alg){ |
|
71 | + public function isSupported($alg) { |
|
72 | 72 | return array_key_exists($alg, $this->algorithms); |
73 | 73 | } |
74 | 74 | |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @param $alg |
77 | 77 | * @return null|DigitalSignatureAlgorithm|MAC_Algorithm |
78 | 78 | */ |
79 | - public function get($alg){ |
|
80 | - if(!$this->isSupported($alg)) return null; |
|
79 | + public function get($alg) { |
|
80 | + if (!$this->isSupported($alg)) return null; |
|
81 | 81 | return $this->algorithms[$alg]; |
82 | 82 | } |
83 | 83 | } |
84 | 84 | \ No newline at end of file |