From 44e65fcaf97d0aa41b186b887e3f8ed973bedbe4 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 10 Jan 2020 16:13:28 +0100 Subject: [PATCH 1/3] Add a test for hash_key() --- actix-http/src/ws/proto.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/actix-http/src/ws/proto.rs b/actix-http/src/ws/proto.rs index ad42b7a6ba1..630c5c6141c 100644 --- a/actix-http/src/ws/proto.rs +++ b/actix-http/src/ws/proto.rs @@ -277,6 +277,12 @@ mod test { assert_eq!(format!("{}", OpCode::Bad), "BAD"); } + #[test] + fn test_hash_key() { + let hash = hash_key(b"hello actix-web"); + assert_eq!(&hash, "cR1dlyUUJKp0s/Bel25u5TgvC3E="); + } + #[test] fn closecode_from_u16() { assert_eq!(CloseCode::from(1000u16), CloseCode::Normal); From a7c13e28c73be249c83582e694e15da343514ccb Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 6 Jan 2020 12:09:31 +0100 Subject: [PATCH 2/3] Replace sha1 dependency with sha-1 This other crate is being maintained, and it offers better performances when using the `asm` feature (especially [on AArch64](https://github.com/RustCrypto/hashes/pull/97)). --- actix-http/Cargo.toml | 2 +- actix-http/src/ws/proto.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 367dbafeca9..93aaa756e3d 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -74,7 +74,7 @@ rand = "0.7" regex = "1.3" serde = "1.0" serde_json = "1.0" -sha1 = "0.6" +sha-1 = "0.8" slab = "0.4" serde_urlencoded = "0.6.1" time = "0.1.42" diff --git a/actix-http/src/ws/proto.rs b/actix-http/src/ws/proto.rs index 630c5c6141c..60af6f08bb7 100644 --- a/actix-http/src/ws/proto.rs +++ b/actix-http/src/ws/proto.rs @@ -207,12 +207,13 @@ static WS_GUID: &str = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; // TODO: hash is always same size, we dont need String pub fn hash_key(key: &[u8]) -> String { + use sha1::Digest; let mut hasher = sha1::Sha1::new(); - hasher.update(key); - hasher.update(WS_GUID.as_bytes()); + hasher.input(key); + hasher.input(WS_GUID.as_bytes()); - base64::encode(&hasher.digest().bytes()) + base64::encode(hasher.result().as_ref()) } #[cfg(test)] From 84be66a2de159b40a900a0f3155c6af5e78ecf0b Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 6 Jan 2020 12:32:45 +0100 Subject: [PATCH 3/3] Update CHANGES.md with the sha-1 migration --- CHANGES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2f96dce5d5b..29f78e0b1a0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Changes +## [2.0.NEXT] - 2020-01-xx + +### Changed + +* Use `sha-1` crate instead of unmaintained `sha1` crate + ## [2.0.0] - 2019-12-25 ### Changed