This repository has been archived by the owner on Dec 30, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugs fixed and Add Key command added
- Loading branch information
Showing
11 changed files
with
127 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2014-2017 Spomky-Labs | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
namespace Jose\Component\Console; | ||
|
||
use Jose\Component\Core\Converter\JsonConverterInterface; | ||
use Jose\Component\Core\JWK; | ||
use Jose\Component\Core\JWKSet; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Class AddKeyIntoKeysetCommand. | ||
*/ | ||
final class AddKeyIntoKeysetCommand extends AbstractObjectOutputCommand | ||
{ | ||
/** | ||
* KeyAnalyzerCommand constructor. | ||
* | ||
* @param JsonConverterInterface $jsonConverter | ||
* @param string|null $name | ||
*/ | ||
public function __construct(JsonConverterInterface $jsonConverter, string $name = null) | ||
{ | ||
parent::__construct($jsonConverter, $name); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
parent::configure(); | ||
$this | ||
->setName('keyset:add:key') | ||
->setDescription('Add a key into a key set.') | ||
->setHelp('This command adds a key at the end of a key set.') | ||
->addArgument('jwkset', InputArgument::REQUIRED, 'The JWKSet object') | ||
->addArgument('jwk', InputArgument::REQUIRED, 'The new JWK object') | ||
; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$jwkset = $this->getKeyset($input); | ||
$jwk = $this->getKey($input); | ||
$jwkset = $jwkset->with($jwk); | ||
$this->prepareJsonOutput($input, $output,$jwkset); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* | ||
* @return JWKSet | ||
*/ | ||
private function getKeyset(InputInterface $input): JWKSet | ||
{ | ||
$jwkset = $input->getArgument('jwkset'); | ||
$json = $this->jsonConverter->decode($jwkset); | ||
if (is_array($json)) { | ||
return JWKSet::createFromKeyData($json); | ||
} | ||
|
||
throw new \InvalidArgumentException('The argument must be a valid JWKSet.'); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* | ||
* @return JWK | ||
*/ | ||
private function getKey(InputInterface $input): JWK | ||
{ | ||
$jwkset = $input->getArgument('jwk'); | ||
$json = $this->jsonConverter->decode($jwkset); | ||
if (is_array($json)) { | ||
return JWK::create($json); | ||
} | ||
|
||
throw new \InvalidArgumentException('The argument must be a valid JWK.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters