diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py index c03208427..da62486e0 100644 --- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -1118,8 +1118,6 @@ class KDFTests(unittest.TestCase): iterations=1, dklen=None) self.assertEqual(out, self.pbkdf2_results['sha1'][0][0]) - # TODO: RUSTPYTHON - @unittest.expectedFailure @unittest.skipIf(builtin_hashlib is None, "test requires builtin_hashlib") def test_pbkdf2_hmac_py(self): with warnings_helper.check_warnings(): diff --git a/stdlib/src/lib.rs b/stdlib/src/lib.rs index 2a1a7d5ce..97aaa8b89 100644 --- a/stdlib/src/lib.rs +++ b/stdlib/src/lib.rs @@ -20,6 +20,7 @@ mod md5; mod sha1; mod sha256; mod sha3; +mod sha512; mod json; #[cfg(not(any(target_os = "ios", target_os = "android", target_arch = "wasm32")))] @@ -111,7 +112,7 @@ pub fn get_module_inits() -> impl Iterator, StdlibInit "_sha1" => sha1::make_module, "_sha3" => sha3::make_module, "_sha256" => sha256::make_module, - // "_sha512" => sha512::make_module, // TODO: RUSPYTHON fix strange fail on vm: 'static type has not been initialized' + "_sha512" => sha512::make_module, "_md5" => md5::make_module, "_blake2" => blake2::make_module, "_json" => json::make_module, diff --git a/stdlib/src/sha256.rs b/stdlib/src/sha256.rs index bae22fa4c..cae017266 100644 --- a/stdlib/src/sha256.rs +++ b/stdlib/src/sha256.rs @@ -1,4 +1,9 @@ -pub(crate) use _sha256::make_module; +use crate::vm::{builtins::PyModule, PyRef, VirtualMachine}; + +pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { + let _ = vm.import("_hashlib", 0); + _sha256::make_module(vm) +} #[pymodule] mod _sha256 { diff --git a/stdlib/src/sha512.rs b/stdlib/src/sha512.rs index bb93fc9db..8c510fb73 100644 --- a/stdlib/src/sha512.rs +++ b/stdlib/src/sha512.rs @@ -1,20 +1,22 @@ -// spell-checker:ignore usedforsecurity HASHXOF +use crate::vm::{builtins::PyModule, PyRef, VirtualMachine}; -pub(crate) use _sha512::make_module; +pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { + let _ = vm.import("_hashlib", 0); + _sha512::make_module(vm) +} #[pymodule] mod _sha512 { - use crate::hashlib::_hashlib::{HashArgs, HashWrapper, PyHasher}; - use crate::vm::{PyObjectRef, PyPayload, PyResult, VirtualMachine}; - use sha2::{Sha384, Sha512}; + use crate::hashlib::_hashlib::{local_sha384, local_sha512, HashArgs}; + use crate::vm::{PyPayload, PyResult, VirtualMachine}; - #[pyfunction(name = "sha384")] - fn sha384(args: HashArgs, vm: &VirtualMachine) -> PyResult { - Ok(PyHasher::new("sha384", HashWrapper::new::(args.string)).into_pyobject(vm)) + #[pyfunction] + fn sha384(args: HashArgs, vm: &VirtualMachine) -> PyResult { + Ok(local_sha384(args).into_pyobject(vm)) } - #[pyfunction(name = "sha512")] - fn sha512(args: HashArgs, vm: &VirtualMachine) -> PyResult { - Ok(PyHasher::new("sha512", HashWrapper::new::(args.string)).into_pyobject(vm)) + #[pyfunction] + fn sha512(args: HashArgs, vm: &VirtualMachine) -> PyResult { + Ok(local_sha512(args).into_pyobject(vm)) } } diff --git a/vm/src/class.rs b/vm/src/class.rs index 6ce73d32c..d6893bf15 100644 --- a/vm/src/class.rs +++ b/vm/src/class.rs @@ -22,7 +22,7 @@ pub trait StaticType { fn static_type() -> &'static Py { Self::static_cell() .get() - .expect("static type has not been initialized") + .expect("static type has not been initialized. e.g. the native types defined in different module may be used before importing library.") } fn init_manually(typ: PyTypeRef) -> &'static Py { let cell = Self::static_cell();