|
11 | 11 |
|
12 | 12 | namespace AcmePhp\Ssl\Generator\RsaKey; |
13 | 13 |
|
14 | | -use AcmePhp\Ssl\Exception\KeyGenerationException; |
15 | | -use AcmePhp\Ssl\Exception\KeyPairGenerationException; |
16 | 14 | use AcmePhp\Ssl\Generator\KeyOption; |
| 15 | +use AcmePhp\Ssl\Generator\OpensslPrivateKeyGeneratorTrait; |
17 | 16 | use AcmePhp\Ssl\Generator\PrivateKeyGeneratorInterface; |
18 | | -use AcmePhp\Ssl\PrivateKey; |
19 | 17 | use Webmozart\Assert\Assert; |
20 | 18 |
|
21 | 19 | /** |
|
25 | 23 | */ |
26 | 24 | class RsaKeyGenerator implements PrivateKeyGeneratorInterface |
27 | 25 | { |
| 26 | + use OpensslPrivateKeyGeneratorTrait; |
| 27 | + |
28 | 28 | /** |
29 | 29 | * @param RsaKeyOption|KeyOption $keyOption |
30 | 30 | */ |
31 | 31 | public function generatePrivateKey(KeyOption $keyOption) |
32 | 32 | { |
33 | 33 | Assert::isInstanceOf($keyOption, RsaKeyOption::class); |
34 | 34 |
|
35 | | - $resource = openssl_pkey_new( |
| 35 | + return $this->generatePrivateKeyFromOpensslOptions( |
36 | 36 | [ |
37 | 37 | 'private_key_type' => OPENSSL_KEYTYPE_RSA, |
38 | 38 | 'private_key_bits' => $keyOption->getBits(), |
39 | 39 | ] |
40 | 40 | ); |
41 | | - |
42 | | - if (!$resource) { |
43 | | - throw new KeyGenerationException( |
44 | | - sprintf('OpenSSL key creation failed during generation with error: %s', openssl_error_string()) |
45 | | - ); |
46 | | - } |
47 | | - if (!openssl_pkey_export($resource, $privateKey)) { |
48 | | - throw new KeyPairGenerationException( |
49 | | - sprintf('OpenSSL key export failed during generation with error: %s', openssl_error_string()) |
50 | | - ); |
51 | | - } |
52 | | - |
53 | | - return new PrivateKey($privateKey); |
54 | 41 | } |
55 | 42 |
|
56 | 43 | public function supportsKeyOption(KeyOption $keyOption) |
|
0 commit comments