Skip to content

Commit

Permalink
change http checksums to be base64 encoded (#615)
Browse files Browse the repository at this point in the history
* change http checksums to be base64 encoded

due to a misreading of the spec, the http checksums where hex encoded when they should actually be base64 encoded

* Update changelog
  • Loading branch information
rcoh authored Jul 28, 2021
1 parent 6201a38 commit a50c966
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## vNext (Month Day Year)
**New This Week**
- :bug: Correctly encode HTTP Checksums using base64 instead of hex. Fixes aws-sdk-rust#164. (#615)
- (When complete) Add profile file provider for region (#594, #xyz)

## v0.18.1 (July 27th 2021)
Expand Down
2 changes: 1 addition & 1 deletion aws/sdk/aws-models/s3-tests.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ apply PutBucketLifecycleConfiguration @httpRequestTests([
headers: {
// we can assert this, but when this test is promoted, it can't assert
// on the exact contents
"content-md5": "b14bbeb8064f913b40c4975a03ef6e4a",
"content-md5": "sUu+uAZPkTtAxJdaA+9uSg==",
},
bodyMediaType: "application/xml",
body: """
Expand Down
2 changes: 1 addition & 1 deletion codegen-test/model/rest-xml-extras.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ map XmlMapsNestedNestedNamespaceInputOutputMap {
params: {
field: "hello"
},
headers: { "Content-Md5": "240240a9803ad7032101319e42a45c31" },
headers: { "Content-Md5": "JAJAqYA61wMhATGeQqRcMQ==" },
protocol: "aws.protocols#restXml"
}])
@httpChecksumRequired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import software.amazon.smithy.rust.codegen.rustlang.Writable
import software.amazon.smithy.rust.codegen.rustlang.asType
import software.amazon.smithy.rust.codegen.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.rustlang.writable
import software.amazon.smithy.rust.codegen.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.smithy.customize.OperationCustomization
import software.amazon.smithy.rust.codegen.smithy.customize.OperationSection
import software.amazon.smithy.rust.codegen.smithy.generators.ProtocolConfig
Expand Down Expand Up @@ -46,13 +47,14 @@ class HttpChecksumRequiredGenerator(
let checksum = #{md5}::compute(data);
req.headers_mut().insert(
#{http}::header::HeaderName::from_static("content-md5"),
format!("{:x}", checksum).parse().expect("checksum is valid header value")
#{base64_encode}(&checksum[..]).parse().expect("checksum is valid header value")
);
Result::<_, #{BuildError}>::Ok(req)
})?;
""",
"md5" to CargoDependency.Md5.asType(),
"http" to CargoDependency.Http.asType(),
"base64_encode" to RuntimeType.Base64Encode(protocolConfig.runtimeConfig),
"BuildError" to protocolConfig.runtimeConfig.operationBuildError()
)
}
Expand Down

0 comments on commit a50c966

Please sign in to comment.