13
13
#![ deny( rust_2018_idioms) ]
14
14
15
15
use base64:: Engine ;
16
- use pyo3:: prelude:: PyBytesMethods ;
17
16
use pyo3:: PyTypeInfo ;
18
17
use std:: convert:: TryInto ;
19
18
use std:: io:: Write ;
@@ -29,7 +28,7 @@ fn gensalt<'p>(
29
28
py : pyo3:: Python < ' p > ,
30
29
rounds : Option < u16 > ,
31
30
prefix : Option < & [ u8 ] > ,
32
- ) -> pyo3:: PyResult < pyo3 :: Bound < ' p , pyo3:: types:: PyBytes > > {
31
+ ) -> pyo3:: PyResult < & ' p pyo3:: types:: PyBytes > {
33
32
let rounds = rounds. unwrap_or ( 12 ) ;
34
33
let prefix = prefix. unwrap_or ( b"2b" ) ;
35
34
@@ -48,7 +47,7 @@ fn gensalt<'p>(
48
47
49
48
let encoded_salt = BASE64_ENGINE . encode ( salt) ;
50
49
51
- pyo3:: types:: PyBytes :: new_bound_with (
50
+ pyo3:: types:: PyBytes :: new_with (
52
51
py,
53
52
1 + prefix. len ( ) + 1 + 2 + 1 + encoded_salt. len ( ) ,
54
53
|mut b| {
@@ -69,7 +68,7 @@ fn hashpw<'p>(
69
68
py : pyo3:: Python < ' p > ,
70
69
password : & [ u8 ] ,
71
70
salt : & [ u8 ] ,
72
- ) -> pyo3:: PyResult < pyo3 :: Bound < ' p , pyo3:: types:: PyBytes > > {
71
+ ) -> pyo3:: PyResult < & ' p pyo3:: types:: PyBytes > {
73
72
// bcrypt originally suffered from a wraparound bug:
74
73
// http://www.openwall.com/lists/oss-security/2012/01/02/4
75
74
// This bug was corrected in the OpenBSD source by truncating inputs to 72
@@ -113,7 +112,7 @@ fn hashpw<'p>(
113
112
let hashed = py
114
113
. allow_threads ( || bcrypt:: hash_with_salt ( password, cost, raw_salt) )
115
114
. map_err ( |_| pyo3:: exceptions:: PyValueError :: new_err ( "Invalid salt" ) ) ?;
116
- Ok ( pyo3:: types:: PyBytes :: new_bound (
115
+ Ok ( pyo3:: types:: PyBytes :: new (
117
116
py,
118
117
hashed. format_for_version ( version) . as_bytes ( ) ,
119
118
) )
@@ -135,7 +134,7 @@ fn kdf<'p>(
135
134
desired_key_bytes : usize ,
136
135
rounds : u32 ,
137
136
ignore_few_rounds : Option < bool > ,
138
- ) -> pyo3:: PyResult < pyo3 :: Bound < ' p , pyo3:: types:: PyBytes > > {
137
+ ) -> pyo3:: PyResult < & ' p pyo3:: types:: PyBytes > {
139
138
let ignore_few_rounds = ignore_few_rounds. unwrap_or ( false ) ;
140
139
141
140
if password. is_empty ( ) || salt. is_empty ( ) {
@@ -156,19 +155,7 @@ fn kdf<'p>(
156
155
) ) ;
157
156
}
158
157
159
- if rounds < 50 && !ignore_few_rounds {
160
- // They probably think bcrypt.kdf()'s rounds parameter is logarithmic,
161
- // expecting this value to be slow enough (it probably would be if this
162
- // were bcrypt). Emit a warning.
163
- pyo3:: PyErr :: warn_bound (
164
- 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." ) ,
167
- 3
168
- ) ?;
169
- }
170
-
171
- pyo3:: types:: PyBytes :: new_bound_with ( py, desired_key_bytes, |output| {
158
+ pyo3:: types:: PyBytes :: new_with ( py, desired_key_bytes, |output| {
172
159
py. allow_threads ( || {
173
160
bcrypt_pbkdf:: bcrypt_pbkdf ( password, salt, rounds, output) . unwrap ( ) ;
174
161
} ) ;
@@ -177,10 +164,7 @@ fn kdf<'p>(
177
164
}
178
165
179
166
#[ pyo3:: prelude:: pymodule]
180
- fn _bcrypt (
181
- _py : pyo3:: Python < ' _ > ,
182
- m : & pyo3:: Bound < ' _ , pyo3:: types:: PyModule > ,
183
- ) -> pyo3:: PyResult < ( ) > {
167
+ fn _bcrypt ( _py : pyo3:: Python < ' _ > , m : & pyo3:: types:: PyModule ) -> pyo3:: PyResult < ( ) > {
184
168
m. add_function ( pyo3:: wrap_pyfunction!( gensalt, m) ?) ?;
185
169
m. add_function ( pyo3:: wrap_pyfunction!( hashpw, m) ?) ?;
186
170
m. add_function ( pyo3:: wrap_pyfunction!( checkpw, m) ?) ?;
0 commit comments