FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Include SHAKE algorithm names in HASHXOF repr by moreal · Pull Request #7132 · RustPython/RustPython · GitHub

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

Filter by extension

Filter by extension .py  (1) .rs  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 0 additions & 1 deletion Lib/test/test_hashlib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL