Fix _hashlib.compare_digest to reject non-ASCII strings (#7280) · RustPython/RustPython@be29462 · GitHub
Skip to content

Commit be29462

Browse files
authored
Fix _hashlib.compare_digest to reject non-ASCII strings (#7280)
Add non-ASCII string check to _hashlib.compare_digest, matching the behavior of _operator._compare_digest. When both arguments are strings, non-ASCII characters now correctly raise TypeError. Also replace the non-constant-time == comparison with constant_time_eq for proper timing-attack resistance, and return PyResult<bool> instead of PyResult<PyObjectRef>.
1 parent 7b7c7a1 commit be29462

4 files changed

Lines changed: 19 additions & 22 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_hmac.py

Lines changed: 0 additions & 8 deletions

crates/stdlib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ sha3 = "0.10.1"
6969
blake2 = "0.10.4"
7070
hmac = "0.12"
7171
pbkdf2 = { version = "0.12", features = ["hmac"] }
72+
constant_time_eq = { workspace = true }
7273

7374
## unicode stuff
7475
unicode_names2 = { workspace = true }

crates/stdlib/src/hashlib.rs

Lines changed: 17 additions & 14 deletions

0 commit comments

Comments
 (0)