JsonWebKey   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compute() 0 15 2
A thumbprint() 0 3 1
1
<?php
2
3
namespace Rogierw\RwAcme\Support;
4
5
use Rogierw\RwAcme\Exceptions\LetsEncryptClientException;
6
7
class JsonWebKey
8
{
9
    public static function compute(
10
        #[\SensitiveParameter] string $accountKey
11
    ): array {
12
        $privateKey = openssl_pkey_get_private($accountKey);
13
14
        if ($privateKey === false) {
15
            throw new LetsEncryptClientException('Can not create private key.');
16
        }
17
18
        $details = openssl_pkey_get_details($privateKey);
19
20
        return [
21
            'e' => Base64::urlSafeEncode($details['rsa']['e']),
22
            'kty' => 'RSA',
23
            'n' => Base64::urlSafeEncode($details['rsa']['n']),
24
        ];
25
    }
26
27
    public static function thumbprint(array $jwk): string
28
    {
29
        return Base64::urlSafeEncode(hash('sha256', json_encode($jwk, JSON_THROW_ON_ERROR), true));
30
    }
31
}
32