Skip to content

Commit 7537e8a

Browse files
committed
postgres-protocol: use RustCrypto md-5 crate
Swap the md5 crate for the md-5 crate. Despite the latter's somewhat more suspicious name, it is part of the wider RustCrypto ecosystem, and shares code with the sha2 crate that postgres-protocol already uses.
1 parent e29439a commit 7537e8a

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

postgres-protocol/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ byteorder = "1.0"
1414
bytes = "1.0"
1515
fallible-iterator = "0.2"
1616
hmac = "0.10"
17-
md5 = "0.7"
17+
md-5 = "0.9"
1818
memchr = "2.0"
1919
rand = "0.8"
2020
sha2 = "0.9"

postgres-protocol/src/authentication/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Authentication protocol support.
2-
use md5::Context;
2+
use md5::{Digest, Md5};
33

44
pub mod sasl;
55

@@ -10,14 +10,13 @@ pub mod sasl;
1010
/// `PasswordMessage` message.
1111
#[inline]
1212
pub fn md5_hash(username: &[u8], password: &[u8], salt: [u8; 4]) -> String {
13-
let mut context = Context::new();
14-
context.consume(password);
15-
context.consume(username);
16-
let output = context.compute();
17-
context = Context::new();
18-
context.consume(format!("{:x}", output));
19-
context.consume(&salt);
20-
format!("md5{:x}", context.compute())
13+
let mut md5 = Md5::new();
14+
md5.update(password);
15+
md5.update(username);
16+
let output = md5.finalize_reset();
17+
md5.update(format!("{:x}", output));
18+
md5.update(&salt);
19+
format!("md5{:x}", md5.finalize())
2120
}
2221

2322
#[cfg(test)]

0 commit comments

Comments
 (0)