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

JsonWebKey::thumbprint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 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
}