Passed
Push — master ( d0e289...84c60d )
by Rogier
02:10
created

JsonWebKey   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 8
dl 0
loc 18
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compute() 0 10 1
A thumbprint() 0 3 1
1
<?php
2
3
namespace Rogierw\RwAcme\Support;
4
5
class JsonWebKey
6
{
7
    public static function compute(string $accountKey): array
8
    {
9
        $privateKey = openssl_pkey_get_private($accountKey);
10
11
        $details = openssl_pkey_get_details($privateKey);
0 ignored issues
show
Bug introduced by
It seems like $privateKey can also be of type false; however, parameter $key of openssl_pkey_get_details() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

11
        $details = openssl_pkey_get_details(/** @scrutinizer ignore-type */ $privateKey);
Loading history...
12
13
        return [
14
            'e'   => Base64::urlSafeEncode($details['rsa']['e']),
15
            'kty' => 'RSA',
16
            'n'   => Base64::urlSafeEncode($details['rsa']['n']),
17
        ];
18
    }
19
20
    public static function thumbprint(array $jwk): string
21
    {
22
        return Base64::urlSafeEncode(hash('sha256', json_encode($jwk), true));
23
    }
24
}