-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
X509CertificateLoaderCommand.php
45 lines (37 loc) · 1.28 KB
/
X509CertificateLoaderCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
declare(strict_types=1);
namespace Jose\Component\Console;
use InvalidArgumentException;
use function is_string;
use Jose\Component\KeyManagement\JWKFactory;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
final class X509CertificateLoaderCommand extends GeneratorCommand
{
protected static $defaultName = 'key:load:x509';
protected function configure(): void
{
parent::configure();
$this->setDescription('Load a key from a X.509 certificate file.')
->addArgument('file', InputArgument::REQUIRED, 'Filename of the X.509 certificate.')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$file = $input->getArgument('file');
if (! is_string($file)) {
throw new InvalidArgumentException('Invalid file');
}
$args = [];
foreach (['use', 'alg'] as $key) {
$value = $input->getOption($key);
if ($value !== null) {
$args[$key] = $value;
}
}
$jwk = JWKFactory::createFromCertificateFile($file, $args);
$this->prepareJsonOutput($input, $output, $jwk);
return 0;
}
}