Unverified Commit 79ead488 authored by Chris Holcombe's avatar Chris Holcombe Committed by GitHub
Browse files

Make SigningInstructions public (#2730)



## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->
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.

<!--- If it fixes an open issue, please link to the issue here -->

## Description
<!--- Describe your changes in detail -->
Exported the `SigningInstructions` struct in the sign module of
http_request for aws-sigv4.

## Testing
<!--- Please describe in detail how you tested your changes -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->


_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: default avatarChris Holcombe <chholcombe@tesla.com>
Co-authored-by: default avatarJohn DiSanti <jdisanti@amazon.com>
parent 9fe5d55c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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 }
+1 −1
Original line number Diff line number Diff line
@@ -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};
+8 −0
Original line number Diff line number Diff line
@@ -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<HeaderMap<HeaderValue>>,
@@ -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<HeaderValue>> {
        self.headers.as_ref()
    }

    /// Returns the headers and sets the internal value to `None`.
    pub fn take_headers(&mut self) -> Option<HeaderMap<HeaderValue>> {
        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<Vec<(&'static str, Cow<'static, str>)>> {
        self.params.take()
    }

    /// Applies the instructions to the given `request`.
    pub fn apply_to_request<B>(mut self, request: &mut http::Request<B>) {
        if let Some(new_headers) = self.take_headers() {
            for (name, value) in new_headers.into_iter() {