Skip to content

Commit

Permalink
Make SigningInstructions public (#2730)
Browse files Browse the repository at this point in the history
## 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: Chris Holcombe <[email protected]>
Co-authored-by: John DiSanti <[email protected]>
  • Loading branch information
3 people authored May 26, 2023
1 parent 9fe5d55 commit 79ead48
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-sigv4/src/http_request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 8 additions & 0 deletions aws/rust-runtime/aws-sigv4/src/http_request/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
Expand All @@ -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() {
Expand Down

0 comments on commit 79ead48

Please sign in to comment.