From 6f72954eda8a040a13176083543019c80bd092a7 Mon Sep 17 00:00:00 2001 From: Petros Angelatos Date: Mon, 23 May 2022 14:50:19 +0200 Subject: [PATCH 1/2] Use md5 implementation of RustCrypto organization Signed-off-by: Petros Angelatos --- CHANGELOG.next.toml | 18 ++++++++++++++++++ .../rust/codegen/rustlang/CargoDependency.kt | 7 ++++--- .../HttpChecksumRequiredGenerator.kt | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 659f4c605b..ff97dff4e9 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -28,3 +28,21 @@ author = "alonlud" references = ["smithy-rs#1390"] meta = { "breaking" = false, "tada" = true, "bug" = false } author = "Velfi" + +[[smithy-rs]] +message = "Add ability to specify a different rust crate name than the one derived from the package name" +references = ["smithy-rs#1404"] +meta = { "breaking" = false, "tada" = false, "bug" = false } +author = "petrosagg" + +[[smithy-rs]] +message = "Switch to [RustCrypto](https://github.com/RustCrypto)'s implementation of MD5." +references = ["smithy-rs#1404"] +meta = { "breaking" = false, "tada" = false, "bug" = false } +author = "petrosagg" + +[[aws-sdk-rust]] +message = "Switch to [RustCrypto](https://github.com/RustCrypto)'s implementation of MD5." +references = ["smithy-rs#1404"] +meta = { "breaking" = false, "tada" = false, "bug" = false } +author = "petrosagg" diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt index 147d8941fa..03893ddf94 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt @@ -128,7 +128,8 @@ data class CargoDependency( private val location: DependencyLocation, val scope: DependencyScope = DependencyScope.Compile, val optional: Boolean = false, - val features: Set = emptySet() + val features: Set = emptySet(), + val crateName: String = name.replace("-", "_") ) : RustDependency(name) { val key: Triple get() = Triple(name, location, scope) @@ -143,7 +144,7 @@ data class CargoDependency( is Local -> "local" } - fun rustName(name: String): RuntimeType = RuntimeType(name, this, this.name.replace("-", "_")) + fun rustName(name: String): RuntimeType = RuntimeType(name, this, this.crateName) fun toMap(): Map { val attribs = mutableMapOf() @@ -199,7 +200,7 @@ data class CargoDependency( val Hyper: CargoDependency = CargoDependency("hyper", CratesIo("0.14")) val HyperWithStream: CargoDependency = Hyper.withFeature("stream") val LazyStatic: CargoDependency = CargoDependency("lazy_static", CratesIo("1.4")) - val Md5: CargoDependency = CargoDependency("md5", CratesIo("0.7")) + val Md5: CargoDependency = CargoDependency("md-5", CratesIo("0.10"), crateName = "md5") val PercentEncoding: CargoDependency = CargoDependency("percent-encoding", CratesIo("2")) val PrettyAssertions: CargoDependency = CargoDependency("pretty_assertions", CratesIo("1"), scope = DependencyScope.Dev) val Regex: CargoDependency = CargoDependency("regex", CratesIo("1")) diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/customizations/HttpChecksumRequiredGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/customizations/HttpChecksumRequiredGenerator.kt index 72bbbbc9f1..5790d16023 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/customizations/HttpChecksumRequiredGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/customizations/HttpChecksumRequiredGenerator.kt @@ -42,7 +42,7 @@ class HttpChecksumRequiredGenerator( .body() .bytes() .expect("checksum can only be computed for non-streaming operations"); - let checksum = #{md5}::compute(data); + let checksum = <#{md5}::Md5 as #{md5}::Digest>::digest(data); req.headers_mut().insert( #{http}::header::HeaderName::from_static("content-md5"), #{base64_encode}(&checksum[..]).parse().expect("checksum is valid header value") From 65fca8839f9cb5220b0630232f1cf28f598b7d8e Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Tue, 24 May 2022 09:53:52 -0700 Subject: [PATCH 2/2] Fix crate name issue --- .../smithy/rust/codegen/rustlang/CargoDependency.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt index 03893ddf94..43b7e1baee 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt @@ -115,8 +115,7 @@ class InlineDependency( } } -fun CargoDependency.asType(): RuntimeType = - RuntimeType(null, dependency = this, namespace = this.name.replace("-", "_")) +fun CargoDependency.asType(): RuntimeType = RuntimeType(null, dependency = this, namespace = rustName) data class Feature(val name: String, val default: Boolean, val deps: List) @@ -129,7 +128,7 @@ data class CargoDependency( val scope: DependencyScope = DependencyScope.Compile, val optional: Boolean = false, val features: Set = emptySet(), - val crateName: String = name.replace("-", "_") + val rustName: String = name.replace("-", "_") ) : RustDependency(name) { val key: Triple get() = Triple(name, location, scope) @@ -144,7 +143,7 @@ data class CargoDependency( is Local -> "local" } - fun rustName(name: String): RuntimeType = RuntimeType(name, this, this.crateName) + fun rustName(name: String): RuntimeType = RuntimeType(name, this, this.rustName) fun toMap(): Map { val attribs = mutableMapOf() @@ -200,7 +199,7 @@ data class CargoDependency( val Hyper: CargoDependency = CargoDependency("hyper", CratesIo("0.14")) val HyperWithStream: CargoDependency = Hyper.withFeature("stream") val LazyStatic: CargoDependency = CargoDependency("lazy_static", CratesIo("1.4")) - val Md5: CargoDependency = CargoDependency("md-5", CratesIo("0.10"), crateName = "md5") + val Md5: CargoDependency = CargoDependency("md-5", CratesIo("0.10"), rustName = "md5") val PercentEncoding: CargoDependency = CargoDependency("percent-encoding", CratesIo("2")) val PrettyAssertions: CargoDependency = CargoDependency("pretty_assertions", CratesIo("1"), scope = DependencyScope.Dev) val Regex: CargoDependency = CargoDependency("regex", CratesIo("1"))