save
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Acme PHP project.
|
||||
*
|
||||
* (c) Titouan Galopin <galopintitouan@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace AcmePhp\Ssl\Generator\EcKey;
|
||||
|
||||
use AcmePhp\Ssl\Generator\KeyOption;
|
||||
use AcmePhp\Ssl\Generator\OpensslPrivateKeyGeneratorTrait;
|
||||
use AcmePhp\Ssl\Generator\PrivateKeyGeneratorInterface;
|
||||
use AcmePhp\Ssl\PrivateKey;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* Generate random EC private key using OpenSSL.
|
||||
*
|
||||
* @author Jérémy Derussé <jeremy@derusse.com>
|
||||
*/
|
||||
class EcKeyGenerator implements PrivateKeyGeneratorInterface
|
||||
{
|
||||
use OpensslPrivateKeyGeneratorTrait;
|
||||
|
||||
public function generatePrivateKey(KeyOption $keyOption): PrivateKey
|
||||
{
|
||||
Assert::isInstanceOf($keyOption, EcKeyOption::class);
|
||||
|
||||
return $this->generatePrivateKeyFromOpensslOptions([
|
||||
'private_key_type' => OPENSSL_KEYTYPE_EC,
|
||||
'curve_name' => $keyOption->getCurveName(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function supportsKeyOption(KeyOption $keyOption): bool
|
||||
{
|
||||
return $keyOption instanceof EcKeyOption;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Acme PHP project.
|
||||
*
|
||||
* (c) Titouan Galopin <galopintitouan@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace AcmePhp\Ssl\Generator\EcKey;
|
||||
|
||||
use AcmePhp\Ssl\Generator\KeyOption;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
class EcKeyOption implements KeyOption
|
||||
{
|
||||
/** @var string */
|
||||
private $curveName;
|
||||
|
||||
public function __construct(string $curveName = 'secp384r1')
|
||||
{
|
||||
Assert::oneOf($curveName, openssl_get_curve_names(), 'The given curve %s is not supported. Available curves are: %s');
|
||||
|
||||
$this->curveName = $curveName;
|
||||
}
|
||||
|
||||
public function getCurveName(): string
|
||||
{
|
||||
return $this->curveName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user