@@ -50,7 +50,7 @@ public static function parseKeySet(array $jwks)
50
50
}
51
51
}
52
52
53
- if (0 === count ($ keys )) {
53
+ if (0 === \ count ($ keys )) {
54
54
throw new UnexpectedValueException ('No supported algorithms found in JWK Set ' );
55
55
}
56
56
@@ -81,18 +81,18 @@ private static function parseKey(array $jwk)
81
81
82
82
switch ($ jwk ['kty ' ]) {
83
83
case 'RSA ' :
84
- if (array_key_exists ('d ' , $ jwk )) {
84
+ if (\ array_key_exists ('d ' , $ jwk )) {
85
85
throw new UnexpectedValueException ('RSA private keys are not supported ' );
86
86
}
87
87
if (!isset ($ jwk ['n ' ]) || !isset ($ jwk ['e ' ])) {
88
88
throw new UnexpectedValueException ('RSA keys must contain values for both "n" and "e" ' );
89
89
}
90
90
91
91
$ pem = self ::createPemFromModulusAndExponent ($ jwk ['n ' ], $ jwk ['e ' ]);
92
- $ publicKey = openssl_pkey_get_public ($ pem );
92
+ $ publicKey = \ openssl_pkey_get_public ($ pem );
93
93
if (false === $ publicKey ) {
94
94
throw new DomainException (
95
- 'OpenSSL error: ' . openssl_error_string ()
95
+ 'OpenSSL error: ' . \ openssl_error_string ()
96
96
);
97
97
}
98
98
return $ publicKey ;
@@ -118,32 +118,32 @@ private static function createPemFromModulusAndExponent($n, $e)
118
118
$ publicExponent = JWT ::urlsafeB64Decode ($ e );
119
119
120
120
$ components = array (
121
- 'modulus ' => pack ('Ca*a* ' , 2 , self ::encodeLength (strlen ($ modulus )), $ modulus ),
122
- 'publicExponent ' => pack ('Ca*a* ' , 2 , self ::encodeLength (strlen ($ publicExponent )), $ publicExponent )
121
+ 'modulus ' => \ pack ('Ca*a* ' , 2 , self ::encodeLength (\ strlen ($ modulus )), $ modulus ),
122
+ 'publicExponent ' => \ pack ('Ca*a* ' , 2 , self ::encodeLength (\ strlen ($ publicExponent )), $ publicExponent )
123
123
);
124
124
125
- $ rsaPublicKey = pack (
125
+ $ rsaPublicKey = \ pack (
126
126
'Ca*a*a* ' ,
127
127
48 ,
128
- self ::encodeLength (strlen ($ components ['modulus ' ]) + strlen ($ components ['publicExponent ' ])),
128
+ self ::encodeLength (\ strlen ($ components ['modulus ' ]) + \ strlen ($ components ['publicExponent ' ])),
129
129
$ components ['modulus ' ],
130
130
$ components ['publicExponent ' ]
131
131
);
132
132
133
133
// sequence(oid(1.2.840.113549.1.1.1), null)) = rsaEncryption.
134
- $ rsaOID = pack ('H* ' , '300d06092a864886f70d0101010500 ' ); // hex version of MA0GCSqGSIb3DQEBAQUA
135
- $ rsaPublicKey = chr (0 ) . $ rsaPublicKey ;
136
- $ rsaPublicKey = chr (3 ) . self ::encodeLength (strlen ($ rsaPublicKey )) . $ rsaPublicKey ;
134
+ $ rsaOID = \ pack ('H* ' , '300d06092a864886f70d0101010500 ' ); // hex version of MA0GCSqGSIb3DQEBAQUA
135
+ $ rsaPublicKey = \ chr (0 ) . $ rsaPublicKey ;
136
+ $ rsaPublicKey = \ chr (3 ) . self ::encodeLength (\ strlen ($ rsaPublicKey )) . $ rsaPublicKey ;
137
137
138
- $ rsaPublicKey = pack (
138
+ $ rsaPublicKey = \ pack (
139
139
'Ca*a* ' ,
140
140
48 ,
141
- self ::encodeLength (strlen ($ rsaOID . $ rsaPublicKey )),
141
+ self ::encodeLength (\ strlen ($ rsaOID . $ rsaPublicKey )),
142
142
$ rsaOID . $ rsaPublicKey
143
143
);
144
144
145
145
$ rsaPublicKey = "-----BEGIN PUBLIC KEY----- \r\n" .
146
- chunk_split (base64_encode ($ rsaPublicKey ), 64 ) .
146
+ \ chunk_split (\ base64_encode ($ rsaPublicKey ), 64 ) .
147
147
'-----END PUBLIC KEY----- ' ;
148
148
149
149
return $ rsaPublicKey ;
@@ -161,11 +161,11 @@ private static function createPemFromModulusAndExponent($n, $e)
161
161
private static function encodeLength ($ length )
162
162
{
163
163
if ($ length <= 0x7F ) {
164
- return chr ($ length );
164
+ return \ chr ($ length );
165
165
}
166
166
167
- $ temp = ltrim (pack ('N ' , $ length ), chr (0 ));
167
+ $ temp = \ ltrim (\ pack ('N ' , $ length ), \ chr (0 ));
168
168
169
- return pack ('Ca* ' , 0x80 | strlen ($ temp ), $ temp );
169
+ return \ pack ('Ca* ' , 0x80 | \ strlen ($ temp ), $ temp );
170
170
}
171
171
}
0 commit comments