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