GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PublicKey   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 55
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A subjectPublicKeyData() 0 3 1
A fromPEM() 0 10 3
A publicKeyInfo() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\CryptoTypes\Asymmetric;
6
7
use Sop\CryptoEncoding\PEM;
8
use Sop\CryptoTypes\AlgorithmIdentifier\Feature\AlgorithmIdentifierType;
9
10
/**
11
 * Base class for public keys.
12
 */
13
abstract class PublicKey
14
{
15
    /**
16
     * Get the public key algorithm identifier.
17
     *
18
     * @return AlgorithmIdentifierType
19
     */
20
    abstract public function algorithmIdentifier(): AlgorithmIdentifierType;
21
22
    /**
23
     * Get DER encoding of the public key.
24
     *
25
     * @return string
26
     */
27
    abstract public function toDER(): string;
28
29
    /**
30
     * Get the public key data for subjectPublicKey in PublicKeyInfo.
31
     *
32
     * @return string
33
     */
34 3
    public function subjectPublicKeyData(): string
35
    {
36 3
        return $this->toDER();
37
    }
38
39
    /**
40
     * Get the public key as a PublicKeyInfo type.
41
     *
42
     * @return PublicKeyInfo
43
     */
44 7
    public function publicKeyInfo(): PublicKeyInfo
45
    {
46 7
        return PublicKeyInfo::fromPublicKey($this);
47
    }
48
49
    /**
50
     * Initialize public key from PEM.
51
     *
52
     * @param PEM $pem
53
     *
54
     * @throws \UnexpectedValueException
55
     *
56
     * @return PublicKey
57
     */
58 6
    public static function fromPEM(PEM $pem)
59
    {
60 6
        switch ($pem->type()) {
61 6
            case PEM::TYPE_RSA_PUBLIC_KEY:
62 1
                return RSA\RSAPublicKey::fromDER($pem->data());
63 5
            case PEM::TYPE_PUBLIC_KEY:
64 4
                return PublicKeyInfo::fromPEM($pem)->publicKey();
65
        }
66 1
        throw new \UnexpectedValueException(
67 1
            'PEM type ' . $pem->type() . ' is not a valid public key.');
68
    }
69
}
70