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 ( 62af7f...70b15e )
by Joni
04:01
created

RSASSAPKCS1Algorithm::fromPublicKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace JWX\JWS\Algorithm;
4
5
use JWX\JWA\JWA;
6
use JWX\JWK\JWK;
7
use JWX\JWK\RSA\RSAPrivateKeyJWK;
8
use JWX\JWK\RSA\RSAPublicKeyJWK;
9
use JWX\JWT\Header\Header;
10
use JWX\JWT\Parameter\AlgorithmParameter;
11
12
13
/**
14
 * Base class for algorithms implementing signature with PKCS #1.
15
 *
16
 * @link https://tools.ietf.org/html/rfc7518#section-3.3
17
 */
18
abstract class RSASSAPKCS1Algorithm extends OpenSSLSignatureAlgorithm
19
{
20
	/**
21
	 * Mapping from algorithm name to class name.
22
	 *
23
	 * @internal
24
	 *
25
	 * @var array
26
	 */
27
	const MAP_ALGO_TO_CLASS = array(
28
		/* @formatter:off */
29
		JWA::ALGO_RS256 => RS256Algorithm::class,
30
		JWA::ALGO_RS384 => RS384Algorithm::class,
31
		JWA::ALGO_RS512 => RS512Algorithm::class
32
		/* @formatter:on */
33
	);
34
	
35
	/**
36
	 * Constructor
37
	 *
38
	 * @param RSAPublicKeyJWK $pub_key
39
	 * @param RSAPrivateKeyJWK $priv_key
40
	 */
41 10
	protected function __construct(RSAPublicKeyJWK $pub_key, 
42
			RSAPrivateKeyJWK $priv_key = null) {
43 10
		$this->_publicKey = $pub_key;
44 10
		$this->_privateKey = $priv_key;
45 10
	}
46
	
47
	/**
48
	 * Initialize from a public key.
49
	 *
50
	 * @param RSAPublicKeyJWK $jwk
51
	 * @return self
52
	 */
53 2
	public static function fromPublicKey(RSAPublicKeyJWK $jwk) {
54 2
		return new static($jwk);
55
	}
56
	
57
	/**
58
	 * Initialize from a private key.
59
	 *
60
	 * @param RSAPrivateKeyJWK $jwk
61
	 * @return self
62
	 */
63 8
	public static function fromPrivateKey(RSAPrivateKeyJWK $jwk) {
64 8
		return new static($jwk->publicKey(), $jwk);
65
	}
66
	
67
	/**
68
	 *
69
	 * @param JWK $jwk
70
	 * @param Header $header
71
	 * @throws \UnexpectedValueException
72
	 * @return RSASSAPKCS1Algorithm
73
	 */
74 5 View Code Duplication
	public static function fromJWK(JWK $jwk, Header $header) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75 5
		$alg = JWA::deriveAlgorithmName($header, $jwk);
76 5
		if (!array_key_exists($alg, self::MAP_ALGO_TO_CLASS)) {
77 1
			throw new \UnexpectedValueException("Unsupported algorithm '$alg'.");
78
		}
79 4
		$cls = self::MAP_ALGO_TO_CLASS[$alg];
80 4
		if ($jwk->has(...RSAPrivateKeyJWK::MANAGED_PARAMS)) {
81 2
			return $cls::fromPrivateKey(RSAPrivateKeyJWK::fromJWK($jwk));
82
		}
83 2
		return $cls::fromPublicKey(RSAPublicKeyJWK::fromJWK($jwk));
84
	}
85
	
86 1
	public function headerParameters() {
87 1
		return array(AlgorithmParameter::fromAlgorithm($this));
88
	}
89
}
90