diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2022-06-25 12:19:05 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-25 19:19:05 +0300 |
commit | 29e95a958b0b8c767f9c1fca9d8fbd5777cd90c4 (patch) | |
tree | 41c823c71a45e40199009c555fe019cf310d95b6 | |
parent | bcd1f6411011f2a9d1de3127734d1f38ce451405 (diff) | |
download | py-bcrypt-git-29e95a958b0b8c767f9c1fca9d8fbd5777cd90c4.tar.gz |
Release the GIL during expensive crypto ops (#355)
-rw-r--r-- | src/_bcrypt/src/lib.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/_bcrypt/src/lib.rs b/src/_bcrypt/src/lib.rs index ac1897f..8e61c3d 100644 --- a/src/_bcrypt/src/lib.rs +++ b/src/_bcrypt/src/lib.rs @@ -49,7 +49,7 @@ fn hashpass<'p>( .try_into() .map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid salt"))?; - let hashed = bcrypt::hash_with_salt(password, cost, raw_salt).unwrap(); + let hashed = py.allow_threads(|| bcrypt::hash_with_salt(password, cost, raw_salt).unwrap()); Ok(pyo3::types::PyBytes::new( py, hashed.format_for_version(version).as_bytes(), @@ -65,7 +65,9 @@ fn pbkdf<'p>( desired_key_bytes: usize, ) -> pyo3::PyResult<&'p pyo3::types::PyBytes> { pyo3::types::PyBytes::new_with(py, desired_key_bytes, |output| { - bcrypt_pbkdf::bcrypt_pbkdf(password, salt, rounds, output).unwrap(); + py.allow_threads(|| { + bcrypt_pbkdf::bcrypt_pbkdf(password, salt, rounds, output).unwrap(); + }); Ok(()) }) } |