From 79ead4884c206f1c41eacb5e61feab2a96c06173 Mon Sep 17 00:00:00 2001 From: Chris Holcombe Date: Fri, 26 May 2023 14:02:36 -0700 Subject: [PATCH] Make SigningInstructions public (#2730) ## Motivation and Context I'm building an s3 server in rust and I need signature verification to work from the server side when receiving requests. To do that the server needs to generate a signature and then compare it to the one that the client has already sent along. I believe that the sign module in aws-sigv4 http_request contains the functions required to do that. ## Description Exported the `SigningInstructions` struct in the sign module of http_request for aws-sigv4. ## Testing _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --------- Co-authored-by: Chris Holcombe Co-authored-by: John DiSanti --- CHANGELOG.next.toml | 6 ++++++ aws/rust-runtime/aws-sigv4/src/http_request/mod.rs | 2 +- aws/rust-runtime/aws-sigv4/src/http_request/sign.rs | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index f81531ff73..51319b5986 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -62,3 +62,9 @@ message = "For event stream operations, the `EventStreamSender` in inputs/output references = ["smithy-rs#2673"] meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all"} author = "jdisanti" + +[[aws-sdk-rust]] +message = "The `SigningInstructions` in the `aws-sigv4` module are now public. This allows them to be named in a function signature." +references = ["smithy-rs#2730"] +author = "cholcombe973" +meta = { "breaking" = false, "tada" = false, "bug" = true } diff --git a/aws/rust-runtime/aws-sigv4/src/http_request/mod.rs b/aws/rust-runtime/aws-sigv4/src/http_request/mod.rs index 023c142997..db021bbee5 100644 --- a/aws/rust-runtime/aws-sigv4/src/http_request/mod.rs +++ b/aws/rust-runtime/aws-sigv4/src/http_request/mod.rs @@ -56,4 +56,4 @@ pub use settings::{ PayloadChecksumKind, PercentEncodingMode, SessionTokenMode, SignatureLocation, SigningParams, SigningSettings, UriPathNormalizationMode, }; -pub use sign::{sign, SignableBody, SignableRequest}; +pub use sign::{sign, SignableBody, SignableRequest, SigningInstructions}; diff --git a/aws/rust-runtime/aws-sigv4/src/http_request/sign.rs b/aws/rust-runtime/aws-sigv4/src/http_request/sign.rs index b716b9fd40..69d646daa2 100644 --- a/aws/rust-runtime/aws-sigv4/src/http_request/sign.rs +++ b/aws/rust-runtime/aws-sigv4/src/http_request/sign.rs @@ -103,6 +103,7 @@ pub enum SignableBody<'a> { StreamingUnsignedPayloadTrailer, } +/// Instructions for applying a signature to an HTTP request. #[derive(Debug)] pub struct SigningInstructions { headers: Option>, @@ -117,20 +118,27 @@ impl SigningInstructions { Self { headers, params } } + /// Returns a reference to the headers that should be added to the request. pub fn headers(&self) -> Option<&HeaderMap> { self.headers.as_ref() } + + /// Returns the headers and sets the internal value to `None`. pub fn take_headers(&mut self) -> Option> { self.headers.take() } + /// Returns a reference to the query parameters that should be added to the request. pub fn params(&self) -> Option<&Vec<(&'static str, Cow<'static, str>)>> { self.params.as_ref() } + + /// Returns the query parameters and sets the internal value to `None`. pub fn take_params(&mut self) -> Option)>> { self.params.take() } + /// Applies the instructions to the given `request`. pub fn apply_to_request(mut self, request: &mut http::Request) { if let Some(new_headers) = self.take_headers() { for (name, value) in new_headers.into_iter() {