aws_sdk_kms/operation/generate_data_key_without_plaintext/
builders.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub use crate::operation::generate_data_key_without_plaintext::_generate_data_key_without_plaintext_output::GenerateDataKeyWithoutPlaintextOutputBuilder;
3
4pub use crate::operation::generate_data_key_without_plaintext::_generate_data_key_without_plaintext_input::GenerateDataKeyWithoutPlaintextInputBuilder;
5
6impl crate::operation::generate_data_key_without_plaintext::builders::GenerateDataKeyWithoutPlaintextInputBuilder {
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::generate_data_key_without_plaintext::GenerateDataKeyWithoutPlaintextOutput,
13        ::aws_smithy_runtime_api::client::result::SdkError<
14            crate::operation::generate_data_key_without_plaintext::GenerateDataKeyWithoutPlaintextError,
15            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
16        >,
17    > {
18        let mut fluent_builder = client.generate_data_key_without_plaintext();
19        fluent_builder.inner = self;
20        fluent_builder.send().await
21    }
22}
23/// Fluent builder constructing a request to `GenerateDataKeyWithoutPlaintext`.
24///
25/// <p>Returns a unique symmetric data key for use outside of KMS. This operation returns a data key that is encrypted under a symmetric encryption KMS key that you specify. The bytes in the key are random; they are not related to the caller or to the KMS key.</p>
26/// <p><code>GenerateDataKeyWithoutPlaintext</code> is identical to the <code>GenerateDataKey</code> operation except that it does not return a plaintext copy of the data key.</p>
27/// <p>This operation is useful for systems that need to encrypt data at some point, but not immediately. When you need to encrypt the data, you call the <code>Decrypt</code> operation on the encrypted copy of the key.</p>
28/// <p>It's also useful in distributed systems with different levels of trust. For example, you might store encrypted data in containers. One component of your system creates new containers and stores an encrypted data key with each container. Then, a different component puts the data into the containers. That component first decrypts the data key, uses the plaintext data key to encrypt data, puts the encrypted data into the container, and then destroys the plaintext data key. In this system, the component that creates the containers never sees the plaintext data key.</p>
29/// <p>To request an asymmetric data key pair, use the <code>GenerateDataKeyPair</code> or <code>GenerateDataKeyPairWithoutPlaintext</code> operations.</p>
30/// <p>To generate a data key, you must specify the symmetric encryption KMS key that is used to encrypt the data key. You cannot use an asymmetric KMS key or a key in a custom key store to generate a data key. To get the type of your KMS key, use the <code>DescribeKey</code> operation.</p>
31/// <p>You must also specify the length of the data key. Use either the <code>KeySpec</code> or <code>NumberOfBytes</code> parameters (but not both). For 128-bit and 256-bit data keys, use the <code>KeySpec</code> parameter.</p>
32/// <p>To generate an SM4 data key (China Regions only), specify a <code>KeySpec</code> value of <code>AES_128</code> or <code>NumberOfBytes</code> value of <code>16</code>. The symmetric encryption key used in China Regions to encrypt your data key is an SM4 encryption key.</p>
33/// <p>If the operation succeeds, you will find the encrypted copy of the data key in the <code>CiphertextBlob</code> field.</p>
34/// <p>You can use an optional encryption context to add additional security to the encryption operation. If you specify an <code>EncryptionContext</code>, you must specify the same encryption context (a case-sensitive exact match) when decrypting the encrypted data key. 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>
35/// <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>
36/// <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>
37/// <p><b>Required permissions</b>: <a href="https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html">kms:GenerateDataKeyWithoutPlaintext</a> (key policy)</p>
38/// <p><b>Related operations:</b></p>
39/// <ul>
40/// <li>
41/// <p><code>Decrypt</code></p></li>
42/// <li>
43/// <p><code>Encrypt</code></p></li>
44/// <li>
45/// <p><code>GenerateDataKey</code></p></li>
46/// <li>
47/// <p><code>GenerateDataKeyPair</code></p></li>
48/// <li>
49/// <p><code>GenerateDataKeyPairWithoutPlaintext</code></p></li>
50/// </ul>
51/// <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>
52#[derive(::std::clone::Clone, ::std::fmt::Debug)]
53pub struct GenerateDataKeyWithoutPlaintextFluentBuilder {
54    handle: ::std::sync::Arc<crate::client::Handle>,
55    inner: crate::operation::generate_data_key_without_plaintext::builders::GenerateDataKeyWithoutPlaintextInputBuilder,
56    config_override: ::std::option::Option<crate::config::Builder>,
57}
58impl
59    crate::client::customize::internal::CustomizableSend<
60        crate::operation::generate_data_key_without_plaintext::GenerateDataKeyWithoutPlaintextOutput,
61        crate::operation::generate_data_key_without_plaintext::GenerateDataKeyWithoutPlaintextError,
62    > for GenerateDataKeyWithoutPlaintextFluentBuilder
63{
64    fn send(
65        self,
66        config_override: crate::config::Builder,
67    ) -> crate::client::customize::internal::BoxFuture<
68        crate::client::customize::internal::SendResult<
69            crate::operation::generate_data_key_without_plaintext::GenerateDataKeyWithoutPlaintextOutput,
70            crate::operation::generate_data_key_without_plaintext::GenerateDataKeyWithoutPlaintextError,
71        >,
72    > {
73        ::std::boxed::Box::pin(async move { self.config_override(config_override).send().await })
74    }
75}
76impl GenerateDataKeyWithoutPlaintextFluentBuilder {
77    /// Creates a new `GenerateDataKeyWithoutPlaintextFluentBuilder`.
78    pub(crate) fn new(handle: ::std::sync::Arc<crate::client::Handle>) -> Self {
79        Self {
80            handle,
81            inner: ::std::default::Default::default(),
82            config_override: ::std::option::Option::None,
83        }
84    }
85    /// Access the GenerateDataKeyWithoutPlaintext as a reference.
86    pub fn as_input(&self) -> &crate::operation::generate_data_key_without_plaintext::builders::GenerateDataKeyWithoutPlaintextInputBuilder {
87        &self.inner
88    }
89    /// Sends the request and returns the response.
90    ///
91    /// If an error occurs, an `SdkError` will be returned with additional details that
92    /// can be matched against.
93    ///
94    /// By default, any retryable failures will be retried twice. Retry behavior
95    /// is configurable with the [RetryConfig](aws_smithy_types::retry::RetryConfig), which can be
96    /// set when configuring the client.
97    pub async fn send(
98        self,
99    ) -> ::std::result::Result<
100        crate::operation::generate_data_key_without_plaintext::GenerateDataKeyWithoutPlaintextOutput,
101        ::aws_smithy_runtime_api::client::result::SdkError<
102            crate::operation::generate_data_key_without_plaintext::GenerateDataKeyWithoutPlaintextError,
103            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
104        >,
105    > {
106        let input = self
107            .inner
108            .build()
109            .map_err(::aws_smithy_runtime_api::client::result::SdkError::construction_failure)?;
110        let runtime_plugins = crate::operation::generate_data_key_without_plaintext::GenerateDataKeyWithoutPlaintext::operation_runtime_plugins(
111            self.handle.runtime_plugins.clone(),
112            &self.handle.conf,
113            self.config_override,
114        );
115        crate::operation::generate_data_key_without_plaintext::GenerateDataKeyWithoutPlaintext::orchestrate(&runtime_plugins, input).await
116    }
117
118    /// Consumes this builder, creating a customizable operation that can be modified before being sent.
119    pub fn customize(
120        self,
121    ) -> crate::client::customize::CustomizableOperation<
122        crate::operation::generate_data_key_without_plaintext::GenerateDataKeyWithoutPlaintextOutput,
123        crate::operation::generate_data_key_without_plaintext::GenerateDataKeyWithoutPlaintextError,
124        Self,
125    > {
126        crate::client::customize::CustomizableOperation::new(self)
127    }
128    pub(crate) fn config_override(mut self, config_override: impl ::std::convert::Into<crate::config::Builder>) -> Self {
129        self.set_config_override(::std::option::Option::Some(config_override.into()));
130        self
131    }
132
133    pub(crate) fn set_config_override(&mut self, config_override: ::std::option::Option<crate::config::Builder>) -> &mut Self {
134        self.config_override = config_override;
135        self
136    }
137    /// <p>Specifies the symmetric encryption KMS key that encrypts the data key. You cannot specify an asymmetric KMS key or a KMS key in a custom key store. To get the type and origin of your KMS key, use the <code>DescribeKey</code> operation.</p>
138    /// <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>
139    /// <p>For example:</p>
140    /// <ul>
141    /// <li>
142    /// <p>Key ID: <code>1234abcd-12ab-34cd-56ef-1234567890ab</code></p></li>
143    /// <li>
144    /// <p>Key ARN: <code>arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab</code></p></li>
145    /// <li>
146    /// <p>Alias name: <code>alias/ExampleAlias</code></p></li>
147    /// <li>
148    /// <p>Alias ARN: <code>arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias</code></p></li>
149    /// </ul>
150    /// <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>
151    pub fn key_id(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
152        self.inner = self.inner.key_id(input.into());
153        self
154    }
155    /// <p>Specifies the symmetric encryption KMS key that encrypts the data key. You cannot specify an asymmetric KMS key or a KMS key in a custom key store. To get the type and origin of your KMS key, use the <code>DescribeKey</code> operation.</p>
156    /// <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>
157    /// <p>For example:</p>
158    /// <ul>
159    /// <li>
160    /// <p>Key ID: <code>1234abcd-12ab-34cd-56ef-1234567890ab</code></p></li>
161    /// <li>
162    /// <p>Key ARN: <code>arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab</code></p></li>
163    /// <li>
164    /// <p>Alias name: <code>alias/ExampleAlias</code></p></li>
165    /// <li>
166    /// <p>Alias ARN: <code>arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias</code></p></li>
167    /// </ul>
168    /// <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>
169    pub fn set_key_id(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
170        self.inner = self.inner.set_key_id(input);
171        self
172    }
173    /// <p>Specifies the symmetric encryption KMS key that encrypts the data key. You cannot specify an asymmetric KMS key or a KMS key in a custom key store. To get the type and origin of your KMS key, use the <code>DescribeKey</code> operation.</p>
174    /// <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>
175    /// <p>For example:</p>
176    /// <ul>
177    /// <li>
178    /// <p>Key ID: <code>1234abcd-12ab-34cd-56ef-1234567890ab</code></p></li>
179    /// <li>
180    /// <p>Key ARN: <code>arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab</code></p></li>
181    /// <li>
182    /// <p>Alias name: <code>alias/ExampleAlias</code></p></li>
183    /// <li>
184    /// <p>Alias ARN: <code>arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias</code></p></li>
185    /// </ul>
186    /// <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>
187    pub fn get_key_id(&self) -> &::std::option::Option<::std::string::String> {
188        self.inner.get_key_id()
189    }
190    ///
191    /// Adds a key-value pair to `EncryptionContext`.
192    ///
193    /// To override the contents of this collection use [`set_encryption_context`](Self::set_encryption_context).
194    ///
195    /// <p>Specifies the encryption context that will be used when encrypting the data key.</p><important>
196    /// <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>
197    /// </important>
198    /// <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>
199    /// <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>
200    pub fn encryption_context(
201        mut self,
202        k: impl ::std::convert::Into<::std::string::String>,
203        v: impl ::std::convert::Into<::std::string::String>,
204    ) -> Self {
205        self.inner = self.inner.encryption_context(k.into(), v.into());
206        self
207    }
208    /// <p>Specifies the encryption context that will be used when encrypting the data key.</p><important>
209    /// <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>
210    /// </important>
211    /// <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>
212    /// <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>
213    pub fn set_encryption_context(
214        mut self,
215        input: ::std::option::Option<::std::collections::HashMap<::std::string::String, ::std::string::String>>,
216    ) -> Self {
217        self.inner = self.inner.set_encryption_context(input);
218        self
219    }
220    /// <p>Specifies the encryption context that will be used when encrypting the data key.</p><important>
221    /// <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>
222    /// </important>
223    /// <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>
224    /// <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>
225    pub fn get_encryption_context(&self) -> &::std::option::Option<::std::collections::HashMap<::std::string::String, ::std::string::String>> {
226        self.inner.get_encryption_context()
227    }
228    /// <p>The length of the data key. Use <code>AES_128</code> to generate a 128-bit symmetric key, or <code>AES_256</code> to generate a 256-bit symmetric key.</p>
229    pub fn key_spec(mut self, input: crate::types::DataKeySpec) -> Self {
230        self.inner = self.inner.key_spec(input);
231        self
232    }
233    /// <p>The length of the data key. Use <code>AES_128</code> to generate a 128-bit symmetric key, or <code>AES_256</code> to generate a 256-bit symmetric key.</p>
234    pub fn set_key_spec(mut self, input: ::std::option::Option<crate::types::DataKeySpec>) -> Self {
235        self.inner = self.inner.set_key_spec(input);
236        self
237    }
238    /// <p>The length of the data key. Use <code>AES_128</code> to generate a 128-bit symmetric key, or <code>AES_256</code> to generate a 256-bit symmetric key.</p>
239    pub fn get_key_spec(&self) -> &::std::option::Option<crate::types::DataKeySpec> {
240        self.inner.get_key_spec()
241    }
242    /// <p>The length of the data key in bytes. For example, use the value 64 to generate a 512-bit data key (64 bytes is 512 bits). For common key lengths (128-bit and 256-bit symmetric keys), we recommend that you use the <code>KeySpec</code> field instead of this one.</p>
243    pub fn number_of_bytes(mut self, input: i32) -> Self {
244        self.inner = self.inner.number_of_bytes(input);
245        self
246    }
247    /// <p>The length of the data key in bytes. For example, use the value 64 to generate a 512-bit data key (64 bytes is 512 bits). For common key lengths (128-bit and 256-bit symmetric keys), we recommend that you use the <code>KeySpec</code> field instead of this one.</p>
248    pub fn set_number_of_bytes(mut self, input: ::std::option::Option<i32>) -> Self {
249        self.inner = self.inner.set_number_of_bytes(input);
250        self
251    }
252    /// <p>The length of the data key in bytes. For example, use the value 64 to generate a 512-bit data key (64 bytes is 512 bits). For common key lengths (128-bit and 256-bit symmetric keys), we recommend that you use the <code>KeySpec</code> field instead of this one.</p>
253    pub fn get_number_of_bytes(&self) -> &::std::option::Option<i32> {
254        self.inner.get_number_of_bytes()
255    }
256    ///
257    /// Appends an item to `GrantTokens`.
258    ///
259    /// To override the contents of this collection use [`set_grant_tokens`](Self::set_grant_tokens).
260    ///
261    /// <p>A list of grant tokens.</p>
262    /// <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>
263    pub fn grant_tokens(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
264        self.inner = self.inner.grant_tokens(input.into());
265        self
266    }
267    /// <p>A list of grant tokens.</p>
268    /// <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>
269    pub fn set_grant_tokens(mut self, input: ::std::option::Option<::std::vec::Vec<::std::string::String>>) -> Self {
270        self.inner = self.inner.set_grant_tokens(input);
271        self
272    }
273    /// <p>A list of grant tokens.</p>
274    /// <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>
275    pub fn get_grant_tokens(&self) -> &::std::option::Option<::std::vec::Vec<::std::string::String>> {
276        self.inner.get_grant_tokens()
277    }
278    /// <p>Checks if your request will succeed. <code>DryRun</code> is an optional parameter.</p>
279    /// <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>
280    pub fn dry_run(mut self, input: bool) -> Self {
281        self.inner = self.inner.dry_run(input);
282        self
283    }
284    /// <p>Checks if your request will succeed. <code>DryRun</code> is an optional parameter.</p>
285    /// <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>
286    pub fn set_dry_run(mut self, input: ::std::option::Option<bool>) -> Self {
287        self.inner = self.inner.set_dry_run(input);
288        self
289    }
290    /// <p>Checks if your request will succeed. <code>DryRun</code> is an optional parameter.</p>
291    /// <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>
292    pub fn get_dry_run(&self) -> &::std::option::Option<bool> {
293        self.inner.get_dry_run()
294    }
295}