| Conditions | 2 |
| Paths | 2 |
| Total Lines | 31 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 7 | public static function generate(array $payload = null, string $kid, string $url, string $nonce, string $accountKeysPath): array |
||
| 8 | { |
||
| 9 | $privateKey = openssl_pkey_get_private(file_get_contents($accountKeysPath . 'private.pem')); |
||
| 10 | |||
| 11 | $data = [ |
||
| 12 | 'alg' => 'RS256', |
||
| 13 | 'kid' => $kid, |
||
| 14 | 'nonce' => $nonce, |
||
| 15 | 'url' => $url, |
||
| 16 | ]; |
||
| 17 | |||
| 18 | $payload = is_array($payload) |
||
| 19 | ? str_replace('\\/', '/', json_encode($payload)) |
||
| 20 | : ''; |
||
| 21 | |||
| 22 | $payload64 = Base64::urlSafeEncode($payload); |
||
| 23 | $protected64 = Base64::urlSafeEncode(json_encode($data)); |
||
| 24 | |||
| 25 | openssl_sign( |
||
| 26 | $protected64 . '.' . $payload64, |
||
| 27 | $signed, |
||
| 28 | $privateKey, |
||
| 29 | 'SHA256' |
||
|
|
|||
| 30 | ); |
||
| 31 | |||
| 32 | $signed64 = Base64::urlSafeEncode($signed); |
||
| 33 | |||
| 34 | return [ |
||
| 35 | 'protected' => $protected64, |
||
| 36 | 'payload' => $payload64, |
||
| 37 | 'signature' => $signed64, |
||
| 38 | ]; |
||
| 41 |