@@ -9,21 +9,21 @@ discard block |
||
9 | 9 | function assertEqual($a, $b) { |
10 | 10 | if ($a != $b) { |
11 | 11 | global $failure; |
12 | - $failure ++; |
|
13 | - echo "\n FAIL: '" . $a . "' != '" . $b . "'"; |
|
14 | - } else { |
|
12 | + $failure++; |
|
13 | + echo "\n FAIL: '".$a."' != '".$b."'"; |
|
14 | + }else { |
|
15 | 15 | global $success; |
16 | - $success ++; |
|
16 | + $success++; |
|
17 | 17 | echo "\n success"; |
18 | 18 | } |
19 | 19 | } |
20 | 20 | |
21 | 21 | function printHeader($text) { |
22 | - echo "\n " . $text . " test:"; |
|
22 | + echo "\n ".$text." test:"; |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | function printSubHeader($text) { |
26 | - echo "\n " . $text . ":"; |
|
26 | + echo "\n ".$text.":"; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | |
134 | 134 | |
135 | 135 | if ($failure == 0) { |
136 | - echo "\n\nALL " . $success . " TESTS SUCCESSFUL\n\n"; |
|
137 | -} else { |
|
138 | - echo "\n\n" . $failure . "/" . ($failure + $success) . " FAILURES OCCURRED\n\n"; |
|
136 | + echo "\n\nALL ".$success." TESTS SUCCESSFUL\n\n"; |
|
137 | +}else { |
|
138 | + echo "\n\n".$failure."/".($failure + $success)." FAILURES OCCURRED\n\n"; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | ?> |
@@ -6,13 +6,13 @@ |
||
6 | 6 | |
7 | 7 | class Ecdsa { |
8 | 8 | |
9 | - public static function sign ($message, $privateKey) { |
|
9 | + public static function sign($message, $privateKey) { |
|
10 | 10 | $signature = null; |
11 | 11 | openssl_sign($message, $signature, $privateKey->openSslPrivateKey, OPENSSL_ALGO_SHA256); |
12 | 12 | return new Signature($signature); |
13 | 13 | } |
14 | 14 | |
15 | - public static function verify ($message, $signature, $publicKey) { |
|
15 | + public static function verify($message, $signature, $publicKey) { |
|
16 | 16 | $success = openssl_verify($message, $signature->toDer(), $publicKey->openSslPublicKey, OPENSSL_ALGO_SHA256); |
17 | 17 | if ($success == 1) { |
18 | 18 | return true; |
@@ -3,7 +3,7 @@ |
||
3 | 3 | namespace EllipticCurve\Utils; |
4 | 4 | |
5 | 5 | class File { |
6 | - static function read($path, $mode="r") { |
|
6 | + static function read($path, $mode = "r") { |
|
7 | 7 | $file = fopen($path, $mode); |
8 | 8 | $content = fread($file, filesize($path)); |
9 | 9 | fclose($file); |
@@ -5,23 +5,23 @@ |
||
5 | 5 | |
6 | 6 | class Signature { |
7 | 7 | |
8 | - function __construct ($der) { |
|
8 | + function __construct($der) { |
|
9 | 9 | $this->der = $der; |
10 | 10 | } |
11 | 11 | |
12 | - function toDer () { |
|
12 | + function toDer() { |
|
13 | 13 | return $this->der; |
14 | 14 | } |
15 | 15 | |
16 | - function toBase64 () { |
|
16 | + function toBase64() { |
|
17 | 17 | return base64_encode($this->der); |
18 | 18 | } |
19 | 19 | |
20 | - static function fromDer ($str) { |
|
20 | + static function fromDer($str) { |
|
21 | 21 | return new Signature($str); |
22 | 22 | } |
23 | 23 | |
24 | - static function fromBase64 ($str) { |
|
24 | + static function fromBase64($str) { |
|
25 | 25 | return new Signature(base64_decode($str)); |
26 | 26 | } |
27 | 27 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | |
6 | 6 | |
7 | 7 | class PrivateKey { |
8 | - function __construct($curve="secp256k1", $openSslPrivateKey=null) { |
|
8 | + function __construct($curve = "secp256k1", $openSslPrivateKey = null) { |
|
9 | 9 | if (is_null($openSslPrivateKey)) { |
10 | 10 | $config = array( |
11 | 11 | "digest_alg" => "sha256", |
@@ -30,15 +30,15 @@ discard block |
||
30 | 30 | return new PublicKey($openSslPublicKey); |
31 | 31 | } |
32 | 32 | |
33 | - function toString () { |
|
33 | + function toString() { |
|
34 | 34 | return base64_encode($this->toDer()); |
35 | 35 | } |
36 | 36 | |
37 | - function toDer () { |
|
37 | + function toDer() { |
|
38 | 38 | $pem = $this->toPem(); |
39 | 39 | |
40 | 40 | $lines = array(); |
41 | - foreach(explode("\n", $pem) as $value) { |
|
41 | + foreach (explode("\n", $pem) as $value) { |
|
42 | 42 | if (substr($value, 0, 5) !== "-----") { |
43 | 43 | array_push($lines, $value); |
44 | 44 | } |
@@ -49,30 +49,30 @@ discard block |
||
49 | 49 | return base64_decode($pem_data); |
50 | 50 | } |
51 | 51 | |
52 | - function toPem () { |
|
52 | + function toPem() { |
|
53 | 53 | openssl_pkey_export($this->openSslPrivateKey, $out, null); |
54 | 54 | return $out; |
55 | 55 | } |
56 | 56 | |
57 | - static function fromPem ($str) { |
|
57 | + static function fromPem($str) { |
|
58 | 58 | $rebuilt = array(); |
59 | - foreach(explode("\n", $str) as $line) { |
|
59 | + foreach (explode("\n", $str) as $line) { |
|
60 | 60 | $line = trim($line); |
61 | 61 | if (strlen($line) > 1) { |
62 | 62 | array_push($rebuilt, $line); |
63 | 63 | } |
64 | 64 | }; |
65 | - $rebuilt = join("\n", $rebuilt) . "\n"; |
|
65 | + $rebuilt = join("\n", $rebuilt)."\n"; |
|
66 | 66 | return new PrivateKey(null, openssl_get_privatekey($rebuilt)); |
67 | 67 | } |
68 | 68 | |
69 | - static function fromDer ($str) { |
|
69 | + static function fromDer($str) { |
|
70 | 70 | $pem_data = base64_encode($str); |
71 | - $pem = "-----BEGIN EC PRIVATE KEY-----\n" . substr($pem_data, 0, 64) . "\n" . substr($pem_data, 64, 64) . "\n" . substr($pem_data, 128, 64) . "\n-----END EC PRIVATE KEY-----\n"; |
|
71 | + $pem = "-----BEGIN EC PRIVATE KEY-----\n".substr($pem_data, 0, 64)."\n".substr($pem_data, 64, 64)."\n".substr($pem_data, 128, 64)."\n-----END EC PRIVATE KEY-----\n"; |
|
72 | 72 | return new PrivateKey(null, openssl_get_privatekey($pem)); |
73 | 73 | } |
74 | 74 | |
75 | - static function fromString ($str) { |
|
75 | + static function fromString($str) { |
|
76 | 76 | return PrivateKey::fromDer(base64_decode($str)); |
77 | 77 | } |
78 | 78 |
@@ -5,20 +5,20 @@ discard block |
||
5 | 5 | |
6 | 6 | class PublicKey { |
7 | 7 | |
8 | - function __construct ($pem) { |
|
8 | + function __construct($pem) { |
|
9 | 9 | $this->pem = $pem; |
10 | 10 | $this->openSslPublicKey = openssl_get_publickey($pem); |
11 | 11 | } |
12 | 12 | |
13 | - function toString () { |
|
13 | + function toString() { |
|
14 | 14 | return base64_encode($this->toDer()); |
15 | 15 | } |
16 | 16 | |
17 | - function toDer () { |
|
17 | + function toDer() { |
|
18 | 18 | $pem = $this->toPem(); |
19 | 19 | |
20 | 20 | $lines = array(); |
21 | - foreach(explode("\n", $pem) as $value) { |
|
21 | + foreach (explode("\n", $pem) as $value) { |
|
22 | 22 | if (substr($value, 0, 5) !== "-----") { |
23 | 23 | array_push($lines, $value); |
24 | 24 | } |
@@ -29,29 +29,29 @@ discard block |
||
29 | 29 | return base64_decode($pem_data); |
30 | 30 | } |
31 | 31 | |
32 | - function toPem () { |
|
32 | + function toPem() { |
|
33 | 33 | return $this->pem; |
34 | 34 | } |
35 | 35 | |
36 | - static function fromPem ($str) { |
|
36 | + static function fromPem($str) { |
|
37 | 37 | $rebuilt = array(); |
38 | - foreach(explode("\n", $str) as $line) { |
|
38 | + foreach (explode("\n", $str) as $line) { |
|
39 | 39 | $line = trim($line); |
40 | 40 | if (strlen($line) > 1) { |
41 | 41 | array_push($rebuilt, $line); |
42 | 42 | } |
43 | 43 | }; |
44 | - $rebuilt = join("\n", $rebuilt) . "\n"; |
|
44 | + $rebuilt = join("\n", $rebuilt)."\n"; |
|
45 | 45 | return new PublicKey($rebuilt); |
46 | 46 | } |
47 | 47 | |
48 | - static function fromDer ($str) { |
|
48 | + static function fromDer($str) { |
|
49 | 49 | $pem_data = base64_encode($str); |
50 | - $pem = "-----BEGIN PUBLIC KEY-----\n" . substr($pem_data, 0, 64) . "\n" . substr($pem_data, 64) . "\n-----END PUBLIC KEY-----\n"; |
|
50 | + $pem = "-----BEGIN PUBLIC KEY-----\n".substr($pem_data, 0, 64)."\n".substr($pem_data, 64)."\n-----END PUBLIC KEY-----\n"; |
|
51 | 51 | return new PublicKey($pem); |
52 | 52 | } |
53 | 53 | |
54 | - static function fromString ($str) { |
|
54 | + static function fromString($str) { |
|
55 | 55 | return PublicKey::fromDer(base64_decode($str)); |
56 | 56 | } |
57 | 57 |
@@ -2,5 +2,5 @@ |
||
2 | 2 | |
3 | 3 | // Don't redefine the functions if included multiple times. |
4 | 4 | if (!\function_exists('GuzzleHttp\describe_type')) { |
5 | - require __DIR__ . '/functions.php'; |
|
5 | + require __DIR__.'/functions.php'; |
|
6 | 6 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $options['allow_redirects'] = self::$defaultSettings; |
60 | 60 | } elseif (!\is_array($options['allow_redirects'])) { |
61 | 61 | throw new \InvalidArgumentException('allow_redirects must be true, false, or array'); |
62 | - } else { |
|
62 | + }else { |
|
63 | 63 | // Merge the default settings with the provided settings |
64 | 64 | $options['allow_redirects'] += self::$defaultSettings; |
65 | 65 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | } |
70 | 70 | |
71 | 71 | return $fn($request, $options) |
72 | - ->then(function (ResponseInterface $response) use ($request, $options) { |
|
72 | + ->then(function(ResponseInterface $response) use ($request, $options) { |
|
73 | 73 | return $this->checkRedirect($request, $options, $response); |
74 | 74 | }); |
75 | 75 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | private function withTracking(PromiseInterface $promise, string $uri, int $statusCode): PromiseInterface |
125 | 125 | { |
126 | 126 | return $promise->then( |
127 | - static function (ResponseInterface $response) use ($uri, $statusCode) { |
|
127 | + static function(ResponseInterface $response) use ($uri, $statusCode) { |
|
128 | 128 | // Note that we are pushing to the front of the list as this |
129 | 129 | // would be an earlier response than what is currently present |
130 | 130 | // in the history header. |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | ) { |
193 | 193 | $uri = $request->getUri()->withUserInfo(''); |
194 | 194 | $modify['set_headers']['Referer'] = (string) $uri; |
195 | - } else { |
|
195 | + }else { |
|
196 | 196 | $modify['remove_headers'][] = 'Referer'; |
197 | 197 | } |
198 | 198 |
@@ -262,7 +262,7 @@ |
||
262 | 262 | // Add the default user-agent header. |
263 | 263 | if (!isset($this->config['headers'])) { |
264 | 264 | $this->config['headers'] = ['User-Agent' => Utils::defaultUserAgent()]; |
265 | - } else { |
|
265 | + }else { |
|
266 | 266 | // Add the User-Agent header if one was not already set. |
267 | 267 | foreach (\array_keys($this->config['headers']) as $name) { |
268 | 268 | if (\strtolower($name) === 'user-agent') { |