Debian Codegraph @

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