aws_sdk_kms/operation/encrypt/builders.rs
1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub use crate::operation::encrypt::_encrypt_output::EncryptOutputBuilder;
3
4pub use crate::operation::encrypt::_encrypt_input::EncryptInputBuilder;
5
6impl crate::operation::encrypt::builders::EncryptInputBuilder {
7 /// Sends a request with this input using the given client.
8 pub async fn send_with(
9 self,
10 client: &crate::Client,
11 ) -> ::std::result::Result<
12 crate::operation::encrypt::EncryptOutput,
13 ::aws_smithy_runtime_api::client::result::SdkError<
14 crate::operation::encrypt::EncryptError,
15 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
16 >,
17 > {
18 let mut fluent_builder = client.encrypt();
19 fluent_builder.inner = self;
20 fluent_builder.send().await
21 }
22}
23/// Fluent builder constructing a request to `Encrypt`.
24///
25/// <p>Encrypts plaintext of up to 4,096 bytes using a KMS key. You can use a symmetric or asymmetric KMS key with a <code>KeyUsage</code> of <code>ENCRYPT_DECRYPT</code>.</p>
26/// <p>You can use this operation to encrypt small amounts of arbitrary data, such as a personal identifier or database password, or other sensitive information. You don't need to use the <code>Encrypt</code> operation to encrypt a data key. The <code>GenerateDataKey</code> and <code>GenerateDataKeyPair</code> operations return a plaintext data key and an encrypted copy of that data key.</p>
27/// <p>If you use a symmetric encryption KMS key, you can use an encryption context to add additional security to your encryption operation. If you specify an <code>EncryptionContext</code> when encrypting data, you must specify the same encryption context (a case-sensitive exact match) when decrypting the data. Otherwise, the request to decrypt fails with an <code>InvalidCiphertextException</code>. For more information, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#encrypt_context">Encryption Context</a> in the <i>Key Management Service Developer Guide</i>.</p>
28/// <p>If you specify an asymmetric KMS key, you must also specify the encryption algorithm. The algorithm must be compatible with the KMS key spec.</p><important>
29/// <p>When you use an asymmetric KMS key to encrypt or reencrypt data, be sure to record the KMS key and encryption algorithm that you choose. You will be required to provide the same KMS key and encryption algorithm when you decrypt the data. If the KMS key and algorithm do not match the values used to encrypt the data, the decrypt operation fails.</p>
30/// <p>You are not required to supply the key ID and encryption algorithm when you decrypt with symmetric encryption KMS keys because KMS stores this information in the ciphertext blob. KMS cannot store metadata in ciphertext generated with asymmetric keys. The standard format for asymmetric key ciphertext does not include configurable fields.</p>
31/// </important>
32/// <p>The maximum size of the data that you can encrypt varies with the type of KMS key and the encryption algorithm that you choose.</p>
33/// <ul>
34/// <li>
35/// <p>Symmetric encryption KMS keys</p>
36/// <ul>
37/// <li>
38/// <p><code>SYMMETRIC_DEFAULT</code>: 4096 bytes</p></li>
39/// </ul></li>
40/// <li>
41/// <p><code>RSA_2048</code></p>
42/// <ul>
43/// <li>
44/// <p><code>RSAES_OAEP_SHA_1</code>: 214 bytes</p></li>
45/// <li>
46/// <p><code>RSAES_OAEP_SHA_256</code>: 190 bytes</p></li>
47/// </ul></li>
48/// <li>
49/// <p><code>RSA_3072</code></p>
50/// <ul>
51/// <li>
52/// <p><code>RSAES_OAEP_SHA_1</code>: 342 bytes</p></li>
53/// <li>
54/// <p><code>RSAES_OAEP_SHA_256</code>: 318 bytes</p></li>
55/// </ul></li>
56/// <li>
57/// <p><code>RSA_4096</code></p>
58/// <ul>
59/// <li>
60/// <p><code>RSAES_OAEP_SHA_1</code>: 470 bytes</p></li>
61/// <li>
62/// <p><code>RSAES_OAEP_SHA_256</code>: 446 bytes</p></li>
63/// </ul></li>
64/// <li>
65/// <p><code>SM2PKE</code>: 1024 bytes (China Regions only)</p></li>
66/// </ul>
67/// <p>The KMS key that you use for this operation must be in a compatible key state. For details, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html">Key states of KMS keys</a> in the <i>Key Management Service Developer Guide</i>.</p>
68/// <p><b>Cross-account use</b>: Yes. To perform this operation with a KMS key in a different Amazon Web Services account, specify the key ARN or alias ARN in the value of the <code>KeyId</code> parameter.</p>
69/// <p><b>Required permissions</b>: <a href="https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html">kms:Encrypt</a> (key policy)</p>
70/// <p><b>Related operations:</b></p>
71/// <ul>
72/// <li>
73/// <p><code>Decrypt</code></p></li>
74/// <li>
75/// <p><code>GenerateDataKey</code></p></li>
76/// <li>
77/// <p><code>GenerateDataKeyPair</code></p></li>
78/// </ul>
79/// <p><b>Eventual consistency</b>: The KMS API follows an eventual consistency model. For more information, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/programming-eventual-consistency.html">KMS eventual consistency</a>.</p>
80#[derive(::std::clone::Clone, ::std::fmt::Debug)]
81pub struct EncryptFluentBuilder {
82 handle: ::std::sync::Arc<crate::client::Handle>,
83 inner: crate::operation::encrypt::builders::EncryptInputBuilder,
84 config_override: ::std::option::Option<crate::config::Builder>,
85}
86impl crate::client::customize::internal::CustomizableSend<crate::operation::encrypt::EncryptOutput, crate::operation::encrypt::EncryptError>
87 for EncryptFluentBuilder
88{
89 fn send(
90 self,
91 config_override: crate::config::Builder,
92 ) -> crate::client::customize::internal::BoxFuture<
93 crate::client::customize::internal::SendResult<crate::operation::encrypt::EncryptOutput, crate::operation::encrypt::EncryptError>,
94 > {
95 ::std::boxed::Box::pin(async move { self.config_override(config_override).send().await })
96 }
97}
98impl EncryptFluentBuilder {
99 /// Creates a new `EncryptFluentBuilder`.
100 pub(crate) fn new(handle: ::std::sync::Arc<crate::client::Handle>) -> Self {
101 Self {
102 handle,
103 inner: ::std::default::Default::default(),
104 config_override: ::std::option::Option::None,
105 }
106 }
107 /// Access the Encrypt as a reference.
108 pub fn as_input(&self) -> &crate::operation::encrypt::builders::EncryptInputBuilder {
109 &self.inner
110 }
111 /// Sends the request and returns the response.
112 ///
113 /// If an error occurs, an `SdkError` will be returned with additional details that
114 /// can be matched against.
115 ///
116 /// By default, any retryable failures will be retried twice. Retry behavior
117 /// is configurable with the [RetryConfig](aws_smithy_types::retry::RetryConfig), which can be
118 /// set when configuring the client.
119 pub async fn send(
120 self,
121 ) -> ::std::result::Result<
122 crate::operation::encrypt::EncryptOutput,
123 ::aws_smithy_runtime_api::client::result::SdkError<
124 crate::operation::encrypt::EncryptError,
125 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
126 >,
127 > {
128 let input = self
129 .inner
130 .build()
131 .map_err(::aws_smithy_runtime_api::client::result::SdkError::construction_failure)?;
132 let runtime_plugins = crate::operation::encrypt::Encrypt::operation_runtime_plugins(
133 self.handle.runtime_plugins.clone(),
134 &self.handle.conf,
135 self.config_override,
136 );
137 crate::operation::encrypt::Encrypt::orchestrate(&runtime_plugins, input).await
138 }
139
140 /// Consumes this builder, creating a customizable operation that can be modified before being sent.
141 pub fn customize(
142 self,
143 ) -> crate::client::customize::CustomizableOperation<crate::operation::encrypt::EncryptOutput, crate::operation::encrypt::EncryptError, Self>
144 {
145 crate::client::customize::CustomizableOperation::new(self)
146 }
147 pub(crate) fn config_override(mut self, config_override: impl ::std::convert::Into<crate::config::Builder>) -> Self {
148 self.set_config_override(::std::option::Option::Some(config_override.into()));
149 self
150 }
151
152 pub(crate) fn set_config_override(&mut self, config_override: ::std::option::Option<crate::config::Builder>) -> &mut Self {
153 self.config_override = config_override;
154 self
155 }
156 /// <p>Identifies the KMS key to use in the encryption operation. The KMS key must have a <code>KeyUsage</code> of <code>ENCRYPT_DECRYPT</code>. To find the <code>KeyUsage</code> of a KMS key, use the <code>DescribeKey</code> operation.</p>
157 /// <p>To specify a KMS key, use its key ID, key ARN, alias name, or alias ARN. When using an alias name, prefix it with <code>"alias/"</code>. To specify a KMS key in a different Amazon Web Services account, you must use the key ARN or alias ARN.</p>
158 /// <p>For example:</p>
159 /// <ul>
160 /// <li>
161 /// <p>Key ID: <code>1234abcd-12ab-34cd-56ef-1234567890ab</code></p></li>
162 /// <li>
163 /// <p>Key ARN: <code>arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab</code></p></li>
164 /// <li>
165 /// <p>Alias name: <code>alias/ExampleAlias</code></p></li>
166 /// <li>
167 /// <p>Alias ARN: <code>arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias</code></p></li>
168 /// </ul>
169 /// <p>To get the key ID and key ARN for a KMS key, use <code>ListKeys</code> or <code>DescribeKey</code>. To get the alias name and alias ARN, use <code>ListAliases</code>.</p>
170 pub fn key_id(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
171 self.inner = self.inner.key_id(input.into());
172 self
173 }
174 /// <p>Identifies the KMS key to use in the encryption operation. The KMS key must have a <code>KeyUsage</code> of <code>ENCRYPT_DECRYPT</code>. To find the <code>KeyUsage</code> of a KMS key, use the <code>DescribeKey</code> operation.</p>
175 /// <p>To specify a KMS key, use its key ID, key ARN, alias name, or alias ARN. When using an alias name, prefix it with <code>"alias/"</code>. To specify a KMS key in a different Amazon Web Services account, you must use the key ARN or alias ARN.</p>
176 /// <p>For example:</p>
177 /// <ul>
178 /// <li>
179 /// <p>Key ID: <code>1234abcd-12ab-34cd-56ef-1234567890ab</code></p></li>
180 /// <li>
181 /// <p>Key ARN: <code>arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab</code></p></li>
182 /// <li>
183 /// <p>Alias name: <code>alias/ExampleAlias</code></p></li>
184 /// <li>
185 /// <p>Alias ARN: <code>arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias</code></p></li>
186 /// </ul>
187 /// <p>To get the key ID and key ARN for a KMS key, use <code>ListKeys</code> or <code>DescribeKey</code>. To get the alias name and alias ARN, use <code>ListAliases</code>.</p>
188 pub fn set_key_id(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
189 self.inner = self.inner.set_key_id(input);
190 self
191 }
192 /// <p>Identifies the KMS key to use in the encryption operation. The KMS key must have a <code>KeyUsage</code> of <code>ENCRYPT_DECRYPT</code>. To find the <code>KeyUsage</code> of a KMS key, use the <code>DescribeKey</code> operation.</p>
193 /// <p>To specify a KMS key, use its key ID, key ARN, alias name, or alias ARN. When using an alias name, prefix it with <code>"alias/"</code>. To specify a KMS key in a different Amazon Web Services account, you must use the key ARN or alias ARN.</p>
194 /// <p>For example:</p>
195 /// <ul>
196 /// <li>
197 /// <p>Key ID: <code>1234abcd-12ab-34cd-56ef-1234567890ab</code></p></li>
198 /// <li>
199 /// <p>Key ARN: <code>arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab</code></p></li>
200 /// <li>
201 /// <p>Alias name: <code>alias/ExampleAlias</code></p></li>
202 /// <li>
203 /// <p>Alias ARN: <code>arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias</code></p></li>
204 /// </ul>
205 /// <p>To get the key ID and key ARN for a KMS key, use <code>ListKeys</code> or <code>DescribeKey</code>. To get the alias name and alias ARN, use <code>ListAliases</code>.</p>
206 pub fn get_key_id(&self) -> &::std::option::Option<::std::string::String> {
207 self.inner.get_key_id()
208 }
209 /// <p>Data to be encrypted.</p>
210 pub fn plaintext(mut self, input: ::aws_smithy_types::Blob) -> Self {
211 self.inner = self.inner.plaintext(input);
212 self
213 }
214 /// <p>Data to be encrypted.</p>
215 pub fn set_plaintext(mut self, input: ::std::option::Option<::aws_smithy_types::Blob>) -> Self {
216 self.inner = self.inner.set_plaintext(input);
217 self
218 }
219 /// <p>Data to be encrypted.</p>
220 pub fn get_plaintext(&self) -> &::std::option::Option<::aws_smithy_types::Blob> {
221 self.inner.get_plaintext()
222 }
223 ///
224 /// Adds a key-value pair to `EncryptionContext`.
225 ///
226 /// To override the contents of this collection use [`set_encryption_context`](Self::set_encryption_context).
227 ///
228 /// <p>Specifies the encryption context that will be used to encrypt the data. An encryption context is valid only for <a href="https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations">cryptographic operations</a> with a symmetric encryption KMS key. The standard asymmetric encryption algorithms and HMAC algorithms that KMS uses do not support an encryption context.</p><important>
229 /// <p>Do not include confidential or sensitive information in this field. This field may be displayed in plaintext in CloudTrail logs and other output.</p>
230 /// </important>
231 /// <p>An <i>encryption context</i> is a collection of non-secret key-value pairs that represent additional authenticated data. When you use an encryption context to encrypt data, you must specify the same (an exact case-sensitive match) encryption context to decrypt the data. An encryption context is supported only on operations with symmetric encryption KMS keys. On operations with symmetric encryption KMS keys, an encryption context is optional, but it is strongly recommended.</p>
232 /// <p>For more information, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#encrypt_context">Encryption context</a> in the <i>Key Management Service Developer Guide</i>.</p>
233 pub fn encryption_context(
234 mut self,
235 k: impl ::std::convert::Into<::std::string::String>,
236 v: impl ::std::convert::Into<::std::string::String>,
237 ) -> Self {
238 self.inner = self.inner.encryption_context(k.into(), v.into());
239 self
240 }
241 /// <p>Specifies the encryption context that will be used to encrypt the data. An encryption context is valid only for <a href="https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations">cryptographic operations</a> with a symmetric encryption KMS key. The standard asymmetric encryption algorithms and HMAC algorithms that KMS uses do not support an encryption context.</p><important>
242 /// <p>Do not include confidential or sensitive information in this field. This field may be displayed in plaintext in CloudTrail logs and other output.</p>
243 /// </important>
244 /// <p>An <i>encryption context</i> is a collection of non-secret key-value pairs that represent additional authenticated data. When you use an encryption context to encrypt data, you must specify the same (an exact case-sensitive match) encryption context to decrypt the data. An encryption context is supported only on operations with symmetric encryption KMS keys. On operations with symmetric encryption KMS keys, an encryption context is optional, but it is strongly recommended.</p>
245 /// <p>For more information, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#encrypt_context">Encryption context</a> in the <i>Key Management Service Developer Guide</i>.</p>
246 pub fn set_encryption_context(
247 mut self,
248 input: ::std::option::Option<::std::collections::HashMap<::std::string::String, ::std::string::String>>,
249 ) -> Self {
250 self.inner = self.inner.set_encryption_context(input);
251 self
252 }
253 /// <p>Specifies the encryption context that will be used to encrypt the data. An encryption context is valid only for <a href="https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations">cryptographic operations</a> with a symmetric encryption KMS key. The standard asymmetric encryption algorithms and HMAC algorithms that KMS uses do not support an encryption context.</p><important>
254 /// <p>Do not include confidential or sensitive information in this field. This field may be displayed in plaintext in CloudTrail logs and other output.</p>
255 /// </important>
256 /// <p>An <i>encryption context</i> is a collection of non-secret key-value pairs that represent additional authenticated data. When you use an encryption context to encrypt data, you must specify the same (an exact case-sensitive match) encryption context to decrypt the data. An encryption context is supported only on operations with symmetric encryption KMS keys. On operations with symmetric encryption KMS keys, an encryption context is optional, but it is strongly recommended.</p>
257 /// <p>For more information, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#encrypt_context">Encryption context</a> in the <i>Key Management Service Developer Guide</i>.</p>
258 pub fn get_encryption_context(&self) -> &::std::option::Option<::std::collections::HashMap<::std::string::String, ::std::string::String>> {
259 self.inner.get_encryption_context()
260 }
261 ///
262 /// Appends an item to `GrantTokens`.
263 ///
264 /// To override the contents of this collection use [`set_grant_tokens`](Self::set_grant_tokens).
265 ///
266 /// <p>A list of grant tokens.</p>
267 /// <p>Use a grant token when your permission to call this operation comes from a new grant that has not yet achieved <i>eventual consistency</i>. For more information, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/grants.html#grant_token">Grant token</a> and <a href="https://docs.aws.amazon.com/kms/latest/developerguide/grant-manage.html#using-grant-token">Using a grant token</a> in the <i>Key Management Service Developer Guide</i>.</p>
268 pub fn grant_tokens(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
269 self.inner = self.inner.grant_tokens(input.into());
270 self
271 }
272 /// <p>A list of grant tokens.</p>
273 /// <p>Use a grant token when your permission to call this operation comes from a new grant that has not yet achieved <i>eventual consistency</i>. For more information, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/grants.html#grant_token">Grant token</a> and <a href="https://docs.aws.amazon.com/kms/latest/developerguide/grant-manage.html#using-grant-token">Using a grant token</a> in the <i>Key Management Service Developer Guide</i>.</p>
274 pub fn set_grant_tokens(mut self, input: ::std::option::Option<::std::vec::Vec<::std::string::String>>) -> Self {
275 self.inner = self.inner.set_grant_tokens(input);
276 self
277 }
278 /// <p>A list of grant tokens.</p>
279 /// <p>Use a grant token when your permission to call this operation comes from a new grant that has not yet achieved <i>eventual consistency</i>. For more information, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/grants.html#grant_token">Grant token</a> and <a href="https://docs.aws.amazon.com/kms/latest/developerguide/grant-manage.html#using-grant-token">Using a grant token</a> in the <i>Key Management Service Developer Guide</i>.</p>
280 pub fn get_grant_tokens(&self) -> &::std::option::Option<::std::vec::Vec<::std::string::String>> {
281 self.inner.get_grant_tokens()
282 }
283 /// <p>Specifies the encryption algorithm that KMS will use to encrypt the plaintext message. The algorithm must be compatible with the KMS key that you specify.</p>
284 /// <p>This parameter is required only for asymmetric KMS keys. The default value, <code>SYMMETRIC_DEFAULT</code>, is the algorithm used for symmetric encryption KMS keys. If you are using an asymmetric KMS key, we recommend RSAES_OAEP_SHA_256.</p>
285 /// <p>The SM2PKE algorithm is only available in China Regions.</p>
286 pub fn encryption_algorithm(mut self, input: crate::types::EncryptionAlgorithmSpec) -> Self {
287 self.inner = self.inner.encryption_algorithm(input);
288 self
289 }
290 /// <p>Specifies the encryption algorithm that KMS will use to encrypt the plaintext message. The algorithm must be compatible with the KMS key that you specify.</p>
291 /// <p>This parameter is required only for asymmetric KMS keys. The default value, <code>SYMMETRIC_DEFAULT</code>, is the algorithm used for symmetric encryption KMS keys. If you are using an asymmetric KMS key, we recommend RSAES_OAEP_SHA_256.</p>
292 /// <p>The SM2PKE algorithm is only available in China Regions.</p>
293 pub fn set_encryption_algorithm(mut self, input: ::std::option::Option<crate::types::EncryptionAlgorithmSpec>) -> Self {
294 self.inner = self.inner.set_encryption_algorithm(input);
295 self
296 }
297 /// <p>Specifies the encryption algorithm that KMS will use to encrypt the plaintext message. The algorithm must be compatible with the KMS key that you specify.</p>
298 /// <p>This parameter is required only for asymmetric KMS keys. The default value, <code>SYMMETRIC_DEFAULT</code>, is the algorithm used for symmetric encryption KMS keys. If you are using an asymmetric KMS key, we recommend RSAES_OAEP_SHA_256.</p>
299 /// <p>The SM2PKE algorithm is only available in China Regions.</p>
300 pub fn get_encryption_algorithm(&self) -> &::std::option::Option<crate::types::EncryptionAlgorithmSpec> {
301 self.inner.get_encryption_algorithm()
302 }
303 /// <p>Checks if your request will succeed. <code>DryRun</code> is an optional parameter.</p>
304 /// <p>To learn more about how to use this parameter, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/programming-dryrun.html">Testing your KMS API calls</a> in the <i>Key Management Service Developer Guide</i>.</p>
305 pub fn dry_run(mut self, input: bool) -> Self {
306 self.inner = self.inner.dry_run(input);
307 self
308 }
309 /// <p>Checks if your request will succeed. <code>DryRun</code> is an optional parameter.</p>
310 /// <p>To learn more about how to use this parameter, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/programming-dryrun.html">Testing your KMS API calls</a> in the <i>Key Management Service Developer Guide</i>.</p>
311 pub fn set_dry_run(mut self, input: ::std::option::Option<bool>) -> Self {
312 self.inner = self.inner.set_dry_run(input);
313 self
314 }
315 /// <p>Checks if your request will succeed. <code>DryRun</code> is an optional parameter.</p>
316 /// <p>To learn more about how to use this parameter, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/programming-dryrun.html">Testing your KMS API calls</a> in the <i>Key Management Service Developer Guide</i>.</p>
317 pub fn get_dry_run(&self) -> &::std::option::Option<bool> {
318 self.inner.get_dry_run()
319 }
320}