Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Lib/test/test_hashlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ def test_blocksize_and_name(self):
self.check_blocksize_name('sha384', 128, 48)
self.check_blocksize_name('sha512', 128, 64)

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 'shake' not found in '<_hashlib.hashxof object at 0xc68a2c800>'
@requires_sha3
def test_blocksize_name_sha3(self):
self.check_blocksize_name('sha3_224', 144, 28)
Expand Down
16 changes: 12 additions & 4 deletions crates/stdlib/src/hashlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ pub mod _hashlib {
}
}

#[pyclass(flags(IMMUTABLETYPE))]
#[pyclass(with(Representable), flags(IMMUTABLETYPE))]
impl PyHasherXof {
fn new(name: &str, d: HashXofWrapper) -> Self {
Self {
Expand Down Expand Up @@ -447,6 +447,15 @@ pub mod _hashlib {
}
}

impl Representable for PyHasherXof {
fn repr_str(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<String> {
Ok(format!(
"<{} _hashlib.HASHXOF object @ {:#x}>",
zelf.name, zelf as *const _ as usize
))
}
}

#[pyfunction(name = "new")]
fn hashlib_new(args: NewHashArgs, vm: &VirtualMachine) -> PyResult<PyObjectRef> {
let data = resolve_data(args.data, args.string, vm)?;
Expand Down Expand Up @@ -701,9 +710,8 @@ pub mod _hashlib {
if len < 1 {
return Err(vm.new_value_error("key length must be greater than 0.".to_owned()));
}
usize::try_from(len).map_err(|_| {
vm.new_overflow_error("key length is too great.".to_owned())
})?
usize::try_from(len)
.map_err(|_| vm.new_overflow_error("key length is too great.".to_owned()))?
}
None => hash_digest_size(&name).ok_or_else(|| unsupported_hash(&name, vm))?,
};
Expand Down
Loading