Debian Codegraph @

lib/3rdParty/composer/web-token/jwt-library/Console/X509CertificateLoaderCommand.php

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