Skip to main content

aws_sdk_kms/operation/
encrypt.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Orchestration and serialization glue logic for `Encrypt`.
3#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
4#[non_exhaustive]
5pub struct Encrypt;
6impl Encrypt {
7    /// Creates a new `Encrypt`
8    pub fn new() -> Self {
9        Self
10    }
11    /// The schema for this operation's input shape.
12    pub const INPUT_SCHEMA: &'static ::aws_smithy_schema::Schema<'static> = crate::operation::encrypt::EncryptInput::SCHEMA;
13    /// The schema for this operation's output shape.
14    pub const OUTPUT_SCHEMA: &'static ::aws_smithy_schema::Schema<'static> = crate::operation::encrypt::EncryptOutput::SCHEMA;
15    pub(crate) async fn orchestrate(
16        runtime_plugins: &::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
17        input: crate::operation::encrypt::EncryptInput,
18    ) -> ::std::result::Result<
19        crate::operation::encrypt::EncryptOutput,
20        ::aws_smithy_runtime_api::client::result::SdkError<
21            crate::operation::encrypt::EncryptError,
22            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
23        >,
24    > {
25        let map_err =
26            |err: ::aws_smithy_runtime_api::client::result::SdkError<
27                ::aws_smithy_runtime_api::client::interceptors::context::Error,
28                ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
29            >| { err.map_service_error(|err| err.downcast::<crate::operation::encrypt::EncryptError>().expect("correct error type")) };
30        let context = Self::orchestrate_with_stop_point(runtime_plugins, input, ::aws_smithy_runtime::client::orchestrator::StopPoint::None)
31            .await
32            .map_err(map_err)?;
33        let output = context.finalize().map_err(map_err)?;
34        ::std::result::Result::Ok(
35            output
36                .downcast::<crate::operation::encrypt::EncryptOutput>()
37                .expect("correct output type"),
38        )
39    }
40
41    pub(crate) async fn orchestrate_with_stop_point(
42        runtime_plugins: &::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
43        input: crate::operation::encrypt::EncryptInput,
44        stop_point: ::aws_smithy_runtime::client::orchestrator::StopPoint,
45    ) -> ::std::result::Result<
46        ::aws_smithy_runtime_api::client::interceptors::context::InterceptorContext,
47        ::aws_smithy_runtime_api::client::result::SdkError<
48            ::aws_smithy_runtime_api::client::interceptors::context::Error,
49            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
50        >,
51    > {
52        let input = ::aws_smithy_runtime_api::client::interceptors::context::Input::erase(input);
53        use ::tracing::Instrument;
54        ::aws_smithy_runtime::client::orchestrator::invoke_with_stop_point("KMS", "Encrypt", input, runtime_plugins, stop_point)
55            // Create a parent span for the entire operation. Includes a random, internal-only,
56            // seven-digit ID for the operation orchestration so that it can be correlated in the logs.
57            .instrument(::tracing::debug_span!(
58                "KMS.Encrypt",
59                "rpc.service" = "KMS",
60                "rpc.method" = "Encrypt",
61                "sdk_invocation_id" = ::fastrand::u32(1_000_000..10_000_000),
62                "rpc.system" = "aws-api",
63            ))
64            .await
65    }
66
67    pub(crate) fn operation_runtime_plugins(
68        client_runtime_plugins: ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
69        client_config: &crate::config::Config,
70        config_override: ::std::option::Option<crate::config::Builder>,
71    ) -> ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins {
72        let mut runtime_plugins = client_runtime_plugins.with_operation_plugin(Self::new());
73
74        if let ::std::option::Option::Some(config_override) = config_override {
75            for plugin in config_override.runtime_plugins.iter().cloned() {
76                runtime_plugins = runtime_plugins.with_operation_plugin(plugin);
77            }
78            runtime_plugins = runtime_plugins.with_operation_plugin(crate::config::ConfigOverrideRuntimePlugin::new(
79                config_override,
80                client_config.config.clone(),
81                &client_config.runtime_components,
82            ));
83        }
84        runtime_plugins
85    }
86}
87/// Per-operation error registry. Contains an entry for every modeled
88/// error this operation can throw.
89///
90/// Used by the schema-serde error path as the operation-scoped lookup
91/// for registry-backed error reification: an error code that does not
92/// match one of the operation's modeled errors directly is resolved
93/// against this registry first, then widened to the service-wide error
94/// registry.
95pub(crate) mod error_registry {
96    pub(crate) static REGISTRY: ::std::sync::LazyLock<::aws_smithy_schema::registry::TypeRegistry> = ::std::sync::LazyLock::new(|| {
97        ::aws_smithy_schema::registry::TypeRegistry::builder()
98                            .insert_error_shape(
99                        crate::types::error::DependencyTimeoutException::SCHEMA,
100                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::aws_smithy_types::type_erasure::TypeErasedBox, ::aws_smithy_schema::serde::SerdeError> {
101                            ::std::result::Result::Ok(::aws_smithy_types::type_erasure::TypeErasedBox::new(crate::types::error::DependencyTimeoutException::deserialize(d)?))
102                        },
103                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync>, ::aws_smithy_schema::serde::SerdeError> {
104                            ::std::result::Result::Ok(::std::boxed::Box::new(crate::types::error::DependencyTimeoutException::deserialize(d)?))
105                        },
106                    )
107.insert_error_shape(
108                        crate::types::error::DisabledException::SCHEMA,
109                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::aws_smithy_types::type_erasure::TypeErasedBox, ::aws_smithy_schema::serde::SerdeError> {
110                            ::std::result::Result::Ok(::aws_smithy_types::type_erasure::TypeErasedBox::new(crate::types::error::DisabledException::deserialize(d)?))
111                        },
112                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync>, ::aws_smithy_schema::serde::SerdeError> {
113                            ::std::result::Result::Ok(::std::boxed::Box::new(crate::types::error::DisabledException::deserialize(d)?))
114                        },
115                    )
116.insert_error_shape(
117                        crate::types::error::DryRunOperationException::SCHEMA,
118                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::aws_smithy_types::type_erasure::TypeErasedBox, ::aws_smithy_schema::serde::SerdeError> {
119                            ::std::result::Result::Ok(::aws_smithy_types::type_erasure::TypeErasedBox::new(crate::types::error::DryRunOperationException::deserialize(d)?))
120                        },
121                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync>, ::aws_smithy_schema::serde::SerdeError> {
122                            ::std::result::Result::Ok(::std::boxed::Box::new(crate::types::error::DryRunOperationException::deserialize(d)?))
123                        },
124                    )
125.insert_error_shape(
126                        crate::types::error::InvalidGrantTokenException::SCHEMA,
127                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::aws_smithy_types::type_erasure::TypeErasedBox, ::aws_smithy_schema::serde::SerdeError> {
128                            ::std::result::Result::Ok(::aws_smithy_types::type_erasure::TypeErasedBox::new(crate::types::error::InvalidGrantTokenException::deserialize(d)?))
129                        },
130                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync>, ::aws_smithy_schema::serde::SerdeError> {
131                            ::std::result::Result::Ok(::std::boxed::Box::new(crate::types::error::InvalidGrantTokenException::deserialize(d)?))
132                        },
133                    )
134.insert_error_shape(
135                        crate::types::error::InvalidKeyUsageException::SCHEMA,
136                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::aws_smithy_types::type_erasure::TypeErasedBox, ::aws_smithy_schema::serde::SerdeError> {
137                            ::std::result::Result::Ok(::aws_smithy_types::type_erasure::TypeErasedBox::new(crate::types::error::InvalidKeyUsageException::deserialize(d)?))
138                        },
139                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync>, ::aws_smithy_schema::serde::SerdeError> {
140                            ::std::result::Result::Ok(::std::boxed::Box::new(crate::types::error::InvalidKeyUsageException::deserialize(d)?))
141                        },
142                    )
143.insert_error_shape(
144                        crate::types::error::KmsInternalException::SCHEMA,
145                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::aws_smithy_types::type_erasure::TypeErasedBox, ::aws_smithy_schema::serde::SerdeError> {
146                            ::std::result::Result::Ok(::aws_smithy_types::type_erasure::TypeErasedBox::new(crate::types::error::KmsInternalException::deserialize(d)?))
147                        },
148                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync>, ::aws_smithy_schema::serde::SerdeError> {
149                            ::std::result::Result::Ok(::std::boxed::Box::new(crate::types::error::KmsInternalException::deserialize(d)?))
150                        },
151                    )
152.insert_error_shape(
153                        crate::types::error::KmsInvalidStateException::SCHEMA,
154                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::aws_smithy_types::type_erasure::TypeErasedBox, ::aws_smithy_schema::serde::SerdeError> {
155                            ::std::result::Result::Ok(::aws_smithy_types::type_erasure::TypeErasedBox::new(crate::types::error::KmsInvalidStateException::deserialize(d)?))
156                        },
157                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync>, ::aws_smithy_schema::serde::SerdeError> {
158                            ::std::result::Result::Ok(::std::boxed::Box::new(crate::types::error::KmsInvalidStateException::deserialize(d)?))
159                        },
160                    )
161.insert_error_shape(
162                        crate::types::error::KeyUnavailableException::SCHEMA,
163                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::aws_smithy_types::type_erasure::TypeErasedBox, ::aws_smithy_schema::serde::SerdeError> {
164                            ::std::result::Result::Ok(::aws_smithy_types::type_erasure::TypeErasedBox::new(crate::types::error::KeyUnavailableException::deserialize(d)?))
165                        },
166                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync>, ::aws_smithy_schema::serde::SerdeError> {
167                            ::std::result::Result::Ok(::std::boxed::Box::new(crate::types::error::KeyUnavailableException::deserialize(d)?))
168                        },
169                    )
170.insert_error_shape(
171                        crate::types::error::NotFoundException::SCHEMA,
172                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::aws_smithy_types::type_erasure::TypeErasedBox, ::aws_smithy_schema::serde::SerdeError> {
173                            ::std::result::Result::Ok(::aws_smithy_types::type_erasure::TypeErasedBox::new(crate::types::error::NotFoundException::deserialize(d)?))
174                        },
175                        |d: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer| -> ::std::result::Result<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync>, ::aws_smithy_schema::serde::SerdeError> {
176                            ::std::result::Result::Ok(::std::boxed::Box::new(crate::types::error::NotFoundException::deserialize(d)?))
177                        },
178                    )
179                            .build()
180    });
181}
182impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for Encrypt {
183    fn config(&self) -> ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer> {
184        let mut cfg = ::aws_smithy_types::config_bag::Layer::new("Encrypt");
185
186        cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedRequestSerializer::new(
187            EncryptRequestSerializer,
188        ));
189        cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer::new(
190            EncryptResponseDeserializer,
191        ));
192
193        cfg.store_put(::aws_smithy_runtime_api::client::auth::AuthSchemeOptionResolverParams::new(
194            crate::config::auth::Params::builder()
195                .operation_name("Encrypt")
196                .build()
197                .expect("required fields set"),
198        ));
199
200        cfg.store_put(::aws_smithy_runtime_api::client::orchestrator::Metadata::new("Encrypt", "KMS"));
201        let mut signing_options = ::aws_runtime::auth::SigningOptions::default();
202        signing_options.double_uri_encode = true;
203        signing_options.content_sha256_header = false;
204        signing_options.normalize_uri_path = true;
205        signing_options.payload_override = None;
206
207        cfg.store_put(::aws_runtime::auth::SigV4OperationSigningConfig {
208            signing_options,
209            ..::std::default::Default::default()
210        });
211
212        ::std::option::Option::Some(cfg.freeze())
213    }
214
215    fn runtime_components(
216        &self,
217        _: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
218    ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
219        #[allow(unused_mut)]
220        let mut rcb = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("Encrypt")
221            .with_interceptor(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::permanent(
222                EncryptTelemetryInputCaptureInterceptor,
223            ))
224            .with_interceptor(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::permanent(
225                ::aws_smithy_runtime::client::stalled_stream_protection::StalledStreamProtectionInterceptor::default(),
226            ))
227            .with_interceptor(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::permanent(
228                EncryptEndpointParamsInterceptor,
229            ))
230            .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::TransientErrorClassifier::<
231                crate::operation::encrypt::EncryptError,
232            >::new())
233            .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::ModeledAsRetryableClassifier::<
234                crate::operation::encrypt::EncryptError,
235            >::new())
236            .with_retry_classifier(::aws_runtime::retries::classifiers::AwsErrorCodeClassifier::<
237                crate::operation::encrypt::EncryptError,
238            >::new())
239            .with_retry_classifier(::aws_runtime::service_clock_skew::ServiceClockSkewClassifier::<
240                crate::operation::encrypt::EncryptError,
241            >::new());
242
243        ::std::borrow::Cow::Owned(rcb)
244    }
245}
246
247#[derive(Debug)]
248struct EncryptTelemetryInputCaptureInterceptor;
249
250#[::aws_smithy_runtime_api::client::interceptors::dyn_dispatch_hint]
251impl ::aws_smithy_runtime_api::client::interceptors::Intercept for EncryptTelemetryInputCaptureInterceptor {
252    fn name(&self) -> &'static str {
253        "EncryptTelemetryInputCaptureInterceptor"
254    }
255
256    fn read_before_execution(
257        &self,
258        context: &::aws_smithy_runtime_api::client::interceptors::context::BeforeSerializationInterceptorContextRef<
259            '_,
260            ::aws_smithy_runtime_api::client::interceptors::context::Input,
261            ::aws_smithy_runtime_api::client::interceptors::context::Output,
262            ::aws_smithy_runtime_api::client::interceptors::context::Error,
263        >,
264        cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
265    ) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
266        // Nothing to do unless the customer opted in by naming members to record.
267        let ::std::option::Option::Some(requested) = cfg
268            .load::<::aws_smithy_types::telemetry::RequestedTelemetryAttributes>()
269            .filter(|r| !r.is_empty())
270        else {
271            return ::std::result::Result::Ok(());
272        };
273
274        let ::std::option::Option::Some(input) = context.input().downcast_ref::<EncryptInput>() else {
275            // A mismatched input is not this interceptor's concern; skip quietly.
276            return ::std::result::Result::Ok(());
277        };
278
279        let mut captured = ::aws_smithy_types::telemetry::CapturedTelemetryAttributes::default();
280        if requested.should_capture("KeyId") {
281            if let ::std::option::Option::Some(value) = input.key_id.as_deref() {
282                captured.insert("KeyId", value);
283            }
284        }
285
286        cfg.interceptor_state().store_put(captured);
287        ::std::result::Result::Ok(())
288    }
289}
290#[derive(Debug)]
291struct EncryptResponseDeserializer;
292impl ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse for EncryptResponseDeserializer {
293    fn deserialize_nonstreaming_with_config(
294        &self,
295        response: &::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
296        _cfg: &::aws_smithy_types::config_bag::ConfigBag,
297    ) -> ::aws_smithy_runtime_api::client::interceptors::context::OutputOrError {
298        let (success, status) = (response.status().is_success(), response.status().as_u16());
299        // Load body and headers BEFORE BeforeParseResponse so customizations
300        // (e.g., S3's `body_is_error` check that detects errors returned with
301        // HTTP 200) can inspect them. The legacy non-streaming path also
302        // loads `body` before firing this hook.
303        #[allow(unused_variables)]
304        let body = response.body().bytes().expect("body loaded");
305        let headers = response.headers();
306        #[allow(unused_mut)]
307        let mut force_error = false;
308        ::tracing::debug!(request_id = ?::aws_types::request_id::RequestId::request_id(response));
309        if !success && status != 200 || force_error {
310            let protocol = _cfg
311                .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
312                .expect("a SharedClientProtocol is required");
313            #[allow(unused_mut)]
314            let mut generic_builder = protocol.parse_error_metadata(response, _cfg).map_err(|e| {
315                ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(e))
316            })?;
317            generic_builder = ::aws_types::request_id::apply_request_id(generic_builder, headers);
318            let generic = generic_builder.build();
319            let error_code = match generic.code() {
320                ::std::option::Option::Some(code) => code,
321                ::std::option::Option::None => {
322                    return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
323                        ::aws_smithy_runtime_api::box_error::BoxError::from(crate::operation::encrypt::EncryptError::unhandled(generic)),
324                    ))
325                }
326            };
327            let _error_message = generic.message().map(|msg| msg.to_owned());
328            let err = match error_code {
329                "DependencyTimeoutException" => crate::operation::encrypt::EncryptError::DependencyTimeoutException({
330                    let mut deser = protocol.deserialize_error_response(response, _cfg).map_err(|e| {
331                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
332                            e,
333                        ))
334                    })?;
335                    let mut tmp = <crate::types::error::builders::DependencyTimeoutExceptionBuilder>::default();
336                    tmp.deserialize_members(&mut *deser).map_err(|e| {
337                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
338                            e,
339                        ))
340                    })?;
341                    if tmp.message.is_none() {
342                        tmp.message = _error_message;
343                    }
344                    let tmp = tmp.meta(generic);
345                    tmp.build()
346                }),
347                "DisabledException" => crate::operation::encrypt::EncryptError::DisabledException({
348                    let mut deser = protocol.deserialize_error_response(response, _cfg).map_err(|e| {
349                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
350                            e,
351                        ))
352                    })?;
353                    let mut tmp = <crate::types::error::builders::DisabledExceptionBuilder>::default();
354                    tmp.deserialize_members(&mut *deser).map_err(|e| {
355                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
356                            e,
357                        ))
358                    })?;
359                    if tmp.message.is_none() {
360                        tmp.message = _error_message;
361                    }
362                    let tmp = tmp.meta(generic);
363                    tmp.build()
364                }),
365                "DryRunOperationException" => crate::operation::encrypt::EncryptError::DryRunOperationException({
366                    let mut deser = protocol.deserialize_error_response(response, _cfg).map_err(|e| {
367                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
368                            e,
369                        ))
370                    })?;
371                    let mut tmp = <crate::types::error::builders::DryRunOperationExceptionBuilder>::default();
372                    tmp.deserialize_members(&mut *deser).map_err(|e| {
373                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
374                            e,
375                        ))
376                    })?;
377                    if tmp.message.is_none() {
378                        tmp.message = _error_message;
379                    }
380                    let tmp = tmp.meta(generic);
381                    tmp.build()
382                }),
383                "InvalidGrantTokenException" => crate::operation::encrypt::EncryptError::InvalidGrantTokenException({
384                    let mut deser = protocol.deserialize_error_response(response, _cfg).map_err(|e| {
385                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
386                            e,
387                        ))
388                    })?;
389                    let mut tmp = <crate::types::error::builders::InvalidGrantTokenExceptionBuilder>::default();
390                    tmp.deserialize_members(&mut *deser).map_err(|e| {
391                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
392                            e,
393                        ))
394                    })?;
395                    if tmp.message.is_none() {
396                        tmp.message = _error_message;
397                    }
398                    let tmp = tmp.meta(generic);
399                    tmp.build()
400                }),
401                "InvalidKeyUsageException" => crate::operation::encrypt::EncryptError::InvalidKeyUsageException({
402                    let mut deser = protocol.deserialize_error_response(response, _cfg).map_err(|e| {
403                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
404                            e,
405                        ))
406                    })?;
407                    let mut tmp = <crate::types::error::builders::InvalidKeyUsageExceptionBuilder>::default();
408                    tmp.deserialize_members(&mut *deser).map_err(|e| {
409                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
410                            e,
411                        ))
412                    })?;
413                    if tmp.message.is_none() {
414                        tmp.message = _error_message;
415                    }
416                    let tmp = tmp.meta(generic);
417                    tmp.build()
418                }),
419                "KeyUnavailableException" => crate::operation::encrypt::EncryptError::KeyUnavailableException({
420                    let mut deser = protocol.deserialize_error_response(response, _cfg).map_err(|e| {
421                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
422                            e,
423                        ))
424                    })?;
425                    let mut tmp = <crate::types::error::builders::KeyUnavailableExceptionBuilder>::default();
426                    tmp.deserialize_members(&mut *deser).map_err(|e| {
427                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
428                            e,
429                        ))
430                    })?;
431                    if tmp.message.is_none() {
432                        tmp.message = _error_message;
433                    }
434                    let tmp = tmp.meta(generic);
435                    tmp.build()
436                }),
437                "KMSInternalException" => crate::operation::encrypt::EncryptError::KmsInternalException({
438                    let mut deser = protocol.deserialize_error_response(response, _cfg).map_err(|e| {
439                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
440                            e,
441                        ))
442                    })?;
443                    let mut tmp = <crate::types::error::builders::KmsInternalExceptionBuilder>::default();
444                    tmp.deserialize_members(&mut *deser).map_err(|e| {
445                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
446                            e,
447                        ))
448                    })?;
449                    if tmp.message.is_none() {
450                        tmp.message = _error_message;
451                    }
452                    let tmp = tmp.meta(generic);
453                    tmp.build()
454                }),
455                "KMSInvalidStateException" => crate::operation::encrypt::EncryptError::KmsInvalidStateException({
456                    let mut deser = protocol.deserialize_error_response(response, _cfg).map_err(|e| {
457                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
458                            e,
459                        ))
460                    })?;
461                    let mut tmp = <crate::types::error::builders::KmsInvalidStateExceptionBuilder>::default();
462                    tmp.deserialize_members(&mut *deser).map_err(|e| {
463                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
464                            e,
465                        ))
466                    })?;
467                    if tmp.message.is_none() {
468                        tmp.message = _error_message;
469                    }
470                    let tmp = tmp.meta(generic);
471                    tmp.build()
472                }),
473                "NotFoundException" => crate::operation::encrypt::EncryptError::NotFoundException({
474                    let mut deser = protocol.deserialize_error_response(response, _cfg).map_err(|e| {
475                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
476                            e,
477                        ))
478                    })?;
479                    let mut tmp = <crate::types::error::builders::NotFoundExceptionBuilder>::default();
480                    tmp.deserialize_members(&mut *deser).map_err(|e| {
481                        ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(
482                            e,
483                        ))
484                    })?;
485                    if tmp.message.is_none() {
486                        tmp.message = _error_message;
487                    }
488                    let tmp = tmp.meta(generic);
489                    tmp.build()
490                }),
491                _ => {
492                    // Registry-backed, operation-scoped reification of an error whose
493                    // code this operation does not model directly: the operation's own
494                    // error registry is consulted first, then the lookup widens to the
495                    // service-wide error registry. On a hit, the reified error is attached
496                    // as the source of the returned unhandled error while its metadata
497                    // (code, message, request id) is preserved; on a miss the generic
498                    // error is returned unchanged.
499                    match protocol
500                        .deserialize_error_response(response, _cfg)
501                        .ok()
502                        .and_then(|mut deser| {
503                            ::aws_smithy_schema::registry::reify_error(
504                                crate::operation::encrypt::error_registry::REGISTRY
505                                    .or(&crate::error_type_registry::REGISTRY),
506                                error_code,
507                                &mut *deser,
508                            )
509                        }) {
510                        ::std::option::Option::Some(source) => <crate::operation::encrypt::EncryptError as ::aws_smithy_runtime_api::client::result::CreateUnhandledError>::create_unhandled_error(source, ::std::option::Option::Some(generic)),
511                        ::std::option::Option::None => crate::operation::encrypt::EncryptError::generic(generic),
512                    }
513                }
514            };
515            ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::operation(
516                ::aws_smithy_runtime_api::client::interceptors::context::Error::erase(err),
517            ))
518        } else {
519            let protocol = _cfg
520                .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
521                .expect("a SharedClientProtocol is required");
522            let mut deser = protocol.deserialize_response(response, Encrypt::OUTPUT_SCHEMA, _cfg).map_err(|e| {
523                ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(e))
524            })?;
525            // `headers` is already in scope from the top of the function; alias it as
526            // `_response_headers` so MutateOutput customizations have a stable name to
527            // read from.
528            let _response_headers = headers;
529            // `mut` is required because `deserialize_members` and the `MutateOutput`
530            // builder setters take `&mut self`. Marked `allow(unused_mut)` because an
531            // empty output has no members and no customizations to run.
532            #[allow(unused_mut)]
533            let mut output = <crate::operation::encrypt::builders::EncryptOutputBuilder>::default();
534            output.deserialize_members(&mut *deser).map_err(|e| {
535                ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(e))
536            })?;
537            output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
538            let output = output.build();
539            ::std::result::Result::Ok(::aws_smithy_runtime_api::client::interceptors::context::Output::erase(output))
540        }
541    }
542}
543#[derive(Debug)]
544struct EncryptRequestSerializer;
545impl ::aws_smithy_runtime_api::client::ser_de::SerializeRequest for EncryptRequestSerializer {
546    #[allow(unused_mut, clippy::let_and_return, clippy::needless_borrow, clippy::useless_conversion)]
547    fn serialize_input(
548        &self,
549        input: ::aws_smithy_runtime_api::client::interceptors::context::Input,
550        _cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
551    ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, ::aws_smithy_runtime_api::box_error::BoxError> {
552        let input = input.downcast::<crate::operation::encrypt::EncryptInput>().expect("correct type");
553
554        let protocol = _cfg
555            .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
556            .expect("a SharedClientProtocol is required");
557        let mut request = protocol
558            .serialize_request(&input, Encrypt::INPUT_SCHEMA, "/", _cfg)
559            .map_err(::aws_smithy_runtime_api::box_error::BoxError::from)?;
560
561        return ::std::result::Result::Ok(request);
562    }
563}
564#[derive(Debug)]
565struct EncryptEndpointParamsInterceptor;
566
567#[::aws_smithy_runtime_api::client::interceptors::dyn_dispatch_hint]
568impl ::aws_smithy_runtime_api::client::interceptors::Intercept for EncryptEndpointParamsInterceptor {
569    fn name(&self) -> &'static str {
570        "EncryptEndpointParamsInterceptor"
571    }
572
573    fn read_before_execution(
574        &self,
575        context: &::aws_smithy_runtime_api::client::interceptors::context::BeforeSerializationInterceptorContextRef<
576            '_,
577            ::aws_smithy_runtime_api::client::interceptors::context::Input,
578            ::aws_smithy_runtime_api::client::interceptors::context::Output,
579            ::aws_smithy_runtime_api::client::interceptors::context::Error,
580        >,
581        cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
582    ) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
583        let _input = context
584            .input()
585            .downcast_ref::<EncryptInput>()
586            .ok_or("failed to downcast to EncryptInput")?;
587
588        let params = crate::config::endpoint::Params::builder()
589            .set_region(cfg.load::<::aws_types::region::Region>().map(|r| r.as_ref().to_owned()))
590            .set_use_dual_stack(cfg.load::<::aws_types::endpoint_config::UseDualStack>().map(|ty| ty.0))
591            .set_use_fips(cfg.load::<::aws_types::endpoint_config::UseFips>().map(|ty| ty.0))
592            .set_endpoint(cfg.load::<::aws_types::endpoint_config::EndpointUrl>().map(|ty| ty.0.clone()))
593            .build()
594            .map_err(|err| {
595                ::aws_smithy_runtime_api::client::interceptors::error::ContextAttachedError::new("endpoint params could not be built", err)
596            })?;
597        cfg.interceptor_state()
598            .store_put(::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams::new(params));
599        ::std::result::Result::Ok(())
600    }
601}
602
603// The get_* functions below are generated from JMESPath expressions in the
604// operationContextParams trait. They target the operation's input shape.
605
606/// Error type for the `EncryptError` operation.
607#[non_exhaustive]
608#[derive(::std::fmt::Debug)]
609pub enum EncryptError {
610    /// <p>The system timed out while trying to fulfill the request. You can retry the request.</p>
611    DependencyTimeoutException(crate::types::error::DependencyTimeoutException),
612    /// <p>The request was rejected because the specified KMS key is not enabled.</p>
613    DisabledException(crate::types::error::DisabledException),
614    /// <p>The request was rejected because the DryRun parameter was specified.</p>
615    DryRunOperationException(crate::types::error::DryRunOperationException),
616    /// <p>The request was rejected because the specified grant token is not valid.</p>
617    InvalidGrantTokenException(crate::types::error::InvalidGrantTokenException),
618    /// <p>The request was rejected for one of the following reasons:</p>
619    /// <ul>
620    /// <li>
621    /// <p>The <code>KeyUsage</code> value of the KMS key is incompatible with the API operation.</p></li>
622    /// <li>
623    /// <p>The encryption algorithm or signing algorithm specified for the operation is incompatible with the type of key material in the KMS key <code>(KeySpec</code>).</p></li>
624    /// </ul>
625    /// <p>For encrypting, decrypting, re-encrypting, and generating data keys, the <code>KeyUsage</code> must be <code>ENCRYPT_DECRYPT</code>. For signing and verifying messages, the <code>KeyUsage</code> must be <code>SIGN_VERIFY</code>. For generating and verifying message authentication codes (MACs), the <code>KeyUsage</code> must be <code>GENERATE_VERIFY_MAC</code>. For deriving key agreement secrets, the <code>KeyUsage</code> must be <code>KEY_AGREEMENT</code>. For encapsulating and decapsulating shared secrets, the <code>KeyUsage</code> must be <code>ENCAPSULATE_DECAPSULATE</code>. To find the <code>KeyUsage</code> of a KMS key, use the <code>DescribeKey</code> operation.</p>
626    /// <p>To find the encryption or signing algorithms supported for a particular KMS key, use the <code>DescribeKey</code> operation.</p>
627    InvalidKeyUsageException(crate::types::error::InvalidKeyUsageException),
628    /// <p>The request was rejected because the specified KMS key was not available. You can retry the request.</p>
629    KeyUnavailableException(crate::types::error::KeyUnavailableException),
630    /// <p>The request was rejected because an internal exception occurred. The request can be retried.</p>
631    KmsInternalException(crate::types::error::KmsInternalException),
632    /// <p>The request was rejected because the state of the specified resource is not valid for this request.</p>
633    /// <p>This exceptions means one of the following:</p>
634    /// <ul>
635    /// <li>
636    /// <p>The key state of the KMS key is not compatible with the operation.</p>
637    /// <p>To find the key state, use the <code>DescribeKey</code> operation. For more information about which key states are compatible with each KMS operation, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html">Key states of KMS keys</a> in the <i> <i>Key Management Service Developer Guide</i> </i>.</p></li>
638    /// <li>
639    /// <p>For cryptographic operations on KMS keys in custom key stores, this exception represents a general failure with many possible causes. To identify the cause, see the error message that accompanies the exception.</p></li>
640    /// </ul>
641    KmsInvalidStateException(crate::types::error::KmsInvalidStateException),
642    /// <p>The request was rejected because the specified entity or resource could not be found.</p>
643    NotFoundException(crate::types::error::NotFoundException),
644    /// An unexpected error occurred (e.g., invalid JSON returned by the service or an unknown error code).
645    #[deprecated(note = "Matching `Unhandled` directly is not forwards compatible. Instead, match using a \
646    variable wildcard pattern and check `.code()`:
647     \
648    &nbsp;&nbsp;&nbsp;`err if err.code() == Some(\"SpecificExceptionCode\") => { /* handle the error */ }`
649     \
650    See [`ProvideErrorMetadata`](#impl-ProvideErrorMetadata-for-EncryptError) for what information is available for the error.")]
651    Unhandled(crate::error::sealed_unhandled::Unhandled),
652}
653impl EncryptError {
654    /// Creates the `EncryptError::Unhandled` variant from any error type.
655    pub fn unhandled(
656        err: impl ::std::convert::Into<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>>,
657    ) -> Self {
658        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
659            source: err.into(),
660            meta: ::std::default::Default::default(),
661        })
662    }
663
664    /// Creates the `EncryptError::Unhandled` variant from an [`ErrorMetadata`](::aws_smithy_types::error::ErrorMetadata).
665    pub fn generic(err: ::aws_smithy_types::error::ErrorMetadata) -> Self {
666        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
667            source: err.clone().into(),
668            meta: err,
669        })
670    }
671    ///
672    /// Returns error metadata, which includes the error code, message,
673    /// request ID, and potentially additional information.
674    ///
675    pub fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
676        match self {
677            Self::DependencyTimeoutException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
678            Self::DisabledException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
679            Self::DryRunOperationException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
680            Self::InvalidGrantTokenException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
681            Self::InvalidKeyUsageException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
682            Self::KeyUnavailableException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
683            Self::KmsInternalException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
684            Self::KmsInvalidStateException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
685            Self::NotFoundException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
686            Self::Unhandled(e) => &e.meta,
687        }
688    }
689    /// Returns `true` if the error kind is `EncryptError::DependencyTimeoutException`.
690    pub fn is_dependency_timeout_exception(&self) -> bool {
691        matches!(self, Self::DependencyTimeoutException(_))
692    }
693    /// Returns `true` if the error kind is `EncryptError::DisabledException`.
694    pub fn is_disabled_exception(&self) -> bool {
695        matches!(self, Self::DisabledException(_))
696    }
697    /// Returns `true` if the error kind is `EncryptError::DryRunOperationException`.
698    pub fn is_dry_run_operation_exception(&self) -> bool {
699        matches!(self, Self::DryRunOperationException(_))
700    }
701    /// Returns `true` if the error kind is `EncryptError::InvalidGrantTokenException`.
702    pub fn is_invalid_grant_token_exception(&self) -> bool {
703        matches!(self, Self::InvalidGrantTokenException(_))
704    }
705    /// Returns `true` if the error kind is `EncryptError::InvalidKeyUsageException`.
706    pub fn is_invalid_key_usage_exception(&self) -> bool {
707        matches!(self, Self::InvalidKeyUsageException(_))
708    }
709    /// Returns `true` if the error kind is `EncryptError::KeyUnavailableException`.
710    pub fn is_key_unavailable_exception(&self) -> bool {
711        matches!(self, Self::KeyUnavailableException(_))
712    }
713    /// Returns `true` if the error kind is `EncryptError::KmsInternalException`.
714    pub fn is_kms_internal_exception(&self) -> bool {
715        matches!(self, Self::KmsInternalException(_))
716    }
717    /// Returns `true` if the error kind is `EncryptError::KmsInvalidStateException`.
718    pub fn is_kms_invalid_state_exception(&self) -> bool {
719        matches!(self, Self::KmsInvalidStateException(_))
720    }
721    /// Returns `true` if the error kind is `EncryptError::NotFoundException`.
722    pub fn is_not_found_exception(&self) -> bool {
723        matches!(self, Self::NotFoundException(_))
724    }
725}
726impl ::std::error::Error for EncryptError {
727    fn source(&self) -> ::std::option::Option<&(dyn ::std::error::Error + 'static)> {
728        match self {
729            Self::DependencyTimeoutException(_inner) => ::std::option::Option::Some(_inner),
730            Self::DisabledException(_inner) => ::std::option::Option::Some(_inner),
731            Self::DryRunOperationException(_inner) => ::std::option::Option::Some(_inner),
732            Self::InvalidGrantTokenException(_inner) => ::std::option::Option::Some(_inner),
733            Self::InvalidKeyUsageException(_inner) => ::std::option::Option::Some(_inner),
734            Self::KeyUnavailableException(_inner) => ::std::option::Option::Some(_inner),
735            Self::KmsInternalException(_inner) => ::std::option::Option::Some(_inner),
736            Self::KmsInvalidStateException(_inner) => ::std::option::Option::Some(_inner),
737            Self::NotFoundException(_inner) => ::std::option::Option::Some(_inner),
738            Self::Unhandled(_inner) => ::std::option::Option::Some(&*_inner.source),
739        }
740    }
741}
742impl ::std::fmt::Display for EncryptError {
743    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
744        match self {
745            Self::DependencyTimeoutException(_inner) => _inner.fmt(f),
746            Self::DisabledException(_inner) => _inner.fmt(f),
747            Self::DryRunOperationException(_inner) => _inner.fmt(f),
748            Self::InvalidGrantTokenException(_inner) => _inner.fmt(f),
749            Self::InvalidKeyUsageException(_inner) => _inner.fmt(f),
750            Self::KeyUnavailableException(_inner) => _inner.fmt(f),
751            Self::KmsInternalException(_inner) => _inner.fmt(f),
752            Self::KmsInvalidStateException(_inner) => _inner.fmt(f),
753            Self::NotFoundException(_inner) => _inner.fmt(f),
754            Self::Unhandled(_inner) => {
755                if let ::std::option::Option::Some(code) = ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self) {
756                    write!(f, "unhandled error ({code})")
757                } else {
758                    f.write_str("unhandled error")
759                }
760            }
761        }
762    }
763}
764impl ::aws_smithy_types::retry::ProvideErrorKind for EncryptError {
765    fn code(&self) -> ::std::option::Option<&str> {
766        ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self)
767    }
768    fn retryable_error_kind(&self) -> ::std::option::Option<::aws_smithy_types::retry::ErrorKind> {
769        ::std::option::Option::None
770    }
771}
772impl ::aws_smithy_types::error::metadata::ProvideErrorMetadata for EncryptError {
773    fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
774        match self {
775            Self::DependencyTimeoutException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
776            Self::DisabledException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
777            Self::DryRunOperationException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
778            Self::InvalidGrantTokenException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
779            Self::InvalidKeyUsageException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
780            Self::KeyUnavailableException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
781            Self::KmsInternalException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
782            Self::KmsInvalidStateException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
783            Self::NotFoundException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
784            Self::Unhandled(_inner) => &_inner.meta,
785        }
786    }
787}
788impl ::aws_smithy_runtime_api::client::result::CreateUnhandledError for EncryptError {
789    fn create_unhandled_error(
790        source: ::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>,
791        meta: ::std::option::Option<::aws_smithy_types::error::ErrorMetadata>,
792    ) -> Self {
793        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
794            source,
795            meta: meta.unwrap_or_default(),
796        })
797    }
798}
799impl ::aws_types::request_id::RequestId for crate::operation::encrypt::EncryptError {
800    fn request_id(&self) -> Option<&str> {
801        self.meta().request_id()
802    }
803}
804
805pub use crate::operation::encrypt::_encrypt_input::EncryptInput;
806
807pub use crate::operation::encrypt::_encrypt_output::EncryptOutput;
808
809mod _encrypt_input;
810
811mod _encrypt_output;
812
813/// Builders
814pub mod builders;