Skip to content

Commit abb462e

Browse files
linkmauveJohnTitor
authored andcommitted
Replace sha1 dependency with sha-1 (#1258)
* 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](RustCrypto/hashes#97)). * Update CHANGES.md with the sha-1 migration * Add a test for hash_key()
1 parent e66312b commit abb462e

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

CHANGES.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changes
22

3+
## [2.0.NEXT] - 2020-01-xx
4+
5+
### Changed
6+
7+
* Use `sha-1` crate instead of unmaintained `sha1` crate
8+
39
## [2.0.0] - 2019-12-25
410

511
### Changed

actix-http/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ rand = "0.7"
7474
regex = "1.3"
7575
serde = "1.0"
7676
serde_json = "1.0"
77-
sha1 = "0.6"
77+
sha-1 = "0.8"
7878
slab = "0.4"
7979
serde_urlencoded = "0.6.1"
8080
time = "0.1.42"

actix-http/src/ws/proto.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,13 @@ static WS_GUID: &str = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
207207

208208
// TODO: hash is always same size, we dont need String
209209
pub fn hash_key(key: &[u8]) -> String {
210+
use sha1::Digest;
210211
let mut hasher = sha1::Sha1::new();
211212

212-
hasher.update(key);
213-
hasher.update(WS_GUID.as_bytes());
213+
hasher.input(key);
214+
hasher.input(WS_GUID.as_bytes());
214215

215-
base64::encode(&hasher.digest().bytes())
216+
base64::encode(hasher.result().as_ref())
216217
}
217218

218219
#[cfg(test)]
@@ -277,6 +278,12 @@ mod test {
277278
assert_eq!(format!("{}", OpCode::Bad), "BAD");
278279
}
279280

281+
#[test]
282+
fn test_hash_key() {
283+
let hash = hash_key(b"hello actix-web");
284+
assert_eq!(&hash, "cR1dlyUUJKp0s/Bel25u5TgvC3E=");
285+
}
286+
280287
#[test]
281288
fn closecode_from_u16() {
282289
assert_eq!(CloseCode::from(1000u16), CloseCode::Normal);

0 commit comments

Comments
 (0)