@@ -15,27 +15,27 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class A192KWAlgorithm extends AESKWAlgorithm |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * {@inheritdoc} |
|
| 20 | - */ |
|
| 21 | - public function algorithmParamValue(): string |
|
| 22 | - { |
|
| 23 | - return JWA::ALGO_A192KW; |
|
| 24 | - } |
|
| 18 | + /** |
|
| 19 | + * {@inheritdoc} |
|
| 20 | + */ |
|
| 21 | + public function algorithmParamValue(): string |
|
| 22 | + { |
|
| 23 | + return JWA::ALGO_A192KW; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * {@inheritdoc} |
|
| 28 | - */ |
|
| 29 | - protected function _kekSize(): int |
|
| 30 | - { |
|
| 31 | - return 24; |
|
| 32 | - } |
|
| 26 | + /** |
|
| 27 | + * {@inheritdoc} |
|
| 28 | + */ |
|
| 29 | + protected function _kekSize(): int |
|
| 30 | + { |
|
| 31 | + return 24; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * {@inheritdoc} |
|
| 36 | - */ |
|
| 37 | - protected function _AESKWAlgo(): AESKeyWrapAlgorithm |
|
| 38 | - { |
|
| 39 | - return new AESKW192(); |
|
| 40 | - } |
|
| 34 | + /** |
|
| 35 | + * {@inheritdoc} |
|
| 36 | + */ |
|
| 37 | + protected function _AESKWAlgo(): AESKeyWrapAlgorithm |
|
| 38 | + { |
|
| 39 | + return new AESKW192(); |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -18,101 +18,101 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class DirectCEKAlgorithm extends KeyManagementAlgorithm |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Content encryption key. |
|
| 23 | - * |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - protected $_cek; |
|
| 21 | + /** |
|
| 22 | + * Content encryption key. |
|
| 23 | + * |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + protected $_cek; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Constructor. |
|
| 30 | - * |
|
| 31 | - * @param string $cek Content encryption key |
|
| 32 | - */ |
|
| 33 | - public function __construct(string $cek) |
|
| 34 | - { |
|
| 35 | - $this->_cek = $cek; |
|
| 36 | - } |
|
| 28 | + /** |
|
| 29 | + * Constructor. |
|
| 30 | + * |
|
| 31 | + * @param string $cek Content encryption key |
|
| 32 | + */ |
|
| 33 | + public function __construct(string $cek) |
|
| 34 | + { |
|
| 35 | + $this->_cek = $cek; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Initialize from JWK. |
|
| 40 | - * |
|
| 41 | - * @param JWK $jwk |
|
| 42 | - * @param Header $header |
|
| 43 | - * |
|
| 44 | - * @throws \UnexpectedValueException |
|
| 45 | - * |
|
| 46 | - * @return self |
|
| 47 | - */ |
|
| 48 | - public static function fromJWK(JWK $jwk, Header $header): KeyManagementAlgorithm |
|
| 49 | - { |
|
| 50 | - $jwk = SymmetricKeyJWK::fromJWK($jwk); |
|
| 51 | - $alg = JWA::deriveAlgorithmName($header); |
|
| 52 | - if (JWA::ALGO_DIR !== $alg) { |
|
| 53 | - throw new \UnexpectedValueException("Invalid algorithm '{$alg}'."); |
|
| 54 | - } |
|
| 55 | - return new self($jwk->key()); |
|
| 56 | - } |
|
| 38 | + /** |
|
| 39 | + * Initialize from JWK. |
|
| 40 | + * |
|
| 41 | + * @param JWK $jwk |
|
| 42 | + * @param Header $header |
|
| 43 | + * |
|
| 44 | + * @throws \UnexpectedValueException |
|
| 45 | + * |
|
| 46 | + * @return self |
|
| 47 | + */ |
|
| 48 | + public static function fromJWK(JWK $jwk, Header $header): KeyManagementAlgorithm |
|
| 49 | + { |
|
| 50 | + $jwk = SymmetricKeyJWK::fromJWK($jwk); |
|
| 51 | + $alg = JWA::deriveAlgorithmName($header); |
|
| 52 | + if (JWA::ALGO_DIR !== $alg) { |
|
| 53 | + throw new \UnexpectedValueException("Invalid algorithm '{$alg}'."); |
|
| 54 | + } |
|
| 55 | + return new self($jwk->key()); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Get content encryption key. |
|
| 60 | - * |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public function cek(): string |
|
| 64 | - { |
|
| 65 | - return $this->_cek; |
|
| 66 | - } |
|
| 58 | + /** |
|
| 59 | + * Get content encryption key. |
|
| 60 | + * |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public function cek(): string |
|
| 64 | + { |
|
| 65 | + return $this->_cek; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * {@inheritdoc} |
|
| 70 | - */ |
|
| 71 | - public function cekForEncryption(int $length): string |
|
| 72 | - { |
|
| 73 | - if (strlen($this->_cek) !== $length) { |
|
| 74 | - throw new \UnexpectedValueException('Invalid key length.'); |
|
| 75 | - } |
|
| 76 | - return $this->_cek; |
|
| 77 | - } |
|
| 68 | + /** |
|
| 69 | + * {@inheritdoc} |
|
| 70 | + */ |
|
| 71 | + public function cekForEncryption(int $length): string |
|
| 72 | + { |
|
| 73 | + if (strlen($this->_cek) !== $length) { |
|
| 74 | + throw new \UnexpectedValueException('Invalid key length.'); |
|
| 75 | + } |
|
| 76 | + return $this->_cek; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * {@inheritdoc} |
|
| 81 | - */ |
|
| 82 | - public function algorithmParamValue(): string |
|
| 83 | - { |
|
| 84 | - return JWA::ALGO_DIR; |
|
| 85 | - } |
|
| 79 | + /** |
|
| 80 | + * {@inheritdoc} |
|
| 81 | + */ |
|
| 82 | + public function algorithmParamValue(): string |
|
| 83 | + { |
|
| 84 | + return JWA::ALGO_DIR; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * {@inheritdoc} |
|
| 89 | - */ |
|
| 90 | - public function headerParameters(): array |
|
| 91 | - { |
|
| 92 | - return array_merge(parent::headerParameters(), |
|
| 93 | - [AlgorithmParameter::fromAlgorithm($this)]); |
|
| 94 | - } |
|
| 87 | + /** |
|
| 88 | + * {@inheritdoc} |
|
| 89 | + */ |
|
| 90 | + public function headerParameters(): array |
|
| 91 | + { |
|
| 92 | + return array_merge(parent::headerParameters(), |
|
| 93 | + [AlgorithmParameter::fromAlgorithm($this)]); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * {@inheritdoc} |
|
| 98 | - */ |
|
| 99 | - protected function _encryptKey(string $key, Header &$header): string |
|
| 100 | - { |
|
| 101 | - if ($key !== $this->_cek) { |
|
| 102 | - throw new \LogicException("Content encryption key doesn't match."); |
|
| 103 | - } |
|
| 104 | - return ''; |
|
| 105 | - } |
|
| 96 | + /** |
|
| 97 | + * {@inheritdoc} |
|
| 98 | + */ |
|
| 99 | + protected function _encryptKey(string $key, Header &$header): string |
|
| 100 | + { |
|
| 101 | + if ($key !== $this->_cek) { |
|
| 102 | + throw new \LogicException("Content encryption key doesn't match."); |
|
| 103 | + } |
|
| 104 | + return ''; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * {@inheritdoc} |
|
| 109 | - */ |
|
| 110 | - protected function _decryptKey(string $ciphertext, Header $header): string |
|
| 111 | - { |
|
| 112 | - if ('' !== $ciphertext) { |
|
| 113 | - throw new \UnexpectedValueException( |
|
| 114 | - 'Encrypted key must be an empty octet sequence.'); |
|
| 115 | - } |
|
| 116 | - return $this->_cek; |
|
| 117 | - } |
|
| 107 | + /** |
|
| 108 | + * {@inheritdoc} |
|
| 109 | + */ |
|
| 110 | + protected function _decryptKey(string $ciphertext, Header $header): string |
|
| 111 | + { |
|
| 112 | + if ('' !== $ciphertext) { |
|
| 113 | + throw new \UnexpectedValueException( |
|
| 114 | + 'Encrypted key must be an empty octet sequence.'); |
|
| 115 | + } |
|
| 116 | + return $this->_cek; |
|
| 117 | + } |
|
| 118 | 118 | } |
@@ -15,35 +15,35 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class PBES2HS512A256KWAlgorithm extends PBES2Algorithm |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * {@inheritdoc} |
|
| 20 | - */ |
|
| 21 | - public function algorithmParamValue(): string |
|
| 22 | - { |
|
| 23 | - return JWA::ALGO_PBES2_HS512_A256KW; |
|
| 24 | - } |
|
| 18 | + /** |
|
| 19 | + * {@inheritdoc} |
|
| 20 | + */ |
|
| 21 | + public function algorithmParamValue(): string |
|
| 22 | + { |
|
| 23 | + return JWA::ALGO_PBES2_HS512_A256KW; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * {@inheritdoc} |
|
| 28 | - */ |
|
| 29 | - protected function _hashAlgo(): string |
|
| 30 | - { |
|
| 31 | - return 'sha512'; |
|
| 32 | - } |
|
| 26 | + /** |
|
| 27 | + * {@inheritdoc} |
|
| 28 | + */ |
|
| 29 | + protected function _hashAlgo(): string |
|
| 30 | + { |
|
| 31 | + return 'sha512'; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * {@inheritdoc} |
|
| 36 | - */ |
|
| 37 | - protected function _keyLength(): int |
|
| 38 | - { |
|
| 39 | - return 32; |
|
| 40 | - } |
|
| 34 | + /** |
|
| 35 | + * {@inheritdoc} |
|
| 36 | + */ |
|
| 37 | + protected function _keyLength(): int |
|
| 38 | + { |
|
| 39 | + return 32; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * {@inheritdoc} |
|
| 44 | - */ |
|
| 45 | - protected function _kwAlgo(): AESKeyWrapAlgorithm |
|
| 46 | - { |
|
| 47 | - return new AESKW256(); |
|
| 48 | - } |
|
| 42 | + /** |
|
| 43 | + * {@inheritdoc} |
|
| 44 | + */ |
|
| 45 | + protected function _kwAlgo(): AESKeyWrapAlgorithm |
|
| 46 | + { |
|
| 47 | + return new AESKW256(); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -13,19 +13,19 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class RSAESPKCS1Algorithm extends RSAESKeyAlgorithm |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * {@inheritdoc} |
|
| 18 | - */ |
|
| 19 | - public function algorithmParamValue(): string |
|
| 20 | - { |
|
| 21 | - return JWA::ALGO_RSA1_5; |
|
| 22 | - } |
|
| 16 | + /** |
|
| 17 | + * {@inheritdoc} |
|
| 18 | + */ |
|
| 19 | + public function algorithmParamValue(): string |
|
| 20 | + { |
|
| 21 | + return JWA::ALGO_RSA1_5; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * {@inheritdoc} |
|
| 26 | - */ |
|
| 27 | - protected function _paddingScheme(): int |
|
| 28 | - { |
|
| 29 | - return OPENSSL_PKCS1_PADDING; |
|
| 30 | - } |
|
| 24 | + /** |
|
| 25 | + * {@inheritdoc} |
|
| 26 | + */ |
|
| 27 | + protected function _paddingScheme(): int |
|
| 28 | + { |
|
| 29 | + return OPENSSL_PKCS1_PADDING; |
|
| 30 | + } |
|
| 31 | 31 | } |
@@ -15,27 +15,27 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class A256KWAlgorithm extends AESKWAlgorithm |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * {@inheritdoc} |
|
| 20 | - */ |
|
| 21 | - public function algorithmParamValue(): string |
|
| 22 | - { |
|
| 23 | - return JWA::ALGO_A256KW; |
|
| 24 | - } |
|
| 18 | + /** |
|
| 19 | + * {@inheritdoc} |
|
| 20 | + */ |
|
| 21 | + public function algorithmParamValue(): string |
|
| 22 | + { |
|
| 23 | + return JWA::ALGO_A256KW; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * {@inheritdoc} |
|
| 28 | - */ |
|
| 29 | - protected function _kekSize(): int |
|
| 30 | - { |
|
| 31 | - return 32; |
|
| 32 | - } |
|
| 26 | + /** |
|
| 27 | + * {@inheritdoc} |
|
| 28 | + */ |
|
| 29 | + protected function _kekSize(): int |
|
| 30 | + { |
|
| 31 | + return 32; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * {@inheritdoc} |
|
| 36 | - */ |
|
| 37 | - protected function _AESKWAlgo(): AESKeyWrapAlgorithm |
|
| 38 | - { |
|
| 39 | - return new AESKW256(); |
|
| 40 | - } |
|
| 34 | + /** |
|
| 35 | + * {@inheritdoc} |
|
| 36 | + */ |
|
| 37 | + protected function _AESKWAlgo(): AESKeyWrapAlgorithm |
|
| 38 | + { |
|
| 39 | + return new AESKW256(); |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -15,35 +15,35 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class PBES2HS384A192KWAlgorithm extends PBES2Algorithm |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * {@inheritdoc} |
|
| 20 | - */ |
|
| 21 | - public function algorithmParamValue(): string |
|
| 22 | - { |
|
| 23 | - return JWA::ALGO_PBES2_HS384_A192KW; |
|
| 24 | - } |
|
| 18 | + /** |
|
| 19 | + * {@inheritdoc} |
|
| 20 | + */ |
|
| 21 | + public function algorithmParamValue(): string |
|
| 22 | + { |
|
| 23 | + return JWA::ALGO_PBES2_HS384_A192KW; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * {@inheritdoc} |
|
| 28 | - */ |
|
| 29 | - protected function _hashAlgo(): string |
|
| 30 | - { |
|
| 31 | - return 'sha384'; |
|
| 32 | - } |
|
| 26 | + /** |
|
| 27 | + * {@inheritdoc} |
|
| 28 | + */ |
|
| 29 | + protected function _hashAlgo(): string |
|
| 30 | + { |
|
| 31 | + return 'sha384'; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * {@inheritdoc} |
|
| 36 | - */ |
|
| 37 | - protected function _keyLength(): int |
|
| 38 | - { |
|
| 39 | - return 24; |
|
| 40 | - } |
|
| 34 | + /** |
|
| 35 | + * {@inheritdoc} |
|
| 36 | + */ |
|
| 37 | + protected function _keyLength(): int |
|
| 38 | + { |
|
| 39 | + return 24; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * {@inheritdoc} |
|
| 44 | - */ |
|
| 45 | - protected function _kwAlgo(): AESKeyWrapAlgorithm |
|
| 46 | - { |
|
| 47 | - return new AESKW192(); |
|
| 48 | - } |
|
| 42 | + /** |
|
| 43 | + * {@inheritdoc} |
|
| 44 | + */ |
|
| 45 | + protected function _kwAlgo(): AESKeyWrapAlgorithm |
|
| 46 | + { |
|
| 47 | + return new AESKW192(); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -13,19 +13,19 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class RSAESOAEPAlgorithm extends RSAESKeyAlgorithm |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * {@inheritdoc} |
|
| 18 | - */ |
|
| 19 | - public function algorithmParamValue(): string |
|
| 20 | - { |
|
| 21 | - return JWA::ALGO_RSA_OAEP; |
|
| 22 | - } |
|
| 16 | + /** |
|
| 17 | + * {@inheritdoc} |
|
| 18 | + */ |
|
| 19 | + public function algorithmParamValue(): string |
|
| 20 | + { |
|
| 21 | + return JWA::ALGO_RSA_OAEP; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * {@inheritdoc} |
|
| 26 | - */ |
|
| 27 | - protected function _paddingScheme(): int |
|
| 28 | - { |
|
| 29 | - return OPENSSL_PKCS1_OAEP_PADDING; |
|
| 30 | - } |
|
| 24 | + /** |
|
| 25 | + * {@inheritdoc} |
|
| 26 | + */ |
|
| 27 | + protected function _paddingScheme(): int |
|
| 28 | + { |
|
| 29 | + return OPENSSL_PKCS1_OAEP_PADDING; |
|
| 30 | + } |
|
| 31 | 31 | } |
@@ -15,94 +15,94 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class KeyAlgorithmFactory |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Mapping from algorithm name to class name. |
|
| 20 | - * |
|
| 21 | - * @internal |
|
| 22 | - * |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - const MAP_ALGO_TO_CLASS = [ |
|
| 26 | - JWA::ALGO_A128KW => A128KWAlgorithm::class, |
|
| 27 | - JWA::ALGO_A192KW => A192KWAlgorithm::class, |
|
| 28 | - JWA::ALGO_A128KW => A256KWAlgorithm::class, |
|
| 29 | - JWA::ALGO_A128GCMKW => A128GCMKWAlgorithm::class, |
|
| 30 | - JWA::ALGO_A192GCMKW => A192GCMKWAlgorithm::class, |
|
| 31 | - JWA::ALGO_A256GCMKW => A256GCMKWAlgorithm::class, |
|
| 32 | - JWA::ALGO_PBES2_HS256_A128KW => PBES2HS256A128KWAlgorithm::class, |
|
| 33 | - JWA::ALGO_PBES2_HS384_A192KW => PBES2HS384A192KWAlgorithm::class, |
|
| 34 | - JWA::ALGO_PBES2_HS512_A256KW => PBES2HS512A256KWAlgorithm::class, |
|
| 35 | - JWA::ALGO_DIR => DirectCEKAlgorithm::class, |
|
| 36 | - JWA::ALGO_RSA1_5 => RSAESPKCS1Algorithm::class, |
|
| 37 | - JWA::ALGO_RSA_OAEP => RSAESOAEPAlgorithm::class, |
|
| 38 | - ]; |
|
| 39 | - /** |
|
| 40 | - * Header. |
|
| 41 | - * |
|
| 42 | - * @var Header |
|
| 43 | - */ |
|
| 44 | - protected $_header; |
|
| 18 | + /** |
|
| 19 | + * Mapping from algorithm name to class name. |
|
| 20 | + * |
|
| 21 | + * @internal |
|
| 22 | + * |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + const MAP_ALGO_TO_CLASS = [ |
|
| 26 | + JWA::ALGO_A128KW => A128KWAlgorithm::class, |
|
| 27 | + JWA::ALGO_A192KW => A192KWAlgorithm::class, |
|
| 28 | + JWA::ALGO_A128KW => A256KWAlgorithm::class, |
|
| 29 | + JWA::ALGO_A128GCMKW => A128GCMKWAlgorithm::class, |
|
| 30 | + JWA::ALGO_A192GCMKW => A192GCMKWAlgorithm::class, |
|
| 31 | + JWA::ALGO_A256GCMKW => A256GCMKWAlgorithm::class, |
|
| 32 | + JWA::ALGO_PBES2_HS256_A128KW => PBES2HS256A128KWAlgorithm::class, |
|
| 33 | + JWA::ALGO_PBES2_HS384_A192KW => PBES2HS384A192KWAlgorithm::class, |
|
| 34 | + JWA::ALGO_PBES2_HS512_A256KW => PBES2HS512A256KWAlgorithm::class, |
|
| 35 | + JWA::ALGO_DIR => DirectCEKAlgorithm::class, |
|
| 36 | + JWA::ALGO_RSA1_5 => RSAESPKCS1Algorithm::class, |
|
| 37 | + JWA::ALGO_RSA_OAEP => RSAESOAEPAlgorithm::class, |
|
| 38 | + ]; |
|
| 39 | + /** |
|
| 40 | + * Header. |
|
| 41 | + * |
|
| 42 | + * @var Header |
|
| 43 | + */ |
|
| 44 | + protected $_header; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Constructor. |
|
| 48 | - * |
|
| 49 | - * @param Header $header |
|
| 50 | - */ |
|
| 51 | - public function __construct(Header $header) |
|
| 52 | - { |
|
| 53 | - $this->_header = $header; |
|
| 54 | - } |
|
| 46 | + /** |
|
| 47 | + * Constructor. |
|
| 48 | + * |
|
| 49 | + * @param Header $header |
|
| 50 | + */ |
|
| 51 | + public function __construct(Header $header) |
|
| 52 | + { |
|
| 53 | + $this->_header = $header; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Get key management algorithm by given JWK. |
|
| 58 | - * |
|
| 59 | - * @param JWK $jwk |
|
| 60 | - * |
|
| 61 | - * @return KeyManagementAlgorithm |
|
| 62 | - */ |
|
| 63 | - public function algoByKey(JWK $jwk): KeyManagementAlgorithm |
|
| 64 | - { |
|
| 65 | - $alg = JWA::deriveAlgorithmName($this->_header, $jwk); |
|
| 66 | - $cls = self::_algoClassByName($alg); |
|
| 67 | - return $cls::fromJWK($jwk, $this->_header); |
|
| 68 | - } |
|
| 56 | + /** |
|
| 57 | + * Get key management algorithm by given JWK. |
|
| 58 | + * |
|
| 59 | + * @param JWK $jwk |
|
| 60 | + * |
|
| 61 | + * @return KeyManagementAlgorithm |
|
| 62 | + */ |
|
| 63 | + public function algoByKey(JWK $jwk): KeyManagementAlgorithm |
|
| 64 | + { |
|
| 65 | + $alg = JWA::deriveAlgorithmName($this->_header, $jwk); |
|
| 66 | + $cls = self::_algoClassByName($alg); |
|
| 67 | + return $cls::fromJWK($jwk, $this->_header); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Get key management algorithm using a matching key from given JWK set. |
|
| 72 | - * |
|
| 73 | - * @param JWKSet $set |
|
| 74 | - * |
|
| 75 | - * @throws \UnexpectedValueException If a key cannot be found |
|
| 76 | - * |
|
| 77 | - * @return KeyManagementAlgorithm |
|
| 78 | - */ |
|
| 79 | - public function algoByKeys(JWKSet $set): KeyManagementAlgorithm |
|
| 80 | - { |
|
| 81 | - if (!$this->_header->hasKeyID()) { |
|
| 82 | - throw new \UnexpectedValueException('No key ID paremeter.'); |
|
| 83 | - } |
|
| 84 | - $id = $this->_header->keyID()->value(); |
|
| 85 | - if (!$set->hasKeyID($id)) { |
|
| 86 | - throw new \UnexpectedValueException("No key for ID '{$id}'."); |
|
| 87 | - } |
|
| 88 | - return $this->algoByKey($set->keyByID($id)); |
|
| 89 | - } |
|
| 70 | + /** |
|
| 71 | + * Get key management algorithm using a matching key from given JWK set. |
|
| 72 | + * |
|
| 73 | + * @param JWKSet $set |
|
| 74 | + * |
|
| 75 | + * @throws \UnexpectedValueException If a key cannot be found |
|
| 76 | + * |
|
| 77 | + * @return KeyManagementAlgorithm |
|
| 78 | + */ |
|
| 79 | + public function algoByKeys(JWKSet $set): KeyManagementAlgorithm |
|
| 80 | + { |
|
| 81 | + if (!$this->_header->hasKeyID()) { |
|
| 82 | + throw new \UnexpectedValueException('No key ID paremeter.'); |
|
| 83 | + } |
|
| 84 | + $id = $this->_header->keyID()->value(); |
|
| 85 | + if (!$set->hasKeyID($id)) { |
|
| 86 | + throw new \UnexpectedValueException("No key for ID '{$id}'."); |
|
| 87 | + } |
|
| 88 | + return $this->algoByKey($set->keyByID($id)); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Get the algorithm implementation class name by an algorithm name. |
|
| 93 | - * |
|
| 94 | - * @param string $alg Algorithm name |
|
| 95 | - * |
|
| 96 | - * @throws \UnexpectedValueException |
|
| 97 | - * |
|
| 98 | - * @return string Class name |
|
| 99 | - */ |
|
| 100 | - private static function _algoClassByName(string $alg): string |
|
| 101 | - { |
|
| 102 | - if (!array_key_exists($alg, self::MAP_ALGO_TO_CLASS)) { |
|
| 103 | - throw new \UnexpectedValueException( |
|
| 104 | - "Algorithm '{$alg}' not supported."); |
|
| 105 | - } |
|
| 106 | - return self::MAP_ALGO_TO_CLASS[$alg]; |
|
| 107 | - } |
|
| 91 | + /** |
|
| 92 | + * Get the algorithm implementation class name by an algorithm name. |
|
| 93 | + * |
|
| 94 | + * @param string $alg Algorithm name |
|
| 95 | + * |
|
| 96 | + * @throws \UnexpectedValueException |
|
| 97 | + * |
|
| 98 | + * @return string Class name |
|
| 99 | + */ |
|
| 100 | + private static function _algoClassByName(string $alg): string |
|
| 101 | + { |
|
| 102 | + if (!array_key_exists($alg, self::MAP_ALGO_TO_CLASS)) { |
|
| 103 | + throw new \UnexpectedValueException( |
|
| 104 | + "Algorithm '{$alg}' not supported."); |
|
| 105 | + } |
|
| 106 | + return self::MAP_ALGO_TO_CLASS[$alg]; |
|
| 107 | + } |
|
| 108 | 108 | } |
@@ -12,21 +12,21 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | interface CompressionAlgorithm extends CompressionAlgorithmParameterValue, HeaderParameters |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Compress data. |
|
| 17 | - * |
|
| 18 | - * @param string $data Uncompressed data |
|
| 19 | - * |
|
| 20 | - * @return string Compressed data |
|
| 21 | - */ |
|
| 22 | - public function compress(string $data): string; |
|
| 15 | + /** |
|
| 16 | + * Compress data. |
|
| 17 | + * |
|
| 18 | + * @param string $data Uncompressed data |
|
| 19 | + * |
|
| 20 | + * @return string Compressed data |
|
| 21 | + */ |
|
| 22 | + public function compress(string $data): string; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Decompress data. |
|
| 26 | - * |
|
| 27 | - * @param string $data Compressed data |
|
| 28 | - * |
|
| 29 | - * @return string Uncompressed data |
|
| 30 | - */ |
|
| 31 | - public function decompress(string $data): string; |
|
| 24 | + /** |
|
| 25 | + * Decompress data. |
|
| 26 | + * |
|
| 27 | + * @param string $data Compressed data |
|
| 28 | + * |
|
| 29 | + * @return string Uncompressed data |
|
| 30 | + */ |
|
| 31 | + public function decompress(string $data): string; |
|
| 32 | 32 | } |