Debian Codegraph @

lib/3rdParty/composer/web-token/jwt-library/Console/EcKeyGeneratorCommand.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:generate:ec', description: 'Generate an EC key (JWK format)',)]
16 final class EcKeyGeneratorCommand extends GeneratorCommand
17 {
18 protected static $defaultName = 'key:generate:ec';
19
20 protected static $defaultDescription = 'Generate an EC key (JWK format)';
21
22 protected function configure(): void
23 {
24 parent::configure();
25 $this->addArgument('curve', InputArgument::REQUIRED, 'Curve of the key.');
26 }
27
28 protected function execute(InputInterface $input, OutputInterface $output): int
29 {
30 $curve = $input->getArgument('curve');
31 if (! is_string($curve)) {
32 throw new InvalidArgumentException('Invalid curve');
33 }
34 $args = $this->getOptions($input);
35
36 $jwk = JWKFactory::createECKey($curve, $args);
37 $this->prepareJsonOutput($input, $output, $jwk);
38
39 return self::SUCCESS;
40 }
41 }