Skip to content

Commit 50bce3f

Browse files
authored
Fix warnings from pyo3 0.23 (#911)
1 parent 8ea3ef8 commit 50bce3f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/_bcrypt/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use base64::Engine;
1616
use pyo3::types::PyBytesMethods;
1717
use pyo3::PyTypeInfo;
1818
use std::convert::TryInto;
19+
use std::ffi::CString;
1920
use std::io::Write;
2021
use subtle::ConstantTimeEq;
2122

@@ -49,7 +50,7 @@ fn gensalt<'p>(
4950

5051
let encoded_salt = BASE64_ENGINE.encode(salt);
5152

52-
pyo3::types::PyBytes::new_bound_with(
53+
pyo3::types::PyBytes::new_with(
5354
py,
5455
1 + prefix.len() + 1 + 2 + 1 + encoded_salt.len(),
5556
|mut b| {
@@ -114,7 +115,7 @@ fn hashpw<'p>(
114115
let hashed = py
115116
.allow_threads(|| bcrypt::hash_with_salt(password, cost, raw_salt))
116117
.map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid salt"))?;
117-
Ok(pyo3::types::PyBytes::new_bound(
118+
Ok(pyo3::types::PyBytes::new(
118119
py,
119120
hashed.format_for_version(version).as_bytes(),
120121
))
@@ -160,15 +161,15 @@ fn kdf<'p>(
160161
// They probably think bcrypt.kdf()'s rounds parameter is logarithmic,
161162
// expecting this value to be slow enough (it probably would be if this
162163
// were bcrypt). Emit a warning.
163-
pyo3::PyErr::warn_bound(
164+
pyo3::PyErr::warn(
164165
py,
165-
&pyo3::exceptions::PyUserWarning::type_object_bound(py),
166-
&format!("Warning: bcrypt.kdf() called with only {rounds} round(s). This few is not secure: the parameter is linear, like PBKDF2."),
166+
&pyo3::exceptions::PyUserWarning::type_object(py),
167+
&CString::new(format!("Warning: bcrypt.kdf() called with only {rounds} round(s). This few is not secure: the parameter is linear, like PBKDF2.")).unwrap(),
167168
3
168169
)?;
169170
}
170171

171-
pyo3::types::PyBytes::new_bound_with(py, desired_key_bytes, |output| {
172+
pyo3::types::PyBytes::new_with(py, desired_key_bytes, |output| {
172173
py.allow_threads(|| {
173174
bcrypt_pbkdf::bcrypt_pbkdf(password, salt, rounds, output).unwrap();
174175
});

0 commit comments

Comments
 (0)