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.
Completed
Push — master ( b929ce...584c7d )
by Joni
08:37
created

PublicKeyJWK   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 36
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
toPEM() 0 1 ?
A fromPublicKey() 0 9 3
A fromPublicKeyInfo() 0 3 1
1
<?php
2
3
namespace JWX\JWK\Asymmetric;
4
5
use CryptoUtil\ASN1\EC\ECPublicKey;
6
use CryptoUtil\ASN1\PublicKey;
7
use CryptoUtil\ASN1\PublicKeyInfo;
8
use CryptoUtil\ASN1\RSA\RSAPublicKey;
9
use CryptoUtil\PEM\PEM;
10
use JWX\JWK\EC\ECPublicKeyJWK;
11
use JWX\JWK\JWK;
12
use JWX\JWK\RSA\RSAPublicKeyJWK;
13
14
15
/**
16
 * Base class for JWK public keys of an asymmetric key pairs.
17
 */
18
abstract class PublicKeyJWK extends JWK
19
{
20
	/**
21
	 * Convert public key to PEM.
22
	 *
23
	 * @return PEM
24
	 */
25
	abstract public function toPEM();
26
	
27
	/**
28
	 * Initialize from a PublicKey object.
29
	 *
30
	 * @param PublicKey $pub_key Public key
31
	 * @throws \UnexpectedValueException
32
	 * @return self
33
	 */
34 3
	public static function fromPublicKey(PublicKey $pub_key) {
35 3
		if ($pub_key instanceof RSAPublicKey) {
36 1
			return RSAPublicKeyJWK::fromRSAPublicKey($pub_key);
37
		}
38 2
		if ($pub_key instanceof ECPublicKey) {
39 1
			return ECPublicKeyJWK::fromECPublicKey($pub_key);
40
		}
41 1
		throw new \UnexpectedValueException("Unsupported public key.");
42
	}
43
	
44
	/**
45
	 * Initialize from a PublicKeyInfo object.
46
	 *
47
	 * @param PublicKeyInfo $pki Public key info
48
	 * @return self
49
	 */
50 2
	public static function fromPublicKeyInfo(PublicKeyInfo $pki) {
51 2
		return self::fromPublicKey($pki->publicKey());
52
	}
53
}
54