forked from Rust-related/RustPython
Fix _sha512 support
This commit is contained in:
committed by
Jeong, YunWon
parent
940b879950
commit
8c7b811135
2
Lib/test/test_hashlib.py
vendored
2
Lib/test/test_hashlib.py
vendored
@@ -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():
|
||||
|
||||
@@ -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<Item = (Cow<'static, str>, 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,
|
||||
|
||||
@@ -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<PyModule> {
|
||||
let _ = vm.import("_hashlib", 0);
|
||||
_sha256::make_module(vm)
|
||||
}
|
||||
|
||||
#[pymodule]
|
||||
mod _sha256 {
|
||||
|
||||
@@ -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<PyModule> {
|
||||
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<PyObjectRef> {
|
||||
Ok(PyHasher::new("sha384", HashWrapper::new::<Sha384>(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<PyObjectRef> {
|
||||
Ok(PyHasher::new("sha512", HashWrapper::new::<Sha512>(args.string)).into_pyobject(vm))
|
||||
#[pyfunction]
|
||||
fn sha512(args: HashArgs, vm: &VirtualMachine) -> PyResult {
|
||||
Ok(local_sha512(args).into_pyobject(vm))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ pub trait StaticType {
|
||||
fn static_type() -> &'static Py<PyType> {
|
||||
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<PyType> {
|
||||
let cell = Self::static_cell();
|
||||
|
||||
Reference in New Issue
Block a user