◐ Shell
clean mode source ↗

Fix _hashlib.compare_digest to reject non-ASCII strings by ever0de · Pull Request #7280 · RustPython/RustPython

coderabbitai[bot]

Bot reviewed Feb 28, 2026

ShaharNaveh

ShaharNaveh

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>.

youknowone

youknowone pushed a commit to youknowone/RustPython that referenced this pull request

Mar 22, 2026
)

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>.