aws_sdk_kms/protocol_serde/
shape_derive_shared_secret.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2#[allow(clippy::unnecessary_wraps)]
3pub fn de_derive_shared_secret_http_error(
4    _response_status: u16,
5    _response_headers: &::aws_smithy_runtime_api::http::Headers,
6    _response_body: &[u8],
7) -> std::result::Result<
8    crate::operation::derive_shared_secret::DeriveSharedSecretOutput,
9    crate::operation::derive_shared_secret::DeriveSharedSecretError,
10> {
11    #[allow(unused_mut)]
12    let mut generic_builder = crate::protocol_serde::parse_http_error_metadata(_response_status, _response_headers, _response_body)
13        .map_err(crate::operation::derive_shared_secret::DeriveSharedSecretError::unhandled)?;
14    generic_builder = ::aws_types::request_id::apply_request_id(generic_builder, _response_headers);
15    let generic = generic_builder.build();
16    let error_code = match generic.code() {
17        Some(code) => code,
18        None => return Err(crate::operation::derive_shared_secret::DeriveSharedSecretError::unhandled(generic)),
19    };
20
21    let _error_message = generic.message().map(|msg| msg.to_owned());
22    Err(match error_code {
23        "DependencyTimeoutException" => crate::operation::derive_shared_secret::DeriveSharedSecretError::DependencyTimeoutException({
24            #[allow(unused_mut)]
25            let mut tmp = {
26                #[allow(unused_mut)]
27                let mut output = crate::types::error::builders::DependencyTimeoutExceptionBuilder::default();
28                output = crate::protocol_serde::shape_dependency_timeout_exception::de_dependency_timeout_exception_json_err(_response_body, output)
29                    .map_err(crate::operation::derive_shared_secret::DeriveSharedSecretError::unhandled)?;
30                let output = output.meta(generic);
31                output.build()
32            };
33            if tmp.message.is_none() {
34                tmp.message = _error_message;
35            }
36            tmp
37        }),
38        "DisabledException" => crate::operation::derive_shared_secret::DeriveSharedSecretError::DisabledException({
39            #[allow(unused_mut)]
40            let mut tmp = {
41                #[allow(unused_mut)]
42                let mut output = crate::types::error::builders::DisabledExceptionBuilder::default();
43                output = crate::protocol_serde::shape_disabled_exception::de_disabled_exception_json_err(_response_body, output)
44                    .map_err(crate::operation::derive_shared_secret::DeriveSharedSecretError::unhandled)?;
45                let output = output.meta(generic);
46                output.build()
47            };
48            if tmp.message.is_none() {
49                tmp.message = _error_message;
50            }
51            tmp
52        }),
53        "DryRunOperationException" => crate::operation::derive_shared_secret::DeriveSharedSecretError::DryRunOperationException({
54            #[allow(unused_mut)]
55            let mut tmp = {
56                #[allow(unused_mut)]
57                let mut output = crate::types::error::builders::DryRunOperationExceptionBuilder::default();
58                output = crate::protocol_serde::shape_dry_run_operation_exception::de_dry_run_operation_exception_json_err(_response_body, output)
59                    .map_err(crate::operation::derive_shared_secret::DeriveSharedSecretError::unhandled)?;
60                let output = output.meta(generic);
61                output.build()
62            };
63            if tmp.message.is_none() {
64                tmp.message = _error_message;
65            }
66            tmp
67        }),
68        "InvalidGrantTokenException" => crate::operation::derive_shared_secret::DeriveSharedSecretError::InvalidGrantTokenException({
69            #[allow(unused_mut)]
70            let mut tmp = {
71                #[allow(unused_mut)]
72                let mut output = crate::types::error::builders::InvalidGrantTokenExceptionBuilder::default();
73                output =
74                    crate::protocol_serde::shape_invalid_grant_token_exception::de_invalid_grant_token_exception_json_err(_response_body, output)
75                        .map_err(crate::operation::derive_shared_secret::DeriveSharedSecretError::unhandled)?;
76                let output = output.meta(generic);
77                output.build()
78            };
79            if tmp.message.is_none() {
80                tmp.message = _error_message;
81            }
82            tmp
83        }),
84        "InvalidKeyUsageException" => crate::operation::derive_shared_secret::DeriveSharedSecretError::InvalidKeyUsageException({
85            #[allow(unused_mut)]
86            let mut tmp = {
87                #[allow(unused_mut)]
88                let mut output = crate::types::error::builders::InvalidKeyUsageExceptionBuilder::default();
89                output = crate::protocol_serde::shape_invalid_key_usage_exception::de_invalid_key_usage_exception_json_err(_response_body, output)
90                    .map_err(crate::operation::derive_shared_secret::DeriveSharedSecretError::unhandled)?;
91                let output = output.meta(generic);
92                output.build()
93            };
94            if tmp.message.is_none() {
95                tmp.message = _error_message;
96            }
97            tmp
98        }),
99        "KeyUnavailableException" => crate::operation::derive_shared_secret::DeriveSharedSecretError::KeyUnavailableException({
100            #[allow(unused_mut)]
101            let mut tmp = {
102                #[allow(unused_mut)]
103                let mut output = crate::types::error::builders::KeyUnavailableExceptionBuilder::default();
104                output = crate::protocol_serde::shape_key_unavailable_exception::de_key_unavailable_exception_json_err(_response_body, output)
105                    .map_err(crate::operation::derive_shared_secret::DeriveSharedSecretError::unhandled)?;
106                let output = output.meta(generic);
107                output.build()
108            };
109            if tmp.message.is_none() {
110                tmp.message = _error_message;
111            }
112            tmp
113        }),
114        "KMSInternalException" => crate::operation::derive_shared_secret::DeriveSharedSecretError::KmsInternalException({
115            #[allow(unused_mut)]
116            let mut tmp = {
117                #[allow(unused_mut)]
118                let mut output = crate::types::error::builders::KmsInternalExceptionBuilder::default();
119                output = crate::protocol_serde::shape_kms_internal_exception::de_kms_internal_exception_json_err(_response_body, output)
120                    .map_err(crate::operation::derive_shared_secret::DeriveSharedSecretError::unhandled)?;
121                let output = output.meta(generic);
122                output.build()
123            };
124            if tmp.message.is_none() {
125                tmp.message = _error_message;
126            }
127            tmp
128        }),
129        "KMSInvalidStateException" => crate::operation::derive_shared_secret::DeriveSharedSecretError::KmsInvalidStateException({
130            #[allow(unused_mut)]
131            let mut tmp = {
132                #[allow(unused_mut)]
133                let mut output = crate::types::error::builders::KmsInvalidStateExceptionBuilder::default();
134                output = crate::protocol_serde::shape_kms_invalid_state_exception::de_kms_invalid_state_exception_json_err(_response_body, output)
135                    .map_err(crate::operation::derive_shared_secret::DeriveSharedSecretError::unhandled)?;
136                let output = output.meta(generic);
137                output.build()
138            };
139            if tmp.message.is_none() {
140                tmp.message = _error_message;
141            }
142            tmp
143        }),
144        "NotFoundException" => crate::operation::derive_shared_secret::DeriveSharedSecretError::NotFoundException({
145            #[allow(unused_mut)]
146            let mut tmp = {
147                #[allow(unused_mut)]
148                let mut output = crate::types::error::builders::NotFoundExceptionBuilder::default();
149                output = crate::protocol_serde::shape_not_found_exception::de_not_found_exception_json_err(_response_body, output)
150                    .map_err(crate::operation::derive_shared_secret::DeriveSharedSecretError::unhandled)?;
151                let output = output.meta(generic);
152                output.build()
153            };
154            if tmp.message.is_none() {
155                tmp.message = _error_message;
156            }
157            tmp
158        }),
159        _ => crate::operation::derive_shared_secret::DeriveSharedSecretError::generic(generic),
160    })
161}
162
163#[allow(clippy::unnecessary_wraps)]
164pub fn de_derive_shared_secret_http_response(
165    _response_status: u16,
166    _response_headers: &::aws_smithy_runtime_api::http::Headers,
167    _response_body: &[u8],
168) -> std::result::Result<
169    crate::operation::derive_shared_secret::DeriveSharedSecretOutput,
170    crate::operation::derive_shared_secret::DeriveSharedSecretError,
171> {
172    Ok({
173        #[allow(unused_mut)]
174        let mut output = crate::operation::derive_shared_secret::builders::DeriveSharedSecretOutputBuilder::default();
175        output = crate::protocol_serde::shape_derive_shared_secret::de_derive_shared_secret(_response_body, output)
176            .map_err(crate::operation::derive_shared_secret::DeriveSharedSecretError::unhandled)?;
177        output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
178        output.build()
179    })
180}
181
182pub fn ser_derive_shared_secret_input(
183    input: &crate::operation::derive_shared_secret::DeriveSharedSecretInput,
184) -> Result<::aws_smithy_types::body::SdkBody, ::aws_smithy_types::error::operation::SerializationError> {
185    let mut out = String::new();
186    let mut object = ::aws_smithy_json::serialize::JsonObjectWriter::new(&mut out);
187    crate::protocol_serde::shape_derive_shared_secret_input::ser_derive_shared_secret_input_input(&mut object, input)?;
188    object.finish();
189    Ok(::aws_smithy_types::body::SdkBody::from(out))
190}
191
192pub(crate) fn de_derive_shared_secret(
193    value: &[u8],
194    mut builder: crate::operation::derive_shared_secret::builders::DeriveSharedSecretOutputBuilder,
195) -> Result<crate::operation::derive_shared_secret::builders::DeriveSharedSecretOutputBuilder, ::aws_smithy_json::deserialize::error::DeserializeError>
196{
197    let mut tokens_owned = ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(value)).peekable();
198    let tokens = &mut tokens_owned;
199    ::aws_smithy_json::deserialize::token::expect_start_object(tokens.next())?;
200    loop {
201        match tokens.next().transpose()? {
202            Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
203            Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
204                "KeyId" => {
205                    builder = builder.set_key_id(
206                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
207                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
208                            .transpose()?,
209                    );
210                }
211                "SharedSecret" => {
212                    builder = builder.set_shared_secret(::aws_smithy_json::deserialize::token::expect_blob_or_null(tokens.next())?);
213                }
214                "CiphertextForRecipient" => {
215                    builder = builder.set_ciphertext_for_recipient(::aws_smithy_json::deserialize::token::expect_blob_or_null(tokens.next())?);
216                }
217                "KeyAgreementAlgorithm" => {
218                    builder = builder.set_key_agreement_algorithm(
219                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
220                            .map(|s| s.to_unescaped().map(|u| crate::types::KeyAgreementAlgorithmSpec::from(u.as_ref())))
221                            .transpose()?,
222                    );
223                }
224                "KeyOrigin" => {
225                    builder = builder.set_key_origin(
226                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
227                            .map(|s| s.to_unescaped().map(|u| crate::types::OriginType::from(u.as_ref())))
228                            .transpose()?,
229                    );
230                }
231                _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
232            },
233            other => {
234                return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
235                    "expected object key or end object, found: {:?}",
236                    other
237                )))
238            }
239        }
240    }
241    if tokens.next().is_some() {
242        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
243            "found more JSON tokens after completing parsing",
244        ));
245    }
246    Ok(builder)
247}