Skip to content

Commit a437a1a

Browse files
committed
Add KMS getPublicKey and verify
1 parent 908f674 commit a437a1a

File tree

5 files changed

+781
-0
lines changed

5 files changed

+781
-0
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?php
2+
3+
namespace AsyncAws\Kms\Input;
4+
5+
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\Core\Input;
7+
use AsyncAws\Core\Request;
8+
use AsyncAws\Core\Stream\StreamFactory;
9+
use function sprintf;
10+
11+
final class GetPublicKeyRequest extends Input
12+
{
13+
/**
14+
* Identifies an asymmetric KMS key. KMS uses the private key in the asymmetric KMS key to sign the message. The
15+
* `KeyUsage` type of the KMS key must be `SIGN_VERIFY`. To find the `KeyUsage` of a KMS key, use the DescribeKey
16+
* operation.
17+
*
18+
* To specify a KMS key, use its key ID, key ARN, alias name, or alias ARN. When using an alias name, prefix it with
19+
* `"alias/"`. To specify a KMS key in a different Amazon Web Services account, you must use the key ARN or alias ARN.
20+
*
21+
* For example:
22+
*
23+
* - Key ID: `1234abcd-12ab-34cd-56ef-1234567890ab`
24+
* - Key ARN: `arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab`
25+
* - Alias name: `alias/ExampleAlias`
26+
* - Alias ARN: `arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias`
27+
*
28+
* To get the key ID and key ARN for a KMS key, use ListKeys or DescribeKey. To get the alias name and alias ARN, use
29+
* ListAliases.
30+
*
31+
* @var string|null
32+
*/
33+
private $keyId;
34+
35+
/**
36+
* A list of grant tokens.
37+
*
38+
* Use a grant token when your permission to call this operation comes from a new grant that has not yet achieved
39+
* *eventual consistency*. For more information, see Grant token [^1] and Using a grant token [^2] in the *Key
40+
* Management Service Developer Guide*.
41+
*
42+
* [^1]: https://docs.aws.amazon.com/kms/latest/developerguide/grants.html#grant_token
43+
* [^2]: https://docs.aws.amazon.com/kms/latest/developerguide/grant-manage.html#using-grant-token
44+
*
45+
* @var string[]|null
46+
*/
47+
private $grantTokens;
48+
49+
/**
50+
* @param array{
51+
* KeyId?: string,
52+
* GrantTokens?: null|string[],
53+
* } $input
54+
*/
55+
public function __construct(array $input = [])
56+
{
57+
$this->keyId = $input['KeyId'] ?? null;
58+
$this->grantTokens = $input['GrantTokens'] ?? null;
59+
parent::__construct($input);
60+
}
61+
62+
/**
63+
* @param array{
64+
* KeyId?: string,
65+
* GrantTokens?: null|string[]
66+
* }|GetPublicKeyRequest $input
67+
*/
68+
public static function create($input): self
69+
{
70+
return $input instanceof self ? $input : new self($input);
71+
}
72+
73+
/**
74+
* @return string[]
75+
*/
76+
public function getGrantTokens(): array
77+
{
78+
return $this->grantTokens ?? [];
79+
}
80+
81+
public function getKeyId(): ?string
82+
{
83+
return $this->keyId;
84+
}
85+
86+
/**
87+
* @internal
88+
*/
89+
public function request(): Request
90+
{
91+
// Prepare headers
92+
$headers = [
93+
'Content-Type' => 'application/x-amz-json-1.1',
94+
'X-Amz-Target' => 'TrentService.GetPublicKey',
95+
'Accept' => 'application/json',
96+
];
97+
98+
// Prepare query
99+
$query = [];
100+
101+
// Prepare URI
102+
$uriString = '/';
103+
104+
// Prepare Body
105+
$bodyPayload = $this->requestBody();
106+
$body = empty($bodyPayload) ? '{}' : json_encode($bodyPayload, 4194304);
107+
108+
// Return the Request
109+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body));
110+
}
111+
112+
/**
113+
* @param string[] $value
114+
*/
115+
public function setGrantTokens(array $value): self
116+
{
117+
$this->grantTokens = $value;
118+
119+
return $this;
120+
}
121+
122+
public function setKeyId(?string $value): self
123+
{
124+
$this->keyId = $value;
125+
126+
return $this;
127+
}
128+
129+
private function requestBody(): array
130+
{
131+
$payload = [];
132+
if (null === $v = $this->keyId) {
133+
throw new InvalidArgument(sprintf(
134+
'Missing parameter "KeyId" for "%s". The value cannot be null.',
135+
self::class
136+
));
137+
}
138+
$payload['KeyId'] = $v;
139+
if (null !== $v = $this->grantTokens) {
140+
$index = -1;
141+
$payload['GrantTokens'] = [];
142+
foreach ($v as $listValue) {
143+
++$index;
144+
$payload['GrantTokens'][$index] = $listValue;
145+
}
146+
}
147+
return $payload;
148+
}
149+
}

0 commit comments

Comments
 (0)