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