Skip to content

Commit 2e0a0aa

Browse files
committed
Ensure AES-KW library is available before cypher operation
1 parent ed863a6 commit 2e0a0aa

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

src/Library/Encryption/Algorithm/KeyEncryption/AESGCMKW.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Jose\Component\Encryption\Algorithm\KeyEncryption;
66

7+
use AESKW\Wrapper as WrapperInterface;
78
use InvalidArgumentException;
89
use Jose\Component\Core\JWK;
910
use ParagonIE\ConstantTime\Base64UrlSafe;
@@ -20,6 +21,9 @@ public function __construct()
2021
if (! extension_loaded('openssl')) {
2122
throw new RuntimeException('Please install the OpenSSL extension');
2223
}
24+
if (! interface_exists(WrapperInterface::class)) {
25+
throw new RuntimeException('Please install "spomky-labs/aes-key-wrap" to use AES-KW algorithms');
26+
}
2327
}
2428

2529
public function allowedKeyTypes(): array

src/Library/Encryption/Algorithm/KeyEncryption/AESKW.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,19 @@
88
use InvalidArgumentException;
99
use Jose\Component\Core\JWK;
1010
use ParagonIE\ConstantTime\Base64UrlSafe;
11+
use RuntimeException;
1112
use function in_array;
1213
use function is_string;
1314

1415
abstract class AESKW implements KeyWrapping
1516
{
17+
public function __construct()
18+
{
19+
if (! interface_exists(WrapperInterface::class)) {
20+
throw new RuntimeException('Please install "spomky-labs/aes-key-wrap" to use AES-KW algorithms');
21+
}
22+
}
23+
1624
public function allowedKeyTypes(): array
1725
{
1826
return ['oct'];

src/Library/Encryption/Algorithm/KeyEncryption/AbstractECDHAESKW.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44

55
namespace Jose\Component\Encryption\Algorithm\KeyEncryption;
66

7-
use AESKW\A128KW;
8-
use AESKW\A192KW;
9-
use AESKW\A256KW;
7+
use AESKW\Wrapper as WrapperInterface;
8+
use RuntimeException;
109

1110
abstract class AbstractECDHAESKW implements KeyAgreementWithKeyWrapping
1211
{
12+
public function __construct()
13+
{
14+
if (! interface_exists(WrapperInterface::class)) {
15+
throw new RuntimeException('Please install "spomky-labs/aes-key-wrap" to use AES-KW algorithms');
16+
}
17+
}
18+
1319
public function allowedKeyTypes(): array
1420
{
1521
return ['EC', 'OKP'];
@@ -20,7 +26,7 @@ public function getKeyManagementMode(): string
2026
return self::MODE_WRAP;
2127
}
2228

23-
abstract protected function getWrapper(): A128KW|A192KW|A256KW;
29+
abstract protected function getWrapper(): WrapperInterface;
2430

2531
abstract protected function getKeyLength(): int;
2632
}

src/Library/Encryption/Algorithm/KeyEncryption/PBES2AESKW.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
use AESKW\A128KW;
88
use AESKW\A192KW;
99
use AESKW\A256KW;
10+
use AESKW\Wrapper as WrapperInterface;
1011
use InvalidArgumentException;
1112
use Jose\Component\Core\JWK;
1213
use ParagonIE\ConstantTime\Base64UrlSafe;
14+
use RuntimeException;
1315
use function in_array;
1416
use function is_int;
1517
use function is_string;
@@ -20,6 +22,9 @@ public function __construct(
2022
private readonly int $salt_size = 64,
2123
private readonly int $nb_count = 4096
2224
) {
25+
if (! interface_exists(WrapperInterface::class)) {
26+
throw new RuntimeException('Please install "spomky-labs/aes-key-wrap" to use AES-KW algorithms');
27+
}
2328
}
2429

2530
public function allowedKeyTypes(): array

0 commit comments

Comments
 (0)