@@ -13,15 +13,15 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class AlgorithmParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use StringParameterValue; |
|
| 16 | + use StringParameterValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $algo Algorithm name |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $algo) |
|
| 24 | - { |
|
| 25 | - parent::__construct(self::PARAM_ALGORITHM, $algo); |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $algo Algorithm name |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $algo) |
|
| 24 | + { |
|
| 25 | + parent::__construct(self::PARAM_ALGORITHM, $algo); |
|
| 26 | + } |
|
| 27 | 27 | } |
@@ -13,16 +13,16 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class FirstPrimeFactorParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use Base64UIntValue; |
|
| 16 | + use Base64UIntValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $p First prime factor in base64urlUInt encoding |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $p) |
|
| 24 | - { |
|
| 25 | - $this->_validateEncoding($p); |
|
| 26 | - parent::__construct(self::PARAM_FIRST_PRIME_FACTOR, $p); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $p First prime factor in base64urlUInt encoding |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $p) |
|
| 24 | + { |
|
| 25 | + $this->_validateEncoding($p); |
|
| 26 | + parent::__construct(self::PARAM_FIRST_PRIME_FACTOR, $p); |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -13,16 +13,16 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class SecondFactorCRTExponentParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use Base64UIntValue; |
|
| 16 | + use Base64UIntValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $dq Second factor CRT exponent in base64urlUInt encoding |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $dq) |
|
| 24 | - { |
|
| 25 | - $this->_validateEncoding($dq); |
|
| 26 | - parent::__construct(self::PARAM_SECOND_FACTOR_CRT_EXPONENT, $dq); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $dq Second factor CRT exponent in base64urlUInt encoding |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $dq) |
|
| 24 | + { |
|
| 25 | + $this->_validateEncoding($dq); |
|
| 26 | + parent::__construct(self::PARAM_SECOND_FACTOR_CRT_EXPONENT, $dq); |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -13,16 +13,16 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class PrivateExponentParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use Base64UIntValue; |
|
| 16 | + use Base64UIntValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $d Private exponent in base64urlUInt encoding |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $d) |
|
| 24 | - { |
|
| 25 | - $this->_validateEncoding($d); |
|
| 26 | - parent::__construct(self::PARAM_PRIVATE_EXPONENT, $d); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $d Private exponent in base64urlUInt encoding |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $d) |
|
| 24 | + { |
|
| 25 | + $this->_validateEncoding($d); |
|
| 26 | + parent::__construct(self::PARAM_PRIVATE_EXPONENT, $d); |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -13,26 +13,26 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class KeyValueParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use Base64URLValue; |
|
| 16 | + use Base64URLValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $key Base64url encoded key |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $key) |
|
| 24 | - { |
|
| 25 | - $this->_validateEncoding($key); |
|
| 26 | - parent::__construct(self::PARAM_KEY_VALUE, $key); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $key Base64url encoded key |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $key) |
|
| 24 | + { |
|
| 25 | + $this->_validateEncoding($key); |
|
| 26 | + parent::__construct(self::PARAM_KEY_VALUE, $key); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Get key in binary format. |
|
| 31 | - * |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - public function key(): string |
|
| 35 | - { |
|
| 36 | - return $this->string(); |
|
| 37 | - } |
|
| 29 | + /** |
|
| 30 | + * Get key in binary format. |
|
| 31 | + * |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + public function key(): string |
|
| 35 | + { |
|
| 36 | + return $this->string(); |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -14,127 +14,127 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class JWKParameter extends Parameter |
| 16 | 16 | { |
| 17 | - // registered parameter names |
|
| 18 | - const PARAM_KEY_TYPE = "kty"; |
|
| 19 | - const PARAM_PUBLIC_KEY_USE = "use"; |
|
| 20 | - const PARAM_KEY_OPERATIONS = "key_ops"; |
|
| 21 | - const PARAM_ALGORITHM = "alg"; |
|
| 22 | - const PARAM_KEY_ID = "kid"; |
|
| 23 | - const PARAM_X509_URL = "x5u"; |
|
| 24 | - const PARAM_X509_CERTIFICATE_CHAIN = "x5c"; |
|
| 25 | - const PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT = "x5t"; |
|
| 26 | - const PARAM_X509_CERTIFICATE_SHA256_THUMBPRINT = "x5t#S256"; |
|
| 27 | - const PARAM_CURVE = "crv"; |
|
| 28 | - const PARAM_X_COORDINATE = "x"; |
|
| 29 | - const PARAM_Y_COORDINATE = "y"; |
|
| 30 | - const PARAM_ECC_PRIVATE_KEY = "d"; |
|
| 31 | - const PARAM_MODULUS = "n"; |
|
| 32 | - const PARAM_EXPONENT = "e"; |
|
| 33 | - const PARAM_PRIVATE_EXPONENT = "d"; |
|
| 34 | - const PARAM_FIRST_PRIME_FACTOR = "p"; |
|
| 35 | - const PARAM_SECOND_PRIME_FACTOR = "q"; |
|
| 36 | - const PARAM_FIRST_FACTOR_CRT_EXPONENT = "dp"; |
|
| 37 | - const PARAM_SECOND_FACTOR_CRT_EXPONENT = "dq"; |
|
| 38 | - const PARAM_FIRST_CRT_COEFFICIENT = "qi"; |
|
| 39 | - const PARAM_OTHER_PRIMES_INFO = "oth"; |
|
| 40 | - const PARAM_KEY_VALUE = "k"; |
|
| 17 | + // registered parameter names |
|
| 18 | + const PARAM_KEY_TYPE = "kty"; |
|
| 19 | + const PARAM_PUBLIC_KEY_USE = "use"; |
|
| 20 | + const PARAM_KEY_OPERATIONS = "key_ops"; |
|
| 21 | + const PARAM_ALGORITHM = "alg"; |
|
| 22 | + const PARAM_KEY_ID = "kid"; |
|
| 23 | + const PARAM_X509_URL = "x5u"; |
|
| 24 | + const PARAM_X509_CERTIFICATE_CHAIN = "x5c"; |
|
| 25 | + const PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT = "x5t"; |
|
| 26 | + const PARAM_X509_CERTIFICATE_SHA256_THUMBPRINT = "x5t#S256"; |
|
| 27 | + const PARAM_CURVE = "crv"; |
|
| 28 | + const PARAM_X_COORDINATE = "x"; |
|
| 29 | + const PARAM_Y_COORDINATE = "y"; |
|
| 30 | + const PARAM_ECC_PRIVATE_KEY = "d"; |
|
| 31 | + const PARAM_MODULUS = "n"; |
|
| 32 | + const PARAM_EXPONENT = "e"; |
|
| 33 | + const PARAM_PRIVATE_EXPONENT = "d"; |
|
| 34 | + const PARAM_FIRST_PRIME_FACTOR = "p"; |
|
| 35 | + const PARAM_SECOND_PRIME_FACTOR = "q"; |
|
| 36 | + const PARAM_FIRST_FACTOR_CRT_EXPONENT = "dp"; |
|
| 37 | + const PARAM_SECOND_FACTOR_CRT_EXPONENT = "dq"; |
|
| 38 | + const PARAM_FIRST_CRT_COEFFICIENT = "qi"; |
|
| 39 | + const PARAM_OTHER_PRIMES_INFO = "oth"; |
|
| 40 | + const PARAM_KEY_VALUE = "k"; |
|
| 41 | 41 | |
| 42 | - // shorthand aliases for parameter names |
|
| 43 | - const P_KTY = self::PARAM_KEY_TYPE; |
|
| 44 | - const P_USE = self::PARAM_PUBLIC_KEY_USE; |
|
| 45 | - const P_KEY_OPS = self::PARAM_KEY_OPERATIONS; |
|
| 46 | - const P_ALG = self::PARAM_ALGORITHM; |
|
| 47 | - const P_KID = self::PARAM_KEY_ID; |
|
| 48 | - const P_X5U = self::PARAM_X509_URL; |
|
| 49 | - const P_X5C = self::PARAM_X509_CERTIFICATE_CHAIN; |
|
| 50 | - const P_X5T = self::PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT; |
|
| 51 | - const P_X5TS256 = self::PARAM_X509_CERTIFICATE_SHA256_THUMBPRINT; |
|
| 52 | - const P_CRV = self::PARAM_CURVE; |
|
| 53 | - const P_X = self::PARAM_X_COORDINATE; |
|
| 54 | - const P_Y = self::PARAM_Y_COORDINATE; |
|
| 55 | - const P_ECC_D = self::PARAM_ECC_PRIVATE_KEY; |
|
| 56 | - const P_N = self::PARAM_MODULUS; |
|
| 57 | - const P_E = self::PARAM_EXPONENT; |
|
| 58 | - const P_RSA_D = self::PARAM_PRIVATE_EXPONENT; |
|
| 59 | - const P_P = self::PARAM_FIRST_PRIME_FACTOR; |
|
| 60 | - const P_Q = self::PARAM_SECOND_PRIME_FACTOR; |
|
| 61 | - const P_DP = self::PARAM_FIRST_FACTOR_CRT_EXPONENT; |
|
| 62 | - const P_DQ = self::PARAM_SECOND_FACTOR_CRT_EXPONENT; |
|
| 63 | - const P_QI = self::PARAM_FIRST_CRT_COEFFICIENT; |
|
| 64 | - const P_OTH = self::PARAM_OTHER_PRIMES_INFO; |
|
| 65 | - const P_K = self::PARAM_KEY_VALUE; |
|
| 42 | + // shorthand aliases for parameter names |
|
| 43 | + const P_KTY = self::PARAM_KEY_TYPE; |
|
| 44 | + const P_USE = self::PARAM_PUBLIC_KEY_USE; |
|
| 45 | + const P_KEY_OPS = self::PARAM_KEY_OPERATIONS; |
|
| 46 | + const P_ALG = self::PARAM_ALGORITHM; |
|
| 47 | + const P_KID = self::PARAM_KEY_ID; |
|
| 48 | + const P_X5U = self::PARAM_X509_URL; |
|
| 49 | + const P_X5C = self::PARAM_X509_CERTIFICATE_CHAIN; |
|
| 50 | + const P_X5T = self::PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT; |
|
| 51 | + const P_X5TS256 = self::PARAM_X509_CERTIFICATE_SHA256_THUMBPRINT; |
|
| 52 | + const P_CRV = self::PARAM_CURVE; |
|
| 53 | + const P_X = self::PARAM_X_COORDINATE; |
|
| 54 | + const P_Y = self::PARAM_Y_COORDINATE; |
|
| 55 | + const P_ECC_D = self::PARAM_ECC_PRIVATE_KEY; |
|
| 56 | + const P_N = self::PARAM_MODULUS; |
|
| 57 | + const P_E = self::PARAM_EXPONENT; |
|
| 58 | + const P_RSA_D = self::PARAM_PRIVATE_EXPONENT; |
|
| 59 | + const P_P = self::PARAM_FIRST_PRIME_FACTOR; |
|
| 60 | + const P_Q = self::PARAM_SECOND_PRIME_FACTOR; |
|
| 61 | + const P_DP = self::PARAM_FIRST_FACTOR_CRT_EXPONENT; |
|
| 62 | + const P_DQ = self::PARAM_SECOND_FACTOR_CRT_EXPONENT; |
|
| 63 | + const P_QI = self::PARAM_FIRST_CRT_COEFFICIENT; |
|
| 64 | + const P_OTH = self::PARAM_OTHER_PRIMES_INFO; |
|
| 65 | + const P_K = self::PARAM_KEY_VALUE; |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Mapping from registered JWK parameter name to class name. |
|
| 69 | - * |
|
| 70 | - * Note that ECC private key and RSA private key cannot be mapped since |
|
| 71 | - * they share the same parameter name 'd'. |
|
| 72 | - * |
|
| 73 | - * @internal |
|
| 74 | - * |
|
| 75 | - * @var array |
|
| 76 | - */ |
|
| 77 | - const MAP_NAME_TO_CLASS = array( |
|
| 78 | - /* @formatter:off */ |
|
| 79 | - self::P_KTY => KeyTypeParameter::class, |
|
| 80 | - self::P_USE => PublicKeyUseParameter::class, |
|
| 81 | - self::P_KEY_OPS => KeyOperationsParameter::class, |
|
| 82 | - self::P_ALG => AlgorithmParameter::class, |
|
| 83 | - self::P_KID => KeyIDParameter::class, |
|
| 84 | - self::P_CRV => CurveParameter::class, |
|
| 85 | - self::P_X => XCoordinateParameter::class, |
|
| 86 | - self::P_Y => YCoordinateParameter::class, |
|
| 87 | - self::P_N => ModulusParameter::class, |
|
| 88 | - self::P_E => ExponentParameter::class, |
|
| 89 | - self::P_P => FirstPrimeFactorParameter::class, |
|
| 90 | - self::P_Q => SecondPrimeFactorParameter::class, |
|
| 91 | - self::P_DP => FirstFactorCRTExponentParameter::class, |
|
| 92 | - self::P_DQ => SecondFactorCRTExponentParameter::class, |
|
| 93 | - self::P_QI => FirstCRTCoefficientParameter::class, |
|
| 94 | - self::P_OTH => OtherPrimesInfoParameter::class, |
|
| 95 | - self::P_K => KeyValueParameter::class |
|
| 96 | - /* @formatter:on */ |
|
| 97 | - ); |
|
| 67 | + /** |
|
| 68 | + * Mapping from registered JWK parameter name to class name. |
|
| 69 | + * |
|
| 70 | + * Note that ECC private key and RSA private key cannot be mapped since |
|
| 71 | + * they share the same parameter name 'd'. |
|
| 72 | + * |
|
| 73 | + * @internal |
|
| 74 | + * |
|
| 75 | + * @var array |
|
| 76 | + */ |
|
| 77 | + const MAP_NAME_TO_CLASS = array( |
|
| 78 | + /* @formatter:off */ |
|
| 79 | + self::P_KTY => KeyTypeParameter::class, |
|
| 80 | + self::P_USE => PublicKeyUseParameter::class, |
|
| 81 | + self::P_KEY_OPS => KeyOperationsParameter::class, |
|
| 82 | + self::P_ALG => AlgorithmParameter::class, |
|
| 83 | + self::P_KID => KeyIDParameter::class, |
|
| 84 | + self::P_CRV => CurveParameter::class, |
|
| 85 | + self::P_X => XCoordinateParameter::class, |
|
| 86 | + self::P_Y => YCoordinateParameter::class, |
|
| 87 | + self::P_N => ModulusParameter::class, |
|
| 88 | + self::P_E => ExponentParameter::class, |
|
| 89 | + self::P_P => FirstPrimeFactorParameter::class, |
|
| 90 | + self::P_Q => SecondPrimeFactorParameter::class, |
|
| 91 | + self::P_DP => FirstFactorCRTExponentParameter::class, |
|
| 92 | + self::P_DQ => SecondFactorCRTExponentParameter::class, |
|
| 93 | + self::P_QI => FirstCRTCoefficientParameter::class, |
|
| 94 | + self::P_OTH => OtherPrimesInfoParameter::class, |
|
| 95 | + self::P_K => KeyValueParameter::class |
|
| 96 | + /* @formatter:on */ |
|
| 97 | + ); |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Constructor. |
|
| 101 | - * |
|
| 102 | - * @param string $name Parameter name |
|
| 103 | - * @param mixed $value Parameter value |
|
| 104 | - */ |
|
| 105 | - public function __construct(string $name, $value) |
|
| 106 | - { |
|
| 107 | - $this->_name = $name; |
|
| 108 | - $this->_value = $value; |
|
| 109 | - } |
|
| 99 | + /** |
|
| 100 | + * Constructor. |
|
| 101 | + * |
|
| 102 | + * @param string $name Parameter name |
|
| 103 | + * @param mixed $value Parameter value |
|
| 104 | + */ |
|
| 105 | + public function __construct(string $name, $value) |
|
| 106 | + { |
|
| 107 | + $this->_name = $name; |
|
| 108 | + $this->_value = $value; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Initialize from a name and a value. |
|
| 113 | - * |
|
| 114 | - * Returns a parameter specific object if one is implemented. |
|
| 115 | - * |
|
| 116 | - * @param string $name Parameter name |
|
| 117 | - * @param mixed $value Parameter value |
|
| 118 | - * @return self |
|
| 119 | - */ |
|
| 120 | - public static function fromNameAndValue(string $name, string $value): self |
|
| 121 | - { |
|
| 122 | - if (array_key_exists($name, self::MAP_NAME_TO_CLASS)) { |
|
| 123 | - $cls = self::MAP_NAME_TO_CLASS[$name]; |
|
| 124 | - return $cls::fromJSONValue($value); |
|
| 125 | - } |
|
| 126 | - return new self($name, $value); |
|
| 127 | - } |
|
| 111 | + /** |
|
| 112 | + * Initialize from a name and a value. |
|
| 113 | + * |
|
| 114 | + * Returns a parameter specific object if one is implemented. |
|
| 115 | + * |
|
| 116 | + * @param string $name Parameter name |
|
| 117 | + * @param mixed $value Parameter value |
|
| 118 | + * @return self |
|
| 119 | + */ |
|
| 120 | + public static function fromNameAndValue(string $name, string $value): self |
|
| 121 | + { |
|
| 122 | + if (array_key_exists($name, self::MAP_NAME_TO_CLASS)) { |
|
| 123 | + $cls = self::MAP_NAME_TO_CLASS[$name]; |
|
| 124 | + return $cls::fromJSONValue($value); |
|
| 125 | + } |
|
| 126 | + return new self($name, $value); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Initialize from a JSON value. |
|
| 131 | - * |
|
| 132 | - * @param mixed $value |
|
| 133 | - * @return self |
|
| 134 | - */ |
|
| 135 | - public static function fromJSONValue($value) |
|
| 136 | - { |
|
| 137 | - throw new \BadMethodCallException( |
|
| 138 | - __FUNCTION__ . " must be implemented in a derived class."); |
|
| 139 | - } |
|
| 129 | + /** |
|
| 130 | + * Initialize from a JSON value. |
|
| 131 | + * |
|
| 132 | + * @param mixed $value |
|
| 133 | + * @return self |
|
| 134 | + */ |
|
| 135 | + public static function fromJSONValue($value) |
|
| 136 | + { |
|
| 137 | + throw new \BadMethodCallException( |
|
| 138 | + __FUNCTION__ . " must be implemented in a derived class."); |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -13,116 +13,116 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class CurveParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use StringParameterValue; |
|
| 16 | + use StringParameterValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * P-256 Curve. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - const CURVE_P256 = "P-256"; |
|
| 18 | + /** |
|
| 19 | + * P-256 Curve. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + const CURVE_P256 = "P-256"; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * P-384 Curve. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - const CURVE_P384 = "P-384"; |
|
| 25 | + /** |
|
| 26 | + * P-384 Curve. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + const CURVE_P384 = "P-384"; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * P-521 Curve. |
|
| 34 | - * |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - const CURVE_P521 = "P-521"; |
|
| 32 | + /** |
|
| 33 | + * P-521 Curve. |
|
| 34 | + * |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + const CURVE_P521 = "P-521"; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Mapping from curve OID to curve name. |
|
| 41 | - * |
|
| 42 | - * @internal |
|
| 43 | - * |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - const MAP_OID_TO_CURVE = array( |
|
| 47 | - /* @formatter:off */ |
|
| 48 | - "1.2.840.10045.3.1.7" => self::CURVE_P256, |
|
| 49 | - "1.3.132.0.34" => self::CURVE_P384, |
|
| 50 | - "1.3.132.0.35" => self::CURVE_P521 |
|
| 51 | - /* @formatter:on */ |
|
| 52 | - ); |
|
| 39 | + /** |
|
| 40 | + * Mapping from curve OID to curve name. |
|
| 41 | + * |
|
| 42 | + * @internal |
|
| 43 | + * |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + const MAP_OID_TO_CURVE = array( |
|
| 47 | + /* @formatter:off */ |
|
| 48 | + "1.2.840.10045.3.1.7" => self::CURVE_P256, |
|
| 49 | + "1.3.132.0.34" => self::CURVE_P384, |
|
| 50 | + "1.3.132.0.35" => self::CURVE_P521 |
|
| 51 | + /* @formatter:on */ |
|
| 52 | + ); |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Mapping from curve name to bit size. |
|
| 56 | - * |
|
| 57 | - * @internal |
|
| 58 | - * |
|
| 59 | - * @var array |
|
| 60 | - */ |
|
| 61 | - const MAP_CURVE_TO_SIZE = array( |
|
| 62 | - /* @formatter:off */ |
|
| 63 | - self::CURVE_P256 => 256, |
|
| 64 | - self::CURVE_P384 => 384, |
|
| 65 | - self::CURVE_P521 => 521 |
|
| 66 | - /* @formatter:on */ |
|
| 67 | - ); |
|
| 54 | + /** |
|
| 55 | + * Mapping from curve name to bit size. |
|
| 56 | + * |
|
| 57 | + * @internal |
|
| 58 | + * |
|
| 59 | + * @var array |
|
| 60 | + */ |
|
| 61 | + const MAP_CURVE_TO_SIZE = array( |
|
| 62 | + /* @formatter:off */ |
|
| 63 | + self::CURVE_P256 => 256, |
|
| 64 | + self::CURVE_P384 => 384, |
|
| 65 | + self::CURVE_P521 => 521 |
|
| 66 | + /* @formatter:on */ |
|
| 67 | + ); |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Constructor. |
|
| 71 | - * |
|
| 72 | - * @param string $curve Curve name |
|
| 73 | - */ |
|
| 74 | - public function __construct(string $curve) |
|
| 75 | - { |
|
| 76 | - parent::__construct(self::PARAM_CURVE, $curve); |
|
| 77 | - } |
|
| 69 | + /** |
|
| 70 | + * Constructor. |
|
| 71 | + * |
|
| 72 | + * @param string $curve Curve name |
|
| 73 | + */ |
|
| 74 | + public function __construct(string $curve) |
|
| 75 | + { |
|
| 76 | + parent::__construct(self::PARAM_CURVE, $curve); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Initialize from curve OID. |
|
| 81 | - * |
|
| 82 | - * @param string $oid Object identifier in dotted format |
|
| 83 | - * @throws \UnexpectedValueException If the curve is not supported |
|
| 84 | - * @return self |
|
| 85 | - */ |
|
| 86 | - public static function fromOID(string $oid): self |
|
| 87 | - { |
|
| 88 | - if (!array_key_exists($oid, self::MAP_OID_TO_CURVE)) { |
|
| 89 | - throw new \UnexpectedValueException("OID $oid not supported."); |
|
| 90 | - } |
|
| 91 | - $curve = self::MAP_OID_TO_CURVE[$oid]; |
|
| 92 | - return new self($curve); |
|
| 93 | - } |
|
| 79 | + /** |
|
| 80 | + * Initialize from curve OID. |
|
| 81 | + * |
|
| 82 | + * @param string $oid Object identifier in dotted format |
|
| 83 | + * @throws \UnexpectedValueException If the curve is not supported |
|
| 84 | + * @return self |
|
| 85 | + */ |
|
| 86 | + public static function fromOID(string $oid): self |
|
| 87 | + { |
|
| 88 | + if (!array_key_exists($oid, self::MAP_OID_TO_CURVE)) { |
|
| 89 | + throw new \UnexpectedValueException("OID $oid not supported."); |
|
| 90 | + } |
|
| 91 | + $curve = self::MAP_OID_TO_CURVE[$oid]; |
|
| 92 | + return new self($curve); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Get key size in bits for the curve. |
|
| 97 | - * |
|
| 98 | - * @throws \UnexpectedValueException |
|
| 99 | - * @return int |
|
| 100 | - */ |
|
| 101 | - public function keySizeBits(): int |
|
| 102 | - { |
|
| 103 | - if (!array_key_exists($this->_value, self::MAP_CURVE_TO_SIZE)) { |
|
| 104 | - throw new \UnexpectedValueException( |
|
| 105 | - "Curve " . $this->_value . " not supported."); |
|
| 106 | - } |
|
| 107 | - return self::MAP_CURVE_TO_SIZE[$this->_value]; |
|
| 108 | - } |
|
| 95 | + /** |
|
| 96 | + * Get key size in bits for the curve. |
|
| 97 | + * |
|
| 98 | + * @throws \UnexpectedValueException |
|
| 99 | + * @return int |
|
| 100 | + */ |
|
| 101 | + public function keySizeBits(): int |
|
| 102 | + { |
|
| 103 | + if (!array_key_exists($this->_value, self::MAP_CURVE_TO_SIZE)) { |
|
| 104 | + throw new \UnexpectedValueException( |
|
| 105 | + "Curve " . $this->_value . " not supported."); |
|
| 106 | + } |
|
| 107 | + return self::MAP_CURVE_TO_SIZE[$this->_value]; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Get the curve OID by curve name. |
|
| 112 | - * |
|
| 113 | - * @param string $name Curve parameter name |
|
| 114 | - * @throws \UnexpectedValueException If the curve is not supported |
|
| 115 | - * @return string OID in dotted format |
|
| 116 | - */ |
|
| 117 | - public static function nameToOID(string $name): string |
|
| 118 | - { |
|
| 119 | - static $reverseMap; |
|
| 120 | - if (!isset($reverseMap)) { |
|
| 121 | - $reverseMap = array_flip(self::MAP_OID_TO_CURVE); |
|
| 122 | - } |
|
| 123 | - if (!isset($reverseMap[$name])) { |
|
| 124 | - throw new \UnexpectedValueException("Curve $name not supported."); |
|
| 125 | - } |
|
| 126 | - return $reverseMap[$name]; |
|
| 127 | - } |
|
| 110 | + /** |
|
| 111 | + * Get the curve OID by curve name. |
|
| 112 | + * |
|
| 113 | + * @param string $name Curve parameter name |
|
| 114 | + * @throws \UnexpectedValueException If the curve is not supported |
|
| 115 | + * @return string OID in dotted format |
|
| 116 | + */ |
|
| 117 | + public static function nameToOID(string $name): string |
|
| 118 | + { |
|
| 119 | + static $reverseMap; |
|
| 120 | + if (!isset($reverseMap)) { |
|
| 121 | + $reverseMap = array_flip(self::MAP_OID_TO_CURVE); |
|
| 122 | + } |
|
| 123 | + if (!isset($reverseMap[$name])) { |
|
| 124 | + throw new \UnexpectedValueException("Curve $name not supported."); |
|
| 125 | + } |
|
| 126 | + return $reverseMap[$name]; |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -13,16 +13,16 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class ExponentParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use Base64UIntValue; |
|
| 16 | + use Base64UIntValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $e Exponent in base64urlUInt encoding |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $e) |
|
| 24 | - { |
|
| 25 | - $this->_validateEncoding($e); |
|
| 26 | - parent::__construct(self::PARAM_EXPONENT, $e); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $e Exponent in base64urlUInt encoding |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $e) |
|
| 24 | + { |
|
| 25 | + $this->_validateEncoding($e); |
|
| 26 | + parent::__construct(self::PARAM_EXPONENT, $e); |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -13,24 +13,24 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class KeyOperationsParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use ArrayParameterValue; |
|
| 16 | + use ArrayParameterValue; |
|
| 17 | 17 | |
| 18 | - const OP_SIGN = "sign"; |
|
| 19 | - const OP_VERIFY = "verify"; |
|
| 20 | - const OP_ENCRYPT = "encrypt"; |
|
| 21 | - const OP_DECRYPT = "decrypt"; |
|
| 22 | - const OP_WRAP_KEY = "wrapKey"; |
|
| 23 | - const OP_UNWRAP_KEY = "unwrapKey"; |
|
| 24 | - const OP_DERIVE_KEY = "deriveKey"; |
|
| 25 | - const OP_DERIVE_BITS = "deriveBits"; |
|
| 18 | + const OP_SIGN = "sign"; |
|
| 19 | + const OP_VERIFY = "verify"; |
|
| 20 | + const OP_ENCRYPT = "encrypt"; |
|
| 21 | + const OP_DECRYPT = "decrypt"; |
|
| 22 | + const OP_WRAP_KEY = "wrapKey"; |
|
| 23 | + const OP_UNWRAP_KEY = "unwrapKey"; |
|
| 24 | + const OP_DERIVE_KEY = "deriveKey"; |
|
| 25 | + const OP_DERIVE_BITS = "deriveBits"; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Constructor. |
|
| 29 | - * |
|
| 30 | - * @param string ...$ops Key operations |
|
| 31 | - */ |
|
| 32 | - public function __construct(string ...$ops) |
|
| 33 | - { |
|
| 34 | - parent::__construct(self::PARAM_KEY_OPERATIONS, $ops); |
|
| 35 | - } |
|
| 27 | + /** |
|
| 28 | + * Constructor. |
|
| 29 | + * |
|
| 30 | + * @param string ...$ops Key operations |
|
| 31 | + */ |
|
| 32 | + public function __construct(string ...$ops) |
|
| 33 | + { |
|
| 34 | + parent::__construct(self::PARAM_KEY_OPERATIONS, $ops); |
|
| 35 | + } |
|
| 36 | 36 | } |