@@ -15,60 +15,60 @@ |
||
15 | 15 | */ |
16 | 16 | class SymmetricKeyJWK extends JWK |
17 | 17 | { |
18 | - /** |
|
19 | - * Parameter names managed by this class. |
|
20 | - * |
|
21 | - * @internal |
|
22 | - * |
|
23 | - * @var string[] |
|
24 | - */ |
|
25 | - const MANAGED_PARAMS = array( |
|
26 | - /* @formatter:off */ |
|
27 | - JWKParameter::PARAM_KEY_TYPE, |
|
28 | - JWKParameter::PARAM_KEY_VALUE |
|
29 | - /* @formatter:on */ |
|
30 | - ); |
|
18 | + /** |
|
19 | + * Parameter names managed by this class. |
|
20 | + * |
|
21 | + * @internal |
|
22 | + * |
|
23 | + * @var string[] |
|
24 | + */ |
|
25 | + const MANAGED_PARAMS = array( |
|
26 | + /* @formatter:off */ |
|
27 | + JWKParameter::PARAM_KEY_TYPE, |
|
28 | + JWKParameter::PARAM_KEY_VALUE |
|
29 | + /* @formatter:on */ |
|
30 | + ); |
|
31 | 31 | |
32 | - /** |
|
33 | - * Constructor. |
|
34 | - * |
|
35 | - * @param JWKParameter ...$params |
|
36 | - * @throws \UnexpectedValueException If missing required parameter |
|
37 | - */ |
|
38 | - public function __construct(JWKParameter ...$params) |
|
39 | - { |
|
40 | - parent::__construct(...$params); |
|
41 | - foreach (self::MANAGED_PARAMS as $name) { |
|
42 | - if (!$this->has($name)) { |
|
43 | - throw new \UnexpectedValueException("Missing '$name' parameter."); |
|
44 | - } |
|
45 | - } |
|
46 | - if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_OCT) { |
|
47 | - throw new \UnexpectedValueException("Invalid key type."); |
|
48 | - } |
|
49 | - } |
|
32 | + /** |
|
33 | + * Constructor. |
|
34 | + * |
|
35 | + * @param JWKParameter ...$params |
|
36 | + * @throws \UnexpectedValueException If missing required parameter |
|
37 | + */ |
|
38 | + public function __construct(JWKParameter ...$params) |
|
39 | + { |
|
40 | + parent::__construct(...$params); |
|
41 | + foreach (self::MANAGED_PARAMS as $name) { |
|
42 | + if (!$this->has($name)) { |
|
43 | + throw new \UnexpectedValueException("Missing '$name' parameter."); |
|
44 | + } |
|
45 | + } |
|
46 | + if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_OCT) { |
|
47 | + throw new \UnexpectedValueException("Invalid key type."); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Initialize from a key string. |
|
53 | - * |
|
54 | - * @param string $key Symmetric key |
|
55 | - * @param JWKParameter ...$params Optional additional parameters |
|
56 | - * @return self |
|
57 | - */ |
|
58 | - public static function fromKey($key, JWKParameter ...$params) |
|
59 | - { |
|
60 | - $params[] = new KeyTypeParameter(KeyTypeParameter::TYPE_OCT); |
|
61 | - $params[] = KeyValueParameter::fromString($key); |
|
62 | - return new self(...$params); |
|
63 | - } |
|
51 | + /** |
|
52 | + * Initialize from a key string. |
|
53 | + * |
|
54 | + * @param string $key Symmetric key |
|
55 | + * @param JWKParameter ...$params Optional additional parameters |
|
56 | + * @return self |
|
57 | + */ |
|
58 | + public static function fromKey($key, JWKParameter ...$params) |
|
59 | + { |
|
60 | + $params[] = new KeyTypeParameter(KeyTypeParameter::TYPE_OCT); |
|
61 | + $params[] = KeyValueParameter::fromString($key); |
|
62 | + return new self(...$params); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Get the symmetric key. |
|
67 | - * |
|
68 | - * @return string |
|
69 | - */ |
|
70 | - public function key() |
|
71 | - { |
|
72 | - return Base64::urlDecode($this->keyValueParameter()->value()); |
|
73 | - } |
|
65 | + /** |
|
66 | + * Get the symmetric key. |
|
67 | + * |
|
68 | + * @return string |
|
69 | + */ |
|
70 | + public function key() |
|
71 | + { |
|
72 | + return Base64::urlDecode($this->keyValueParameter()->value()); |
|
73 | + } |
|
74 | 74 | } |
@@ -11,17 +11,17 @@ |
||
11 | 11 | */ |
12 | 12 | class X509CertificateSHA1ThumbprintParameter extends JWKParameter |
13 | 13 | { |
14 | - use Base64URLValue; |
|
14 | + use Base64URLValue; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Constructor. |
|
18 | - * |
|
19 | - * @param string $thumbprint Base64url encoded SHA-1 hash |
|
20 | - */ |
|
21 | - public function __construct($thumbprint) |
|
22 | - { |
|
23 | - $this->_validateEncoding($thumbprint); |
|
24 | - parent::__construct(self::PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT, |
|
25 | - (string) $thumbprint); |
|
26 | - } |
|
16 | + /** |
|
17 | + * Constructor. |
|
18 | + * |
|
19 | + * @param string $thumbprint Base64url encoded SHA-1 hash |
|
20 | + */ |
|
21 | + public function __construct($thumbprint) |
|
22 | + { |
|
23 | + $this->_validateEncoding($thumbprint); |
|
24 | + parent::__construct(self::PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT, |
|
25 | + (string) $thumbprint); |
|
26 | + } |
|
27 | 27 | } |
@@ -11,26 +11,26 @@ |
||
11 | 11 | */ |
12 | 12 | class ECCPrivateKeyParameter extends JWKParameter |
13 | 13 | { |
14 | - use Base64URLValue; |
|
14 | + use Base64URLValue; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Constructor. |
|
18 | - * |
|
19 | - * @param string $key Private key in base64url encoding |
|
20 | - */ |
|
21 | - public function __construct($key) |
|
22 | - { |
|
23 | - $this->_validateEncoding($key); |
|
24 | - parent::__construct(self::PARAM_ECC_PRIVATE_KEY, $key); |
|
25 | - } |
|
16 | + /** |
|
17 | + * Constructor. |
|
18 | + * |
|
19 | + * @param string $key Private key in base64url encoding |
|
20 | + */ |
|
21 | + public function __construct($key) |
|
22 | + { |
|
23 | + $this->_validateEncoding($key); |
|
24 | + parent::__construct(self::PARAM_ECC_PRIVATE_KEY, $key); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Get the EC private key in octet string representation. |
|
29 | - * |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function privateKeyOctets() |
|
33 | - { |
|
34 | - return $this->string(); |
|
35 | - } |
|
27 | + /** |
|
28 | + * Get the EC private key in octet string representation. |
|
29 | + * |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function privateKeyOctets() |
|
33 | + { |
|
34 | + return $this->string(); |
|
35 | + } |
|
36 | 36 | } |
@@ -11,24 +11,24 @@ |
||
11 | 11 | */ |
12 | 12 | class KeyOperationsParameter extends JWKParameter |
13 | 13 | { |
14 | - use ArrayParameterValue; |
|
14 | + use ArrayParameterValue; |
|
15 | 15 | |
16 | - const OP_SIGN = "sign"; |
|
17 | - const OP_VERIFY = "verify"; |
|
18 | - const OP_ENCRYPT = "encrypt"; |
|
19 | - const OP_DECRYPT = "decrypt"; |
|
20 | - const OP_WRAP_KEY = "wrapKey"; |
|
21 | - const OP_UNWRAP_KEY = "unwrapKey"; |
|
22 | - const OP_DERIVE_KEY = "deriveKey"; |
|
23 | - const OP_DERIVE_BITS = "deriveBits"; |
|
16 | + const OP_SIGN = "sign"; |
|
17 | + const OP_VERIFY = "verify"; |
|
18 | + const OP_ENCRYPT = "encrypt"; |
|
19 | + const OP_DECRYPT = "decrypt"; |
|
20 | + const OP_WRAP_KEY = "wrapKey"; |
|
21 | + const OP_UNWRAP_KEY = "unwrapKey"; |
|
22 | + const OP_DERIVE_KEY = "deriveKey"; |
|
23 | + const OP_DERIVE_BITS = "deriveBits"; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Constructor. |
|
27 | - * |
|
28 | - * @param string ...$ops Key operations |
|
29 | - */ |
|
30 | - public function __construct(...$ops) |
|
31 | - { |
|
32 | - parent::__construct(self::PARAM_KEY_OPERATIONS, $ops); |
|
33 | - } |
|
25 | + /** |
|
26 | + * Constructor. |
|
27 | + * |
|
28 | + * @param string ...$ops Key operations |
|
29 | + */ |
|
30 | + public function __construct(...$ops) |
|
31 | + { |
|
32 | + parent::__construct(self::PARAM_KEY_OPERATIONS, $ops); |
|
33 | + } |
|
34 | 34 | } |
@@ -11,18 +11,18 @@ |
||
11 | 11 | */ |
12 | 12 | class PublicKeyUseParameter extends JWKParameter |
13 | 13 | { |
14 | - use StringParameterValue; |
|
14 | + use StringParameterValue; |
|
15 | 15 | |
16 | - const USE_SIGNATURE = "sig"; |
|
17 | - const USE_ENCRYPTION = "enc"; |
|
16 | + const USE_SIGNATURE = "sig"; |
|
17 | + const USE_ENCRYPTION = "enc"; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Constructor. |
|
21 | - * |
|
22 | - * @param string $use Intended use of the public key |
|
23 | - */ |
|
24 | - public function __construct($use) |
|
25 | - { |
|
26 | - parent::__construct(self::PARAM_PUBLIC_KEY_USE, $use); |
|
27 | - } |
|
19 | + /** |
|
20 | + * Constructor. |
|
21 | + * |
|
22 | + * @param string $use Intended use of the public key |
|
23 | + */ |
|
24 | + public function __construct($use) |
|
25 | + { |
|
26 | + parent::__construct(self::PARAM_PUBLIC_KEY_USE, $use); |
|
27 | + } |
|
28 | 28 | } |
@@ -11,116 +11,116 @@ |
||
11 | 11 | */ |
12 | 12 | class CurveParameter extends JWKParameter |
13 | 13 | { |
14 | - use StringParameterValue; |
|
14 | + use StringParameterValue; |
|
15 | 15 | |
16 | - /** |
|
17 | - * P-256 Curve. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - const CURVE_P256 = "P-256"; |
|
16 | + /** |
|
17 | + * P-256 Curve. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + const CURVE_P256 = "P-256"; |
|
22 | 22 | |
23 | - /** |
|
24 | - * P-384 Curve. |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - const CURVE_P384 = "P-384"; |
|
23 | + /** |
|
24 | + * P-384 Curve. |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + const CURVE_P384 = "P-384"; |
|
29 | 29 | |
30 | - /** |
|
31 | - * P-521 Curve. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - const CURVE_P521 = "P-521"; |
|
30 | + /** |
|
31 | + * P-521 Curve. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + const CURVE_P521 = "P-521"; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Mapping from curve OID to curve name. |
|
39 | - * |
|
40 | - * @internal |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - const MAP_OID_TO_CURVE = array( |
|
45 | - /* @formatter:off */ |
|
46 | - "1.2.840.10045.3.1.7" => self::CURVE_P256, |
|
47 | - "1.3.132.0.34" => self::CURVE_P384, |
|
48 | - "1.3.132.0.35" => self::CURVE_P521 |
|
49 | - /* @formatter:on */ |
|
50 | - ); |
|
37 | + /** |
|
38 | + * Mapping from curve OID to curve name. |
|
39 | + * |
|
40 | + * @internal |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + const MAP_OID_TO_CURVE = array( |
|
45 | + /* @formatter:off */ |
|
46 | + "1.2.840.10045.3.1.7" => self::CURVE_P256, |
|
47 | + "1.3.132.0.34" => self::CURVE_P384, |
|
48 | + "1.3.132.0.35" => self::CURVE_P521 |
|
49 | + /* @formatter:on */ |
|
50 | + ); |
|
51 | 51 | |
52 | - /** |
|
53 | - * Mapping from curve name to bit size. |
|
54 | - * |
|
55 | - * @internal |
|
56 | - * |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - const MAP_CURVE_TO_SIZE = array( |
|
60 | - /* @formatter:off */ |
|
61 | - self::CURVE_P256 => 256, |
|
62 | - self::CURVE_P384 => 384, |
|
63 | - self::CURVE_P521 => 521 |
|
64 | - /* @formatter:on */ |
|
65 | - ); |
|
52 | + /** |
|
53 | + * Mapping from curve name to bit size. |
|
54 | + * |
|
55 | + * @internal |
|
56 | + * |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + const MAP_CURVE_TO_SIZE = array( |
|
60 | + /* @formatter:off */ |
|
61 | + self::CURVE_P256 => 256, |
|
62 | + self::CURVE_P384 => 384, |
|
63 | + self::CURVE_P521 => 521 |
|
64 | + /* @formatter:on */ |
|
65 | + ); |
|
66 | 66 | |
67 | - /** |
|
68 | - * Constructor. |
|
69 | - * |
|
70 | - * @param string $curve Curve name |
|
71 | - */ |
|
72 | - public function __construct($curve) |
|
73 | - { |
|
74 | - parent::__construct(self::PARAM_CURVE, $curve); |
|
75 | - } |
|
67 | + /** |
|
68 | + * Constructor. |
|
69 | + * |
|
70 | + * @param string $curve Curve name |
|
71 | + */ |
|
72 | + public function __construct($curve) |
|
73 | + { |
|
74 | + parent::__construct(self::PARAM_CURVE, $curve); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Initialize from curve OID. |
|
79 | - * |
|
80 | - * @param string $oid Object identifier in dotted format |
|
81 | - * @throws \UnexpectedValueException If the curve is not supported |
|
82 | - * @return self |
|
83 | - */ |
|
84 | - public static function fromOID($oid) |
|
85 | - { |
|
86 | - if (!array_key_exists($oid, self::MAP_OID_TO_CURVE)) { |
|
87 | - throw new \UnexpectedValueException("OID $oid not supported."); |
|
88 | - } |
|
89 | - $curve = self::MAP_OID_TO_CURVE[$oid]; |
|
90 | - return new self($curve); |
|
91 | - } |
|
77 | + /** |
|
78 | + * Initialize from curve OID. |
|
79 | + * |
|
80 | + * @param string $oid Object identifier in dotted format |
|
81 | + * @throws \UnexpectedValueException If the curve is not supported |
|
82 | + * @return self |
|
83 | + */ |
|
84 | + public static function fromOID($oid) |
|
85 | + { |
|
86 | + if (!array_key_exists($oid, self::MAP_OID_TO_CURVE)) { |
|
87 | + throw new \UnexpectedValueException("OID $oid not supported."); |
|
88 | + } |
|
89 | + $curve = self::MAP_OID_TO_CURVE[$oid]; |
|
90 | + return new self($curve); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Get key size in bits for the curve. |
|
95 | - * |
|
96 | - * @throws \UnexpectedValueException |
|
97 | - * @return int |
|
98 | - */ |
|
99 | - public function keySizeBits() |
|
100 | - { |
|
101 | - if (!array_key_exists($this->_value, self::MAP_CURVE_TO_SIZE)) { |
|
102 | - throw new \UnexpectedValueException( |
|
103 | - "Curve " . $this->_value . " not supported."); |
|
104 | - } |
|
105 | - return self::MAP_CURVE_TO_SIZE[$this->_value]; |
|
106 | - } |
|
93 | + /** |
|
94 | + * Get key size in bits for the curve. |
|
95 | + * |
|
96 | + * @throws \UnexpectedValueException |
|
97 | + * @return int |
|
98 | + */ |
|
99 | + public function keySizeBits() |
|
100 | + { |
|
101 | + if (!array_key_exists($this->_value, self::MAP_CURVE_TO_SIZE)) { |
|
102 | + throw new \UnexpectedValueException( |
|
103 | + "Curve " . $this->_value . " not supported."); |
|
104 | + } |
|
105 | + return self::MAP_CURVE_TO_SIZE[$this->_value]; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Get the curve OID by curve name. |
|
110 | - * |
|
111 | - * @param string $name Curve parameter name |
|
112 | - * @throws \UnexpectedValueException If the curve is not supported |
|
113 | - * @return string OID in dotted format |
|
114 | - */ |
|
115 | - public static function nameToOID($name) |
|
116 | - { |
|
117 | - static $reverseMap; |
|
118 | - if (!isset($reverseMap)) { |
|
119 | - $reverseMap = array_flip(self::MAP_OID_TO_CURVE); |
|
120 | - } |
|
121 | - if (!isset($reverseMap[$name])) { |
|
122 | - throw new \UnexpectedValueException("Curve $name not supported."); |
|
123 | - } |
|
124 | - return $reverseMap[$name]; |
|
125 | - } |
|
108 | + /** |
|
109 | + * Get the curve OID by curve name. |
|
110 | + * |
|
111 | + * @param string $name Curve parameter name |
|
112 | + * @throws \UnexpectedValueException If the curve is not supported |
|
113 | + * @return string OID in dotted format |
|
114 | + */ |
|
115 | + public static function nameToOID($name) |
|
116 | + { |
|
117 | + static $reverseMap; |
|
118 | + if (!isset($reverseMap)) { |
|
119 | + $reverseMap = array_flip(self::MAP_OID_TO_CURVE); |
|
120 | + } |
|
121 | + if (!isset($reverseMap[$name])) { |
|
122 | + throw new \UnexpectedValueException("Curve $name not supported."); |
|
123 | + } |
|
124 | + return $reverseMap[$name]; |
|
125 | + } |
|
126 | 126 | } |
@@ -11,16 +11,16 @@ |
||
11 | 11 | */ |
12 | 12 | class YCoordinateParameter extends CoordinateParameter |
13 | 13 | { |
14 | - use Base64URLValue; |
|
14 | + use Base64URLValue; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Constructor. |
|
18 | - * |
|
19 | - * @param string $coord Y coordinate in base64url encoding |
|
20 | - */ |
|
21 | - public function __construct($coord) |
|
22 | - { |
|
23 | - $this->_validateEncoding($coord); |
|
24 | - parent::__construct(self::PARAM_Y_COORDINATE, $coord); |
|
25 | - } |
|
16 | + /** |
|
17 | + * Constructor. |
|
18 | + * |
|
19 | + * @param string $coord Y coordinate in base64url encoding |
|
20 | + */ |
|
21 | + public function __construct($coord) |
|
22 | + { |
|
23 | + $this->_validateEncoding($coord); |
|
24 | + parent::__construct(self::PARAM_Y_COORDINATE, $coord); |
|
25 | + } |
|
26 | 26 | } |
@@ -12,21 +12,21 @@ |
||
12 | 12 | */ |
13 | 13 | class X509CertificateChainParameter extends JWKParameter |
14 | 14 | { |
15 | - use ArrayParameterValue; |
|
15 | + use ArrayParameterValue; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Constructor. |
|
19 | - * |
|
20 | - * @param string ...$certs Base64 encoded DER certificates |
|
21 | - */ |
|
22 | - public function __construct(...$certs) |
|
23 | - { |
|
24 | - foreach ($certs as $cert) { |
|
25 | - if (!Base64::isValid($cert)) { |
|
26 | - throw new \UnexpectedValueException( |
|
27 | - "Certificate must be base64 encoded."); |
|
28 | - } |
|
29 | - } |
|
30 | - parent::__construct(self::PARAM_X509_CERTIFICATE_CHAIN, $certs); |
|
31 | - } |
|
17 | + /** |
|
18 | + * Constructor. |
|
19 | + * |
|
20 | + * @param string ...$certs Base64 encoded DER certificates |
|
21 | + */ |
|
22 | + public function __construct(...$certs) |
|
23 | + { |
|
24 | + foreach ($certs as $cert) { |
|
25 | + if (!Base64::isValid($cert)) { |
|
26 | + throw new \UnexpectedValueException( |
|
27 | + "Certificate must be base64 encoded."); |
|
28 | + } |
|
29 | + } |
|
30 | + parent::__construct(self::PARAM_X509_CERTIFICATE_CHAIN, $certs); |
|
31 | + } |
|
32 | 32 | } |
@@ -11,16 +11,16 @@ |
||
11 | 11 | */ |
12 | 12 | class FirstFactorCRTExponentParameter extends JWKParameter |
13 | 13 | { |
14 | - use Base64UIntValue; |
|
14 | + use Base64UIntValue; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Constructor. |
|
18 | - * |
|
19 | - * @param string $dp First factor CRT exponent in base64urlUInt encoding |
|
20 | - */ |
|
21 | - public function __construct($dp) |
|
22 | - { |
|
23 | - $this->_validateEncoding($dp); |
|
24 | - parent::__construct(self::PARAM_FIRST_FACTOR_CRT_EXPONENT, $dp); |
|
25 | - } |
|
16 | + /** |
|
17 | + * Constructor. |
|
18 | + * |
|
19 | + * @param string $dp First factor CRT exponent in base64urlUInt encoding |
|
20 | + */ |
|
21 | + public function __construct($dp) |
|
22 | + { |
|
23 | + $this->_validateEncoding($dp); |
|
24 | + parent::__construct(self::PARAM_FIRST_FACTOR_CRT_EXPONENT, $dp); |
|
25 | + } |
|
26 | 26 | } |