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.
Passed
Push — master ( c4f121...b9594d )
by Joni
05:22
created
lib/JWX/JWE/KeyAlgorithm/A128KWAlgorithm.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -15,30 +15,30 @@
 block discarded – undo
15 15
  */
16 16
 class A128KWAlgorithm extends AESKWAlgorithm
17 17
 {
18
-    /**
19
-     *
20
-     * {@inheritdoc}
21
-     */
22
-    protected function _kekSize(): int
23
-    {
24
-        return 16;
25
-    }
18
+	/**
19
+	 *
20
+	 * {@inheritdoc}
21
+	 */
22
+	protected function _kekSize(): int
23
+	{
24
+		return 16;
25
+	}
26 26
     
27
-    /**
28
-     *
29
-     * {@inheritdoc}
30
-     */
31
-    protected function _AESKWAlgo(): AESKeyWrapAlgorithm
32
-    {
33
-        return new AESKW128();
34
-    }
27
+	/**
28
+	 *
29
+	 * {@inheritdoc}
30
+	 */
31
+	protected function _AESKWAlgo(): AESKeyWrapAlgorithm
32
+	{
33
+		return new AESKW128();
34
+	}
35 35
     
36
-    /**
37
-     *
38
-     * {@inheritdoc}
39
-     */
40
-    public function algorithmParamValue(): string
41
-    {
42
-        return JWA::ALGO_A128KW;
43
-    }
36
+	/**
37
+	 *
38
+	 * {@inheritdoc}
39
+	 */
40
+	public function algorithmParamValue(): string
41
+	{
42
+		return JWA::ALGO_A128KW;
43
+	}
44 44
 }
Please login to merge, or discard this patch.
lib/JWX/Util/UUIDv4.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -30,32 +30,32 @@  discard block
 block discarded – undo
30 30
  */
31 31
 class UUIDv4
