MCPcopy Index your code
hub / github.com/RustPython/RustPython / _compare_digest

Function _compare_digest

crates/vm/src/stdlib/_operator.rs:319–341  ·  view source on GitHub ↗
(
        a: Either<PyStrRef, ArgBytesLike>,
        b: Either<PyStrRef, ArgBytesLike>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

317
318 #[pyfunction]
319 fn _compare_digest(
320 a: Either<PyStrRef, ArgBytesLike>,
321 b: Either<PyStrRef, ArgBytesLike>,
322 vm: &VirtualMachine,
323 ) -> PyResult<bool> {
324 let res = match (a, b) {
325 (Either::A(a), Either::A(b)) => {
326 if !a.isascii() || !b.isascii() {
327 return Err(vm.new_type_error(
328 "comparing strings with non-ASCII characters is not supported",
329 ));
330 }
331 constant_time_eq(a.as_bytes(), b.as_bytes())
332 }
333 (Either::B(a), Either::B(b)) => a.with_ref(|a| b.with_ref(|b| constant_time_eq(a, b))),
334 _ => {
335 return Err(
336 vm.new_type_error("unsupported operand types(s) or combination of types")
337 );
338 }
339 };
340 Ok(res)
341 }
342
343 /// attrgetter(attr, /, *attrs)
344 /// --

Callers

nothing calls this directly

Calls 4

with_refMethod · 0.80
ErrClass · 0.50
isasciiMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected