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

PrivateKeyJWK::fromPrivateKey()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
nc 3
cc 3
eloc 6
nop 1
crap 3
1
<?php
2
3
namespace JWX\JWK\Asymmetric;
4
5
use CryptoUtil\ASN1\EC\ECPrivateKey;
6
use CryptoUtil\ASN1\PrivateKey;
7
use CryptoUtil\ASN1\PrivateKeyInfo;
8
use CryptoUtil\ASN1\RSA\RSAPrivateKey;
9
use CryptoUtil\PEM\PEM;
10
use JWX\JWK\EC\ECPrivateKeyJWK;
11
use JWX\JWK\JWK;
12
use JWX\JWK\RSA\RSAPrivateKeyJWK;
13
14
15
/**
16
 * Base class for JWK private keys of an asymmetric key pairs.
17
 */
18
abstract class PrivateKeyJWK extends JWK
19
{
20
	/**
21
	 * Get the public key component of the asymmetric key pair.
22
	 *
23
	 * @return PublicKeyJWK
24
	 */
25
	abstract public function publicKey();
26
	
27
	/**
28
	 * Convert private key to PEM.
29
	 *
30
	 * @return PEM
31
	 */
32
	abstract public function toPEM();
33
	
34
	/**
35
	 * Initialize from a PrivateKey object.
36
	 *
37
	 * @param PrivateKey $priv_key Private key
38
	 * @throws \UnexpectedValueException
39
	 * @return self
40
	 */
41 3
	public static function fromPrivateKey(PrivateKey $priv_key) {
42 3
		if ($priv_key instanceof RSAPrivateKey) {
43 1
			return RSAPrivateKeyJWK::fromRSAPrivateKey($priv_key);
44
		}
45 2
		if ($priv_key instanceof ECPrivateKey) {
46 1
			return ECPrivateKeyJWK::fromECPrivateKey($priv_key);
47
		}
48 1
		throw new \UnexpectedValueException("Unsupported private key.");
49
	}
50
	
51
	/**
52
	 * Initialize from a PrivateKeyInfo object.
53
	 *
54
	 * @param PrivateKeyInfo $pki PrivateKeyInfo
55
	 * @return self
56
	 */
57 2
	public static function fromPrivateKeyInfo(PrivateKeyInfo $pki) {
58 2
		return self::fromPrivateKey($pki->privateKey());
59
	}
60
}
61