32 32
 {
33
-    /**
34
-     * UUID.
35
-     *
36
-     * @var string $_uuid
37
-     */
38
-    protected $_uuid;
33
+	/**
34
+	 * UUID.
35
+	 *
36
+	 * @var string $_uuid
37
+	 */
38
+	protected $_uuid;
39 39
     
40
-    /**
41
-     * Constructor.
42
-     *
43
-     * @param string $uuid UUIDv4 in canonical hexadecimal format
44
-     */
45
-    public function __construct(string $uuid)
46
-    {
47
-        // @todo Check that UUID is version 4
48
-        $this->_uuid = $uuid;
49
-    }
40
+	/**
41
+	 * Constructor.
42
+	 *
43
+	 * @param string $uuid UUIDv4 in canonical hexadecimal format
44
+	 */
45
+	public function __construct(string $uuid)
46
+	{
47
+		// @todo Check that UUID is version 4
48
+		$this->_uuid = $uuid;
49
+	}
50 50
     
51
-    /**
52
-     * Create new random UUIDv4.
53
-     *
54
-     * @return self
55
-     */
56
-    public static function createRandom(): self
57
-    {
58
-        /*
51
+	/**
52
+	 * Create new random UUIDv4.
53
+	 *
54
+	 * @return self
55
+	 */
56
+	public static function createRandom(): self
57
+	{
58
+		/*
59 59
          1. Set the two most significant bits (bits 6 and 7) of
60 60
          the clock_seq_hi_and_reserved to zero and one, respectively.
61 61
          
@@ -66,38 +66,38 @@  discard block
 block discarded – undo
66 66
          3. Set all the other bits to randomly (or pseudo-randomly)
67 67
          chosen values.
68 68
          */
69
-        $uuid = sprintf("%04x%04x-%04x-%04x-%02x%02x-%04x%04x%04x",
70
-            // time_low
71
-            mt_rand(0, 0xffff), mt_rand(0, 0xffff), 
72
-            // time_mid
73
-            mt_rand(0, 0xffff), 
74
-            // time_hi_and_version
75
-            mt_rand(0, 0x0fff) | 0x4000, 
76
-            // clk_seq_hi_res
77
-            mt_rand(0, 0x3f) | 0x80, 
78
-            // clk_seq_low
79
-            mt_rand(0, 0xff), 
80
-            // node
81
-            mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
82
-        return new self($uuid);
83
-    }
69
+		$uuid = sprintf("%04x%04x-%04x-%04x-%02x%02x-%04x%04x%04x",
70
+			// time_low
71
+			mt_rand(0, 0xffff), mt_rand(0, 0xffff), 
72
+			// time_mid
73
+			mt_rand(0, 0xffff), 
74
+			// time_hi_and_version
75
+			mt_rand(0, 0x0fff) | 0x4000, 
76
+			// clk_seq_hi_res
77
+			mt_rand(0, 0x3f) | 0x80, 
78
+			// clk_seq_low
79
+			mt_rand(0, 0xff), 
80
+			// node
81
+			mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
82
+		return new self($uuid);
83
+	}
84 84
     
85
-    /**
86
-     * Get UUIDv4 in canonical form.
87
-     *
88
-     * @return string
89
-     */
90
-    public function canonical(): string
91
-    {
92
-        return $this->_uuid;
93
-    }
85
+	/**
86
+	 * Get UUIDv4 in canonical form.
87
+	 *
88
+	 * @return string
89
+	 */
90
+	public function canonical(): string
91
+	{
92
+		return $this->_uuid;
93
+	}
94 94
     
95
-    /**
96
-     *
97
-     * @return string
98
-     */
99
-    public function __toString()
100
-    {
101
-        return $this->canonical();
102
-    }
95
+	/**
96
+	 *
97
+	 * @return string
98
+	 */
99
+	public function __toString()
100
+	{
101
+		return $this->canonical();
102
+	}
103 103
 }
Please login to merge, or discard this patch.
lib/JWX/Util/BigInt.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -9,86 +9,86 @@
 block discarded – undo
9 9
  */
10 10
 class BigInt
11 11
 {
12
-    /**
13
-     * Number.
14
-     *
15
-     * @var resource|\GMP $_num
16
-     */
17
-    protected $_num;
12
+	/**
13
+	 * Number.
14
+	 *
15
+	 * @var resource|\GMP $_num
16
+	 */
17
+	protected $_num;
18 18
     
19
-    /**
20
-     * Constructor.
21
-     *
22
-     * @param resource|\GMP $num GMP number
23
-     */
24
-    protected function __construct($num)
25
-    {
26
-        $this->_num = $num;
27
-    }
19
+	/**
20
+	 * Constructor.
21
+	 *
22
+	 * @param resource|\GMP $num GMP number
23
+	 */
24
+	protected function __construct($num)
25
+	{
26
+		$this->_num = $num;
27
+	}
28 28
     
29
-    /**
30
-     * Initialize from a base10 number.
31
-     *
32
-     * @param string|int $number
33
-     * @return self
34
-     */
35
-    public static function fromBase10($number): self
36
-    {
37
-        $num = gmp_init($number, 10);
38
-        return new self($num);
39
-    }
29
+	/**
30
+	 * Initialize from a base10 number.
31
+	 *
32
+	 * @param string|int $number
33
+	 * @return self
34
+	 */
35
+	public static function fromBase10($number): self
36
+	{
37
+		$num = gmp_init($number, 10);
38
+		return new self($num);
39
+	}
40 40
     
41
-    /**
42
-     * Initialize from a base256 number.
43
-     *
44
-     * Base64 number is an octet string of big endian, most significant word
45
-     * first integer.
46
-     *
47
-     * @param string $octets
48
-     * @return self
49
-     */
50
-    public static function fromBase256(string $octets): self
51
-    {
52
-        $num = gmp_import($octets, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
53
-        return new self($num);
54
-    }
41
+	/**
42
+	 * Initialize from a base256 number.
43
+	 *
44
+	 * Base64 number is an octet string of big endian, most significant word
45
+	 * first integer.
46
+	 *
47
+	 * @param string $octets
48
+	 * @return self
49
+	 */
50
+	public static function fromBase256(string $octets): self
51
+	{
52
+		$num = gmp_import($octets, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
53
+		return new self($num);
54
+	}
55 55
     
56
-    /**
57
-     * Convert to base10 string.
58
-     *
59
-     * @return string
60
-     */
61
-    public function base10(): string
62
-    {
63
-        return gmp_strval($this->_num, 10);
64
-    }
56
+	/**
57
+	 * Convert to base10 string.
58
+	 *
59
+	 * @return string
60
+	 */
61
+	public function base10(): string
62
+	{
63
+		return gmp_strval($this->_num, 10);
64
+	}
65 65
     
66
-    /**
67
-     * Convert to base16 string.
68
-     *
69
-     * @return string
70
-     */
71
-    public function base16(): string
72
-    {
73
-        return gmp_strval($this->_num, 16);
74
-    }
66
+	/**
67
+	 * Convert to base16 string.
68
+	 *
69
+	 * @return string
70
+	 */
71
+	public function base16(): string
72
+	{
73
+		return gmp_strval($this->_num, 16);
74
+	}
75 75
     
76
-    /**
77
-     * Convert to base256 string.
78
-     *
79
-     * @return string
80
-     */
81
-    public function base256(): string
82
-    {
83
-        return gmp_export($this->_num, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
84
-    }
76
+	/**
77
+	 * Convert to base256 string.
78
+	 *
79
+	 * @return string
80
+	 */
81
+	public function base256(): string
82
+	{
83
+		return gmp_export($this->_num, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
84
+	}
85 85
     
86
-    /**
87
-     *
88
-     * @return string
89
-     */
90
-    public function __toString()
91
-    {
92
-        return $this->base10();
93
-    }
86
+	/**
87
+	 *
88
+	 * @return string
89
+	 */
90
+	public function __toString()
91
+	{
92
+		return $this->base10();
93
+	}
94 94
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      */
50 50
     public static function fromBase256(string $octets): self
51 51
     {
52
-        $num = gmp_import($octets, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
52
+        $num = gmp_import($octets, 1, GMP_MSW_FIRST|GMP_BIG_ENDIAN);
53 53
         return new self($num);
54 54
     }
55 55
     
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public function base256(): string
82 82
     {
83
-        return gmp_export($this->_num, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
83
+        return gmp_export($this->_num, 1, GMP_MSW_FIRST|GMP_BIG_ENDIAN);
84 84
     }
85 85
     
86 86
     /**
Please login to merge, or discard this patch.
lib/JWX/Util/Base64.php 1 patch
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -9,104 +9,104 @@
 block discarded – undo
9 9
  */
10 10
 class Base64
11 11
 {
12
-    /**
13
-     * Encode a string using base64url variant.
14
-     *
15
-     * @link https://en.wikipedia.org/wiki/Base64#URL_applications
16
-     * @param string $data
17
-     * @return string
18
-     */
19
-    public static function urlEncode(string $data): string
20
-    {
21
-        return strtr(rtrim(self::encode($data), "="), "+/", "-_");
22
-    }
12
+	/**
13
+	 * Encode a string using base64url variant.
14
+	 *
15
+	 * @link https://en.wikipedia.org/wiki/Base64#URL_applications
16
+	 * @param string $data
17
+	 * @return string
18
+	 */
19
+	public static function urlEncode(string $data): string
20
+	{
21
+		return strtr(rtrim(self::encode($data), "="), "+/", "-_");
22
+	}
23 23
     
24
-    /**
25
-     * Decode a string using base64url variant.
26
-     *
27
-     * @link https://en.wikipedia.org/wiki/Base64#URL_applications
28
-     * @param string $data
29
-     * @throws \UnexpectedValueException
30
-     * @return string
31
-     */
32
-    public static function urlDecode(string $data): string
33
-    {
34
-        $data = strtr($data, "-_", "+/");
35
-        switch (strlen($data) % 4) {
36
-            case 0:
37
-                break;
38
-            case 2:
39
-                $data .= "==";
40
-                break;
41
-            case 3:
42
-                $data .= "=";
43
-                break;
44
-            default:
45
-                throw new \UnexpectedValueException(
46
-                    "Malformed base64url encoding.");
47
-        }
48
-        return self::decode($data);
49
-    }
24
+	/**
25
+	 * Decode a string using base64url variant.
26
+	 *
27
+	 * @link https://en.wikipedia.org/wiki/Base64#URL_applications
28
+	 * @param string $data
29
+	 * @throws \UnexpectedValueException
30
+	 * @return string
31
+	 */
32
+	public static function urlDecode(string $data): string
33
+	{
34
+		$data = strtr($data, "-_", "+/");
35
+		switch (strlen($data) % 4) {
36
+			case 0:
37
+				break;
38
+			case 2:
39
+				$data .= "==";
40
+				break;
41
+			case 3:
42
+				$data .= "=";
43
+				break;
44
+			default:
45
+				throw new \UnexpectedValueException(
46
+					"Malformed base64url encoding.");
47
+		}
48
+		return self::decode($data);
49
+	}
50 50
     
51
-    /**
52
-     * Check whether string is validly base64url encoded.
53
-     *
54
-     * @link https://en.wikipedia.org/wiki/Base64#URL_applications
55
-     * @param string $data
56
-     * @return bool
57
-     */
58
-    public static function isValidURLEncoding(string $data): bool
59
-    {
60
-        return preg_match('#^[A-Za-z0-9\-_]*$#', $data) == 1;
61
-    }
51
+	/**
52
+	 * Check whether string is validly base64url encoded.
53
+	 *
54
+	 * @link https://en.wikipedia.org/wiki/Base64#URL_applications
55
+	 * @param string $data
56
+	 * @return bool
57
+	 */
58
+	public static function isValidURLEncoding(string $data): bool
59
+	{
60
+		return preg_match('#^[A-Za-z0-9\-_]*$#', $data) == 1;
61
+	}
62 62
     
63
-    /**
64
-     * Encode a string in base64.
65
-     *
66
-     * @link https://tools.ietf.org/html/rfc4648#section-4
67
-     * @param string $data
68
-     * @throws \RuntimeException If encoding fails
69
-     * @return string
70
-     */
71
-    public static function encode(string $data): string
72
-    {
73
-        $ret = @base64_encode($data);
74
-        if (!is_string($ret)) {
75
-            $err = error_get_last();
76
-            $msg = isset($err) && __FILE__ == $err['file'] ? $err['message'] : null;
77
-            throw new \RuntimeException($msg ?? "base64_encode() failed.");
78
-        }
79
-        return $ret;
80
-    }
63
+	/**
64
+	 * Encode a string in base64.
65
+	 *
66
+	 * @link https://tools.ietf.org/html/rfc4648#section-4
67
+	 * @param string $data
68
+	 * @throws \RuntimeException If encoding fails
69
+	 * @return string
70
+	 */
71
+	public static function encode(string $data): string
72
+	{
73
+		$ret = @base64_encode($data);
74
+		if (!is_string($ret)) {
75
+			$err = error_get_last();
76
+			$msg = isset($err) && __FILE__ == $err['file'] ? $err['message'] : null;
77
+			throw new \RuntimeException($msg ?? "base64_encode() failed.");
78
+		}
79
+		return $ret;
80
+	}
81 81
     
82
-    /**
83
-     * Decode a string from base64 encoding.
84
-     *
85
-     * @link https://tools.ietf.org/html/rfc4648#section-4
86
-     * @param string $data
87
-     * @throws \RuntimeException If decoding fails
88
-     * @return string
89
-     */
90
-    public static function decode(string $data): string
91
-    {
92
-        $ret = base64_decode($data, true);
93
-        if (!is_string($ret)) {
94
-            $err = error_get_last();
95
-            $msg = isset($err) && __FILE__ == $err['file'] ? $err['message'] : null;
96
-            throw new \RuntimeException($msg ?? "base64_decode() failed.");
97
-        }
98
-        return $ret;
99
-    }
82
+	/**
83
+	 * Decode a string from base64 encoding.
84
+	 *
85
+	 * @link https://tools.ietf.org/html/rfc4648#section-4
86
+	 * @param string $data
87
+	 * @throws \RuntimeException If decoding fails
88
+	 * @return string
89
+	 */
90
+	public static function decode(string $data): string
91
+	{
92
+		$ret = base64_decode($data, true);
93
+		if (!is_string($ret)) {
94
+			$err = error_get_last();
95
+			$msg = isset($err) && __FILE__ == $err['file'] ? $err['message'] : null;
96
+			throw new \RuntimeException($msg ?? "base64_decode() failed.");
97
+		}
98
+		return $ret;
99
+	}
100 100
     
101
-    /**
102
-     * Check whether string is validly base64 encoded.
103
-     *
104
-     * @link https://tools.ietf.org/html/rfc4648#section-4
105
-     * @param string $data
106
-     * @return bool
107
-     */
108
-    public static function isValid(string $data): bool
109
-    {
110
-        return preg_match('#^[A-Za-z0-9+/]*={0,2}$#', $data) == 1;
111
-    }
101
+	/**
102
+	 * Check whether string is validly base64 encoded.
103
+	 *
104
+	 * @link https://tools.ietf.org/html/rfc4648#section-4
105
+	 * @param string $data
106
+	 * @return bool
107
+	 */
108
+	public static function isValid(string $data): bool
109
+	{
110
+		return preg_match('#^[A-Za-z0-9+/]*={0,2}$#', $data) == 1;
111
+	}
112 112
 }
Please login to merge, or discard this patch.
lib/JWX/JWK/Asymmetric/PrivateKeyJWK.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -18,46 +18,46 @@
 block discarded – undo
18 18
  */
19 19
 abstract class PrivateKeyJWK extends JWK
20 20
 {
21
-    /**
22
-     * Get the public key component of the asymmetric key pair.
23
-     *
24
-     * @return PublicKeyJWK
25
-     */
26
-    abstract public function publicKey(): PublicKeyJWK;
21
+	/**
22
+	 * Get the public key component of the asymmetric key pair.
23
+	 *
24
+	 * @return PublicKeyJWK
25
+	 */
26
+	abstract public function publicKey(): PublicKeyJWK;
27 27
     
28
-    /**
29
-     * Convert private key to PEM.
30
-     *
31
-     * @return PEM
32
-     */
33
-    abstract public function toPEM(): PEM;
28
+	/**
29
+	 * Convert private key to PEM.
30
+	 *
31
+	 * @return PEM
32
+	 */
33
+	abstract public function toPEM(): PEM;
34 34
     
35
-    /**
36
-     * Initialize from a PrivateKey object.
37
-     *
38
-     * @param PrivateKey $priv_key Private key
39
-     * @throws \UnexpectedValueException
40
-     * @return self
41
-     */
42
-    public static function fromPrivateKey(PrivateKey $priv_key): PrivateKeyJWK
43
-    {
44
-        if ($priv_key instanceof RSAPrivateKey) {
45
-            return RSAPrivateKeyJWK::fromRSAPrivateKey($priv_key);
46
-        }
47
-        if ($priv_key instanceof ECPrivateKey) {
48
-            return ECPrivateKeyJWK::fromECPrivateKey($priv_key);
49
-        }
50
-        throw new \UnexpectedValueException("Unsupported private key.");
51
-    }
35
+	/**
36
+	 * Initialize from a PrivateKey object.
37
+	 *
38
+	 * @param PrivateKey $priv_key Private key
39
+	 * @throws \UnexpectedValueException
40
+	 * @return self
41
+	 */
42
+	public static function fromPrivateKey(PrivateKey $priv_key): PrivateKeyJWK
43
+	{
44
+		if ($priv_key instanceof RSAPrivateKey) {
45
+			return RSAPrivateKeyJWK::fromRSAPrivateKey($priv_key);
46
+		}
47
+		if ($priv_key instanceof ECPrivateKey) {
48
+			return ECPrivateKeyJWK::fromECPrivateKey($priv_key);
49
+		}
50
+		throw new \UnexpectedValueException("Unsupported private key.");
51
+	}
52 52
     
53
-    /**
54
-     * Initialize from a PrivateKeyInfo object.
55
-     *
56
-     * @param PrivateKeyInfo $pki PrivateKeyInfo
57
-     * @return self
58
-     */
59
-    public static function fromPrivateKeyInfo(PrivateKeyInfo $pki): PrivateKeyJWK
60
-    {
61
-        return self::fromPrivateKey($pki->privateKey());
62
-    }
53
+	/**
54
+	 * Initialize from a PrivateKeyInfo object.
55
+	 *
56
+	 * @param PrivateKeyInfo $pki PrivateKeyInfo
57
+	 * @return self
58
+	 */
59
+	public static function fromPrivateKeyInfo(PrivateKeyInfo $pki): PrivateKeyJWK
60
+	{
61
+		return self::fromPrivateKey($pki->privateKey());
62
+	}
63 63
 }
Please login to merge, or discard this patch.
lib/JWX/JWK/Asymmetric/PublicKeyJWK.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -18,39 +18,39 @@
 block discarded – undo
18 18
  */
19 19
 abstract class PublicKeyJWK extends JWK
20 20
 {
21
-    /**
22
-     * Convert public key to PEM.
23
-     *
24
-     * @return PEM
25
-     */
26
-    abstract public function toPEM(): PEM;
21
+	/**
22
+	 * Convert public key to PEM.
23
+	 *
24
+	 * @return PEM
25
+	 */
26
+	abstract public function toPEM(): PEM;
27 27
     
28
-    /**
29
-     * Initialize from a PublicKey object.
30
-     *
31
-     * @param PublicKey $pub_key Public key
32
-     * @throws \UnexpectedValueException
33
-     * @return self
34
-     */
35
-    public static function fromPublicKey(PublicKey $pub_key): PublicKeyJWK
36
-    {
37
-        if ($pub_key instanceof RSAPublicKey) {
38
-            return RSAPublicKeyJWK::fromRSAPublicKey($pub_key);
39
-        }
40
-        if ($pub_key instanceof ECPublicKey) {
41
-            return ECPublicKeyJWK::fromECPublicKey($pub_key);
42
-        }
43
-        throw new \UnexpectedValueException("Unsupported public key.");
44
-    }
28
+	/**
29
+	 * Initialize from a PublicKey object.
30
+	 *
31
+	 * @param PublicKey $pub_key Public key
32
+	 * @throws \UnexpectedValueException
33
+	 * @return self
34
+	 */
35
+	public static function fromPublicKey(PublicKey $pub_key): PublicKeyJWK
36
+	{
37
+		if ($pub_key instanceof RSAPublicKey) {
38
+			return RSAPublicKeyJWK::fromRSAPublicKey($pub_key);
39
+		}
40
+		if ($pub_key instanceof ECPublicKey) {
41
+			return ECPublicKeyJWK::fromECPublicKey($pub_key);
42
+		}
43
+		throw new \UnexpectedValueException("Unsupported public key.");
44
+	}
45 45
     
46
-    /**
47
-     * Initialize from a PublicKeyInfo object.
48
-     *
49
-     * @param PublicKeyInfo $pki Public key info
50
-     * @return self
51
-     */
52
-    public static function fromPublicKeyInfo(PublicKeyInfo $pki): PublicKeyJWK
53
-    {
54
-        return self::fromPublicKey($pki->publicKey());
55
-    }
46
+	/**
47
+	 * Initialize from a PublicKeyInfo object.
48
+	 *
49
+	 * @param PublicKeyInfo $pki Public key info
50
+	 * @return self
51
+	 */
52
+	public static function fromPublicKeyInfo(PublicKeyInfo $pki): PublicKeyJWK
53
+	{
54
+		return self::fromPublicKey($pki->publicKey());
55
+	}
56 56
 }
Please login to merge, or discard this patch.
lib/JWX/JWK/JWKSet.php 1 patch
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -13,227 +13,227 @@
 block discarded – undo
13 13
  */
14 14
 class JWKSet implements \Countable, \IteratorAggregate
15 15
 {
16
-    /**
17
-     * JWK objects.
18
-     *
19
-     * @var JWK[] $_jwks
20
-     */
21
-    protected $_jwks;
22
-    
23
-    /**
24
-     * Additional members.
25
-     *
26
-     * @var array $_additional
27
-     */
28
-    protected $_additional;
29
-    
30
-    /**
31
-     * JWK mappings.
32
-     *
33
-     * @var array
34
-     */
35
-    private $_mappings = array();
36
-    
37
-    /**
38
-     * Constructor.
39
-     *
40
-     * @param JWK ...$jwks
41
-     */
42
-    public function __construct(JWK ...$jwks)
43
-    {
44
-        $this->_jwks = $jwks;
45
-        $this->_additional = array();
46
-    }
47
-    
48
-    /**
49
-     * Reset internal cache variables on clone.
50
-     */
51
-    public function __clone()
52
-    {
53
-        $this->_mappings = array();
54
-    }
55
-    
56
-    /**
57
-     * Initialize from an array representing a JSON object.
58
-     *
59
-     * @param array $members
60
-     * @throws \UnexpectedValueException
61
-     * @return self
62
-     */
63
-    public static function fromArray(array $members): self
64
-    {
65
-        if (!isset($members["keys"]) || !is_array($members["keys"])) {
66
-            throw new \UnexpectedValueException(
67
-                "JWK Set must have a 'keys' member.");
68
-        }
69
-        $jwks = array_map(
70
-            function ($jwkdata) {
71
-                return JWK::fromArray($jwkdata);
72
-            }, $members["keys"]);
73
-        unset($members["keys"]);
74
-        $obj = new self(...$jwks);
75
-        $obj->_additional = $members;
76
-        return $obj;
77
-    }
78
-    
79
-    /**
80
-     * Initialize from a JSON string.
81
-     *
82
-     * @param string $json
83
-     * @throws \UnexpectedValueException
84
-     * @return self
85
-     */
86
-    public static function fromJSON(string $json): self
87
-    {
88
-        $members = json_decode($json, true, 32, JSON_BIGINT_AS_STRING);
89
-        if (!is_array($members)) {
90
-            throw new \UnexpectedValueException("Invalid JSON.");
91
-        }
92
-        return self::fromArray($members);
93
-    }
94
-    
95
-    /**
96
-     * Get self with keys added.
97
-     *
98
-     * @param JWK ...$keys JWK objects
99
-     * @return self
100
-     */
101
-    public function withKeys(JWK ...$keys): self
102
-    {
103
-        $obj = clone $this;
104
-        $obj->_jwks = array_merge($obj->_jwks, $keys);
105
-        return $obj;
106
-    }
107
-    
108
-    /**
109
-     * Get all JWK's in a set.
110
-     *
111
-     * @return JWK[]
112
-     */
113
-    public function keys(): array
114
-    {
115
-        return $this->_jwks;
116
-    }
117
-    
118
-    /**
119
-     * Get the first JWK in the set.
120
-     *
121
-     * @throws \LogicException
122
-     * @return JWK
123
-     */
124
-    public function first(): JWK
125
-    {
126
-        if (!count($this->_jwks)) {
127
-            throw new \LogicException("No keys.");
128
-        }
129
-        return $this->_jwks[0];
130
-    }
131
-    
132
-    /**
133
-     * Get JWK by key ID.
134
-     *
135
-     * @param string $id
136
-     * @return JWK|null Null if not found
137
-     */
138
-    protected function _getKeyByID(string $id)
139
-    {
140
-        $map = $this->_getMapping(JWKParameter::PARAM_KEY_ID);
141
-        return isset($map[$id]) ? $map[$id] : null;
142
-    }
143
-    
144
-    /**
145
-     * Check whether set has a JWK with a given key ID.
146
-     *
147
-     * @param string $id
148
-     * @return bool
149
-     */
150
-    public function hasKeyID(string $id): bool
151
-    {
152
-        return $this->_getKeyByID($id) !== null;
153
-    }
154
-    
155
-    /**
156
-     * Get a JWK by a key ID.
157
-     *
158
-     * @param string $id
159
-     * @throws \LogicException
160
-     * @return JWK
161
-     */
162
-    public function keyByID(string $id): JWK
163
-    {
164
-        $jwk = $this->_getKeyByID($id);
165
-        if (!$jwk) {
166
-            throw new \LogicException("No key ID $id.");
167
-        }
168
-        return $jwk;
169
-    }
170
-    
171
-    /**
172
-     * Get mapping from parameter values of given parameter name to JWK.
173
-     *
174
-     * Later duplicate value shall override earlier JWK.
175
-     *
176
-     * @param string $name Parameter name
177
-     * @return array
178
-     */
179
-    protected function _getMapping(string $name): array
180
-    {
181
-        if (!isset($this->_mappings[$name])) {
182
-            $mapping = array();
183
-            foreach ($this->_jwks as $jwk) {
184
-                if ($jwk->has($name)) {
185
-                    $key = (string) $jwk->get($name)->value();
186
-                    $mapping[$key] = $jwk;
187
-                }
188
-            }
189
-            $this->_mappings[$name] = $mapping;
190
-        }
191
-        return $this->_mappings[$name];
192
-    }
193
-    
194
-    /**
195
-     * Convert to array.
196
-     *
197
-     * @return array
198
-     */
199
-    public function toArray(): array
200
-    {
201
-        $data = $this->_additional;
202
-        $data["keys"] = array_map(
203
-            function (JWK $jwk) {
204
-                return $jwk->toArray();
205
-            }, $this->_jwks);
206
-        return $data;
207
-    }
208
-    
209
-    /**
210
-     * Convert to JSON.
211
-     *
212
-     * @return string
213
-     */
214
-    public function toJSON(): string
215
-    {
216
-        return json_encode((object) $this->toArray(), JSON_UNESCAPED_SLASHES);
217
-    }
218
-    
219
-    /**
220
-     * Get the number of keys.
221
-     *
222
-     * @see \Countable::count()
223
-     */
224
-    public function count(): int
225
-    {
226
-        return count($this->_jwks);
227
-    }
228
-    
229
-    /**
230
-     * Get iterator for JWK objects.
231
-     *
232
-     * @see \IteratorAggregate::getIterator()
233
-     * @return \ArrayIterator
234
-     */
235
-    public function getIterator(): \ArrayIterator
236
-    {
237
-        return new \ArrayIterator($this->_jwks);
238
-    }
16
+	/**
17
+	 * JWK objects.
18
+	 *
19
+	 * @var JWK[] $_jwks
20
+	 */
21
+	protected $_jwks;
22
+    
23
+	/**
24
+	 * Additional members.
25
+	 *
26
+	 * @var array $_additional
27
+	 */
28
+	protected $_additional;
29
+    
30
+	/**
31
+	 * JWK mappings.
32
+	 *
33
+	 * @var array
34
+	 */
35
+	private $_mappings = array();
36
+    
37
+	/**
38
+	 * Constructor.
39
+	 *
40
+	 * @param JWK ...$jwks
41
+	 */
42
+	public function __construct(JWK ...$jwks)
43
+	{
44
+		$this->_jwks = $jwks;
45
+		$this->_additional = array();
46
+	}
47
+    
48
+	/**
49
+	 * Reset internal cache variables on clone.
50
+	 */
51
+	public function __clone()
52
+	{
53
+		$this->_mappings = array();
54
+	}
55
+    
56
+	/**
57
+	 * Initialize from an array representing a JSON object.
58
+	 *
59
+	 * @param array $members
60
+	 * @throws \UnexpectedValueException
61
+	 * @return self
62
+	 */
63
+	public static function fromArray(array $members): self
64
+	{
65
+		if (!isset($members["keys"]) || !is_array($members["keys"])) {
66
+			throw new \UnexpectedValueException(
67
+				"JWK Set must have a 'keys' member.");
68
+		}
69
+		$jwks = array_map(
70
+			function ($jwkdata) {
71
+				return JWK::fromArray($jwkdata);
72
+			}, $members["keys"]);
73
+		unset($members["keys"]);
74
+		$obj = new self(...$jwks);
75
+		$obj->_additional = $members;
76
+		return $obj;
77
+	}
78
+    
79
+	/**
80
+	 * Initialize from a JSON string.
81
+	 *
82
+	 * @param string $json
83
+	 * @throws \UnexpectedValueException
84
+	 * @return self
85
+	 */
86
+	public static function fromJSON(string $json): self
87
+	{
88
+		$members = json_decode($json, true, 32, JSON_BIGINT_AS_STRING);
89
+		if (!is_array($members)) {
90
+			throw new \UnexpectedValueException("Invalid JSON.");
91
+		}
92
+		return self::fromArray($members);
93
+	}
94
+    
95
+	/**
96
+	 * Get self with keys added.
97
+	 *
98
+	 * @param JWK ...$keys JWK objects
99
+	 * @return self
100
+	 */
101
+	public function withKeys(JWK ...$keys): self
102
+	{
103
+		$obj = clone $this;
104
+		$obj->_jwks = array_merge($obj->_jwks, $keys);
105
+		return $obj;
106
+	}
107
+    
108
+	/**
109
+	 * Get all JWK's in a set.
110
+	 *
111
+	 * @return JWK[]
112
+	 */
113
+	public function keys(): array
114
+	{
115
+		return $this->_jwks;
116
+	}
117
+    
118
+	/**
119
+	 * Get the first JWK in the set.
120
+	 *
121
+	 * @throws \LogicException
122
+	 * @return JWK
123
+	 */
124
+	public function first(): JWK
125
+	{
126
+		if (!count($this->_jwks)) {
127
+			throw new \LogicException("No keys.");
128
+		}
129
+		return $this->_jwks[0];
130
+	}
131
+    
132
+	/**
133
+	 * Get JWK by key ID.
134
+	 *
135
+	 * @param string $id
136
+	 * @return JWK|null Null if not found
137
+	 */
138
+	protected function _getKeyByID(string $id)
139
+	{
140
+		$map = $this->_getMapping(JWKParameter::PARAM_KEY_ID);
141
+		return isset($map[$id]) ? $map[$id] : null;
142
+	}
143
+    
144
+	/**
145
+	 * Check whether set has a JWK with a given key ID.
146
+	 *
147
+	 * @param string $id
148
+	 * @return bool
149
+	 */
150
+	public function hasKeyID(string $id): bool
151
+	{
152
+		return $this->_getKeyByID($id) !== null;
153
+	}
154
+    
155
+	/**
156
+	 * Get a JWK by a key ID.
157
+	 *
158
+	 * @param string $id
159
+	 * @throws \LogicException
160
+	 * @return JWK
161
+	 */
162
+	public function keyByID(string $id): JWK
163
+	{
164
+		$jwk = $this->_getKeyByID($id);
165
+		if (!$jwk) {
166
+			throw new \LogicException("No key ID $id.");
167
+		}
168
+		return $jwk;
169
+	}
170
+    
171
+	/**
172
+	 * Get mapping from parameter values of given parameter name to JWK.
173
+	 *
174
+	 * Later duplicate value shall override earlier JWK.
175
+	 *
176
+	 * @param string $name Parameter name
177
+	 * @return array
178
+	 */
179
+	protected function _getMapping(string $name): array
180
+	{
181
+		if (!isset($this->_mappings[$name])) {
182
+			$mapping = array();
183
+			foreach ($this->_jwks as $jwk) {
184
+				if ($jwk->has($name)) {
185
+					$key = (string) $jwk->get($name)->value();
186
+					$mapping[$key] = $jwk;
187
+				}
188
+			}
189
+			$this->_mappings[$name] = $mapping;
190
+		}
191
+		return $this->_mappings[$name];
192
+	}
193
+    
194
+	/**
195
+	 * Convert to array.
196
+	 *
197
+	 * @return array
198
+	 */
199
+	public function toArray(): array
200
+	{
201
+		$data = $this->_additional;
202
+		$data["keys"] = array_map(
203
+			function (JWK $jwk) {
204
+				return $jwk->toArray();
205
+			}, $this->_jwks);
206
+		return $data;
207
+	}
208
+    
209
+	/**
210
+	 * Convert to JSON.
211
+	 *
212
+	 * @return string
213
+	 */
214
+	public function toJSON(): string
215
+	{
216
+		return json_encode((object) $this->toArray(), JSON_UNESCAPED_SLASHES);
217
+	}
218
+    
219
+	/**
220
+	 * Get the number of keys.
221
+	 *
222
+	 * @see \Countable::count()
223
+	 */
224
+	public function count(): int
225
+	{
226
+		return count($this->_jwks);
227
+	}
228
+    
229
+	/**
230
+	 * Get iterator for JWK objects.
231
+	 *
232
+	 * @see \IteratorAggregate::getIterator()
233
+	 * @return \ArrayIterator
234
+	 */
235
+	public function getIterator(): \ArrayIterator
236
+	{
237
+		return new \ArrayIterator($this->_jwks);
238
+	}
239 239
 }
Please login to merge, or discard this patch.
lib/JWX/JWK/JWK.php 1 patch
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -14,187 +14,187 @@
 block discarded – undo
14 14
  */
15 15
 class JWK implements \Countable, \IteratorAggregate
16 16
 {
17
-    use TypedJWK;
17
+	use TypedJWK;
18 18
     
19
-    /**
20
-     * Parameters.
21
-     *
22
-     * @var JWKParameter[] $_parameters
23
-     */
24
-    protected $_parameters;
19
+	/**
20
+	 * Parameters.
21
+	 *
22
+	 * @var JWKParameter[] $_parameters
23
+	 */
24
+	protected $_parameters;
25 25
     
26
-    /**
27
-     * Constructor.
28
-     *
29
-     * @param JWKParameter ...$params
30
-     */
31
-    public function __construct(JWKParameter ...$params)
32
-    {
33
-        $this->_parameters = array();
34
-        foreach ($params as $param) {
35
-            $this->_parameters[$param->name()] = $param;
36
-        }
37
-    }
26
+	/**
27
+	 * Constructor.
28
+	 *
29
+	 * @param JWKParameter ...$params
30
+	 */
31
+	public function __construct(JWKParameter ...$params)
32
+	{
33
+		$this->_parameters = array();
34
+		foreach ($params as $param) {
35
+			$this->_parameters[$param->name()] = $param;
36
+		}
37
+	}
38 38
     
39
-    /**
40
-     * Initialize from an array representing a JSON object.
41
-     *
42
-     * @param array $members
43
-     * @return self
44
-     */
45
-    public static function fromArray(array $members): self
46
-    {
47
-        $params = array();
48
-        foreach ($members as $name => $value) {
49
-            $params[] = JWKParameter::fromNameAndValue($name, $value);
50
-        }
51
-        return new static(...$params);
52
-    }
39
+	/**
40
+	 * Initialize from an array representing a JSON object.
41
+	 *
42
+	 * @param array $members
43
+	 * @return self
44
+	 */
45
+	public static function fromArray(array $members): self
46
+	{
47
+		$params = array();
48
+		foreach ($members as $name => $value) {
49
+			$params[] = JWKParameter::fromNameAndValue($name, $value);
50
+		}
51
+		return new static(...$params);
52
+	}
53 53
     
54
-    /**
55
-     * Initialize from a JSON string.
56
-     *
57
-     * @param string $json
58
-     * @throws \UnexpectedValueException
59
-     * @return self
60
-     */
61
-    public static function fromJSON(string $json): self
62
-    {
63
-        $members = json_decode($json, true, 32, JSON_BIGINT_AS_STRING);
64
-        if (!is_array($members)) {
65
-            throw new \UnexpectedValueException("Invalid JSON.");
66
-        }
67
-        return static::fromArray($members);
68
-    }
54
+	/**
55
+	 * Initialize from a JSON string.
56
+	 *
57
+	 * @param string $json
58
+	 * @throws \UnexpectedValueException
59
+	 * @return self
60
+	 */
61
+	public static function fromJSON(string $json): self
62
+	{
63
+		$members = json_decode($json, true, 32, JSON_BIGINT_AS_STRING);
64
+		if (!is_array($members)) {
65
+			throw new \UnexpectedValueException("Invalid JSON.");
66
+		}
67
+		return static::fromArray($members);
68
+	}
69 69
     
70
-    /**
71
-     * Initialize from another JWK.
72
-     *
73
-     * Allows casting to subclass by late static binding.
74
-     *
75
-     * @param JWK $jwk
76
-     * @return self
77
-     */
78
-    public static function fromJWK(JWK $jwk): self
79
-    {
80
-        return new static(...array_values($jwk->_parameters));
81
-    }
70
+	/**
71
+	 * Initialize from another JWK.
72
+	 *
73
+	 * Allows casting to subclass by late static binding.
74
+	 *
75
+	 * @param JWK $jwk
76
+	 * @return self
77
+	 */
78
+	public static function fromJWK(JWK $jwk): self
79
+	{
80
+		return new static(...array_values($jwk->_parameters));
81
+	}
82 82
     
83
-    /**
84
-     * Get self with parameters added.
85
-     *
86
-     * @param JWKParameter ...$params
87
-     * @return self
88
-     */
89
-    public function withParameters(JWKParameter ...$params): self
90
-    {
91
-        $obj = clone $this;
92
-        foreach ($params as $param) {
93
-            $obj->_parameters[$param->name()] = $param;
94
-        }
95
-        return $obj;
96
-    }
83
+	/**
84
+	 * Get self with parameters added.
85
+	 *
86
+	 * @param JWKParameter ...$params
87
+	 * @return self
88
+	 */
89
+	public function withParameters(JWKParameter ...$params): self
90
+	{
91
+		$obj = clone $this;
92
+		foreach ($params as $param) {
93
+			$obj->_parameters[$param->name()] = $param;
94
+		}
95
+		return $obj;
96
+	}
97 97
     
98
-    /**
99
-     * Get all parameters.
100
-     *
101
-     * @return JWKParameter[]
102
-     */
103
-    public function parameters(): array
104
-    {
105
-        return $this->_parameters;
106
-    }
98
+	/**
99
+	 * Get all parameters.
100
+	 *
101
+	 * @return JWKParameter[]
102
+	 */
103
+	public function parameters(): array
104
+	{
105
+		return $this->_parameters;
106
+	}
107 107
     
108
-    /**
109
-     * Get self with given key ID added to parameters.
110
-     *
111
-     * @param string $id Key ID as a string
112
-     * @return self
113
-     */
114
-    public function withKeyID(string $id): self
115
-    {
116
-        return $this->withParameters(new KeyIDParameter($id));
117
-    }
108
+	/**
109
+	 * Get self with given key ID added to parameters.
110
+	 *
111
+	 * @param string $id Key ID as a string
112
+	 * @return self
113
+	 */
114
+	public function withKeyID(string $id): self
115
+	{
116
+		return $this->withParameters(new KeyIDParameter($id));
117
+	}
118 118
     
119
-    /**
120
-     * Whether parameters are present.
121
-     *
122
-     * Returns false if any of the given parameters is not set.
123
-     *
124
-     * @param string ...$names Parameter names
125
-     * @return bool
126
-     */
127
-    public function has(string ...$names): bool
128
-    {
129
-        foreach ($names as $name) {
130
-            if (!isset($this->_parameters[$name])) {
131
-                return false;
132
-            }
133
-        }
134
-        return true;
135
-    }
119
+	/**
120
+	 * Whether parameters are present.
121
+	 *
122
+	 * Returns false if any of the given parameters is not set.
123
+	 *
124
+	 * @param string ...$names Parameter names
125
+	 * @return bool
126
+	 */
127
+	public function has(string ...$names): bool
128
+	{
129
+		foreach ($names as $name) {
130
+			if (!isset($this->_parameters[$name])) {
131
+				return false;
132
+			}
133
+		}
134
+		return true;
135
+	}
136 136
     
137
-    /**
138
-     * Get a parameter.
139
-     *
140
-     * @param string $name Parameter name
141
-     * @throws \LogicException
142
-     * @return JWKParameter
143
-     */
144
-    public function get(string $name): JWKParameter
145
-    {
146
-        if (!$this->has($name)) {
147
-            throw new \LogicException("Parameter $name doesn't exists.");
148
-        }
149
-        return $this->_parameters[$name];
150
-    }
137
+	/**
138
+	 * Get a parameter.
139
+	 *
140
+	 * @param string $name Parameter name
141
+	 * @throws \LogicException
142
+	 * @return JWKParameter
143
+	 */
144
+	public function get(string $name): JWKParameter
145
+	{
146
+		if (!$this->has($name)) {
147
+			throw new \LogicException("Parameter $name doesn't exists.");
148
+		}
149
+		return $this->_parameters[$name];
150
+	}
151 151
     
152
-    /**
153
-     * Convert to array.
154
-     *
155
-     * @return array Parameter values keyed by parameter names
156
-     */
157
-    public function toArray(): array
158
-    {
159
-        $a = array();
160
-        foreach ($this->_parameters as $param) {
161
-            $a[$param->name()] = $param->value();
162
-        }
163
-        return $a;
164
-    }
152
+	/**
153
+	 * Convert to array.
154
+	 *
155
+	 * @return array Parameter values keyed by parameter names
156
+	 */
157
+	public function toArray(): array
158
+	{
159
+		$a = array();
160
+		foreach ($this->_parameters as $param) {
161
+			$a[$param->name()] = $param->value();
162
+		}
163
+		return $a;
164
+	}
165 165
     
166
-    /**
167
-     * Convert to JSON.
168
-     *
169
-     * @return string
170
-     */
171
-    public function toJSON(): string
172
-    {
173
-        $data = $this->toArray();
174
-        if (empty($data)) {
175
-            return "";
176
-        }
177
-        return json_encode((object) $data, JSON_UNESCAPED_SLASHES);
178
-    }
166
+	/**
167
+	 * Convert to JSON.
168
+	 *
169
+	 * @return string
170
+	 */
171
+	public function toJSON(): string
172
+	{
173
+		$data = $this->toArray();
174
+		if (empty($data)) {
175
+			return "";
176
+		}
177
+		return json_encode((object) $data, JSON_UNESCAPED_SLASHES);
178
+	}
179 179
     
180
-    /**
181
-     * Get the number of parameters.
182
-     *
183
-     * @see \Countable::count()
184
-     */
185
-    public function count(): int
186
-    {
187
-        return count($this->_parameters);
188
-    }
180
+	/**
181
+	 * Get the number of parameters.
182
+	 *
183
+	 * @see \Countable::count()
184
+	 */
185
+	public function count(): int
186
+	{
187
+		return count($this->_parameters);
188
+	}
189 189
     
190
-    /**
191
-     * Get iterator for the parameters.
192
-     *
193
-     * @see \IteratorAggregate::getIterator()
194
-     * @return \ArrayIterator
195
-     */
196
-    public function getIterator(): \ArrayIterator
197
-    {
198
-        return new \ArrayIterator($this->_parameters);
199
-    }
190
+	/**
191
+	 * Get iterator for the parameters.
192
+	 *
193
+	 * @see \IteratorAggregate::getIterator()
194
+	 * @return \ArrayIterator
195
+	 */
196
+	public function getIterator(): \ArrayIterator
197
+	{
198
+		return new \ArrayIterator($this->_parameters);
199
+	}
200 200
 }
Please login to merge, or discard this patch.
lib/JWX/JWK/RSA/RSAPrivateKeyJWK.php 1 patch
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -29,126 +29,126 @@
 block discarded – undo
29 29
  */
30 30
 class RSAPrivateKeyJWK extends PrivateKeyJWK
31 31
 {
32
-    /**
33
-     * Parameter names managed by this class.
34
-     *
35
-     * @internal
36
-     *
37
-     * @var string[]
38
-     */
39
-    const MANAGED_PARAMS = array(
40
-        /* @formatter:off */
41
-        JWKParameter::PARAM_KEY_TYPE,
42
-        JWKParameter::PARAM_MODULUS,
43
-        JWKParameter::PARAM_EXPONENT,
44
-        JWKParameter::PARAM_PRIVATE_EXPONENT,
45
-        JWKParameter::PARAM_FIRST_PRIME_FACTOR,
46
-        JWKParameter::PARAM_SECOND_PRIME_FACTOR,
47
-        JWKParameter::PARAM_FIRST_FACTOR_CRT_EXPONENT,
48
-        JWKParameter::PARAM_SECOND_FACTOR_CRT_EXPONENT,
49
-        JWKParameter::PARAM_FIRST_CRT_COEFFICIENT
50
-        /* @formatter:on */
51
-    );
32
+	/**
33
+	 * Parameter names managed by this class.
34
+	 *
35
+	 * @internal
36
+	 *
37
+	 * @var string[]
38
+	 */
39
+	const MANAGED_PARAMS = array(
40
+		/* @formatter:off */
41
+		JWKParameter::PARAM_KEY_TYPE,
42
+		JWKParameter::PARAM_MODULUS,
43
+		JWKParameter::PARAM_EXPONENT,
44
+		JWKParameter::PARAM_PRIVATE_EXPONENT,
45
+		JWKParameter::PARAM_FIRST_PRIME_FACTOR,
46
+		JWKParameter::PARAM_SECOND_PRIME_FACTOR,
47
+		JWKParameter::PARAM_FIRST_FACTOR_CRT_EXPONENT,
48
+		JWKParameter::PARAM_SECOND_FACTOR_CRT_EXPONENT,
49
+		JWKParameter::PARAM_FIRST_CRT_COEFFICIENT
50
+		/* @formatter:on */
51
+	);
52 52
     
53
-    /**
54
-     * Constructor.
55
-     *
56
-     * @param JWKParameter ...$params
57
-     * @throws \UnexpectedValueException If missing required parameter
58
-     */
59
-    public function __construct(JWKParameter ...$params)
60
-    {
61
-        parent::__construct(...$params);
62
-        foreach (self::MANAGED_PARAMS as $name) {
63
-            if (!$this->has($name)) {
64
-                throw new \UnexpectedValueException("Missing '$name' parameter.");
65
-            }
66
-        }
67
-        if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_RSA) {
68
-            throw new \UnexpectedValueException("Invalid key type.");
69
-        }
70
-        // cast private exponent to correct class
71
-        $key = JWKParameter::PARAM_PRIVATE_EXPONENT;
72
-        $this->_parameters[$key] = new PrivateExponentParameter(
73
-            $this->_parameters[$key]->value());
74
-    }
53
+	/**
54
+	 * Constructor.
55
+	 *
56
+	 * @param JWKParameter ...$params
57
+	 * @throws \UnexpectedValueException If missing required parameter
58
+	 */
59
+	public function __construct(JWKParameter ...$params)
60
+	{
61
+		parent::__construct(...$params);
62
+		foreach (self::MANAGED_PARAMS as $name) {
63
+			if (!$this->has($name)) {
64
+				throw new \UnexpectedValueException("Missing '$name' parameter.");
65
+			}
66
+		}
67
+		if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_RSA) {
68
+			throw new \UnexpectedValueException("Invalid key type.");
69
+		}
70
+		// cast private exponent to correct class
71
+		$key = JWKParameter::PARAM_PRIVATE_EXPONENT;
72
+		$this->_parameters[$key] = new PrivateExponentParameter(
73
+			$this->_parameters[$key]->value());
74
+	}
75 75
     
76
-    /**
77
-     * Initialize from RSAPrivateKey.
78
-     *
79
-     * @param RSAPrivateKey $pk
80
-     * @return self
81
-     */
82
-    public static function fromRSAPrivateKey(RSAPrivateKey $pk): self
83
-    {
84
-        $n = ModulusParameter::fromNumber($pk->modulus());
85
-        $e = ExponentParameter::fromNumber($pk->publicExponent());
86
-        $d = PrivateExponentParameter::fromNumber($pk->privateExponent());
87
-        $p = FirstPrimeFactorParameter::fromNumber($pk->prime1());
88
-        $q = SecondPrimeFactorParameter::fromNumber($pk->prime2());
89
-        $dp = FirstFactorCRTExponentParameter::fromNumber($pk->exponent1());
90
-        $dq = SecondFactorCRTExponentParameter::fromNumber($pk->exponent2());
91
-        $qi = FirstCRTCoefficientParameter::fromNumber($pk->coefficient());
92
-        $key_type = new KeyTypeParameter(KeyTypeParameter::TYPE_RSA);
93
-        return new self($key_type, $n, $e, $d, $p, $q, $dp, $dq, $qi);
94
-    }
76
+	/**
77
+	 * Initialize from RSAPrivateKey.
78
+	 *
79
+	 * @param RSAPrivateKey $pk
80
+	 * @return self
81
+	 */
82
+	public static function fromRSAPrivateKey(RSAPrivateKey $pk): self
83
+	{
84
+		$n = ModulusParameter::fromNumber($pk->modulus());
85
+		$e = ExponentParameter::fromNumber($pk->publicExponent());
86
+		$d = PrivateExponentParameter::fromNumber($pk->privateExponent());
87
+		$p = FirstPrimeFactorParameter::fromNumber($pk->prime1());
88
+		$q = SecondPrimeFactorParameter::fromNumber($pk->prime2());
89
+		$dp = FirstFactorCRTExponentParameter::fromNumber($pk->exponent1());
90
+		$dq = SecondFactorCRTExponentParameter::fromNumber($pk->exponent2());
91
+		$qi = FirstCRTCoefficientParameter::fromNumber($pk->coefficient());
92
+		$key_type = new KeyTypeParameter(KeyTypeParameter::TYPE_RSA);
93
+		return new self($key_type, $n, $e, $d, $p, $q, $dp, $dq, $qi);
94
+	}
95 95
     
96
-    /**
97
-     * Initialize from PEM.
98
-     *
99
-     * @param PEM $pem
100
-     * @return self
101
-     */
102
-    public static function fromPEM(PEM $pem): self
103
-    {
104
-        return self::fromRSAPrivateKey(RSAPrivateKey::fromPEM($pem));
105
-    }
96
+	/**
97
+	 * Initialize from PEM.
98
+	 *
99
+	 * @param PEM $pem
100
+	 * @return self
101
+	 */
102
+	public static function fromPEM(PEM $pem): self
103
+	{
104
+		return self::fromRSAPrivateKey(RSAPrivateKey::fromPEM($pem));
105
+	}
106 106
     
107
-    /**
108
-     * Get public key component.
109
-     *
110
-     * @return RSAPublicKeyJWK
111
-     */
112
-    public function publicKey(): PublicKeyJWK
113
-    {
114
-        $kty = $this->keyTypeParameter();
115
-        $n = $this->modulusParameter();
116
-        $e = $this->exponentParameter();
117
-        return new RSAPublicKeyJWK($kty, $n, $e);
118
-    }
107
+	/**
108
+	 * Get public key component.
109
+	 *
110
+	 * @return RSAPublicKeyJWK
111
+	 */
112
+	public function publicKey(): PublicKeyJWK
113
+	{
114
+		$kty = $this->keyTypeParameter();
115
+		$n = $this->modulusParameter();
116
+		$e = $this->exponentParameter();
117
+		return new RSAPublicKeyJWK($kty, $n, $e);
118
+	}
119 119
     
120
-    /**
121
-     * Convert JWK to PEM.
122
-     *
123
-     * @return PEM
124
-     */
125
-    public function toPEM(): PEM
126
-    {
127
-        $n = $this->modulusParameter()
128
-            ->number()
129
-            ->base10();
130
-        $e = $this->exponentParameter()
131
-            ->number()
132
-            ->base10();
133
-        $d = $this->privateExponentParameter()
134
-            ->number()
135
-            ->base10();
136
-        $p = $this->firstPrimeFactorParameter()
137
-            ->number()
138
-            ->base10();
139
-        $q = $this->secondPrimeFactorParameter()
140
-            ->number()
141
-            ->base10();
142
-        $dp = $this->firstFactorCRTExponentParameter()
143
-            ->number()
144
-            ->base10();
145
-        $dq = $this->secondFactorCRTExponentParameter()
146
-            ->number()
147
-            ->base10();
148
-        $qi = $this->firstCRTCoefficientParameter()
149
-            ->number()
150
-            ->base10();
151
-        $pk = new RSAPrivateKey($n, $e, $d, $p, $q, $dp, $dq, $qi);
152
-        return PrivateKeyInfo::fromPrivateKey($pk)->toPEM();
153
-    }
120
+	/**
121
+	 * Convert JWK to PEM.
122
+	 *
123
+	 * @return PEM
124
+	 */
125
+	public function toPEM(): PEM
126
+	{
127
+		$n = $this->modulusParameter()
128
+			->number()
129
+			->base10();
130
+		$e = $this->exponentParameter()
131
+			->number()
132
+			->base10();
133
+		$d = $this->privateExponentParameter()
134
+			->number()
135
+			->base10();
136
+		$p = $this->firstPrimeFactorParameter()
137
+			->number()
138
+			->base10();
139
+		$q = $this->secondPrimeFactorParameter()
140
+			->number()
141
+			->base10();
142
+		$dp = $this->firstFactorCRTExponentParameter()
143
+			->number()
144
+			->base10();
145
+		$dq = $this->secondFactorCRTExponentParameter()
146
+			->number()
147
+			->base10();
148
+		$qi = $this->firstCRTCoefficientParameter()
149
+			->number()
150
+			->base10();
151
+		$pk = new RSAPrivateKey($n, $e, $d, $p, $q, $dp, $dq, $qi);
152
+		return PrivateKeyInfo::fromPrivateKey($pk)->toPEM();
153
+	}
154 154
 }
Please login to merge, or discard this patch.