Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ecdb7d3

Browse filesBrowse files
authored
Merge pull request #5706 from coolreader18/constant_time_eq
Use the `constant_time_eq` crate instead of our bespoke implementation
2 parents c53908f + 10fd02e commit ecdb7d3
Copy full SHA for ecdb7d3

File tree

7 files changed

+12
-62
lines changed
Filter options

7 files changed

+12
-62
lines changed

‎Cargo.lock

Copy file name to clipboardExpand all lines: Cargo.lock
+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

Copy file name to clipboardExpand all lines: Cargo.toml
+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ bitflags = "2.4.2"
155155
bstr = "1"
156156
cfg-if = "1.0"
157157
chrono = "0.4.39"
158+
constant_time_eq = "0.4"
158159
criterion = { version = "0.5", features = ["html_reports"] }
159160
crossbeam-utils = "0.8.21"
160161
flame = "0.2.2"

‎common/Cargo.toml

Copy file name to clipboardExpand all lines: common/Cargo.toml
-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ unicode_names2 = { workspace = true }
3434
lock_api = "0.4"
3535
radium = "1.1"
3636
siphasher = "1"
37-
volatile = "0.3"
3837

3938
[target.'cfg(windows)'.dependencies]
4039
widestring = { workspace = true }

‎common/src/cmp.rs

Copy file name to clipboardExpand all lines: common/src/cmp.rs
-48
This file was deleted.

‎common/src/lib.rs

Copy file name to clipboardExpand all lines: common/src/lib.rs
-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub mod atomic;
1010
pub mod borrow;
1111
pub mod boxvec;
1212
pub mod cformat;
13-
pub mod cmp;
1413
#[cfg(any(unix, windows, target_os = "wasi"))]
1514
pub mod crt_fd;
1615
pub mod encodings;

‎vm/Cargo.toml

Copy file name to clipboardExpand all lines: vm/Cargo.toml
+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ bstr = { workspace = true }
5151
cfg-if = { workspace = true }
5252
crossbeam-utils = { workspace = true }
5353
chrono = { workspace = true, features = ["wasmbind"] }
54+
constant_time_eq = { workspace = true }
5455
flame = { workspace = true, optional = true }
5556
getrandom = { workspace = true }
5657
hex = { workspace = true }

‎vm/src/stdlib/operator.rs

Copy file name to clipboardExpand all lines: vm/src/stdlib/operator.rs
+3-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ pub(crate) use _operator::make_module;
22

33
#[pymodule]
44
mod _operator {
5-
use crate::common::cmp;
65
use crate::{
76
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
87
builtins::{PyInt, PyIntRef, PyStr, PyStrRef, PyTupleRef, PyTypeRef},
@@ -13,6 +12,7 @@ mod _operator {
1312
recursion::ReprGuard,
1413
types::{Callable, Constructor, PyComparisonOp, Representable},
1514
};
15+
use constant_time_eq::constant_time_eq;
1616

1717
#[pyfunction]
1818
fn lt(a: PyObjectRef, b: PyObjectRef, vm: &VirtualMachine) -> PyResult {
@@ -328,11 +328,9 @@ mod _operator {
328328
"comparing strings with non-ASCII characters is not supported".to_owned(),
329329
));
330330
}
331-
cmp::timing_safe_cmp(a.as_bytes(), b.as_bytes())
332-
}
333-
(Either::B(a), Either::B(b)) => {
334-
a.with_ref(|a| b.with_ref(|b| cmp::timing_safe_cmp(a, b)))
331+
constant_time_eq(a.as_bytes(), b.as_bytes())
335332
}
333+
(Either::B(a), Either::B(b)) => a.with_ref(|a| b.with_ref(|b| constant_time_eq(a, b))),
336334
_ => {
337335
return Err(vm.new_type_error(
338336
"unsupported operand types(s) or combination of types".to_owned(),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.