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