@@ -21,6 +21,7 @@ use std::time::Duration;
21
21
#[ macro_use]
22
22
extern crate quickcheck;
23
23
24
+ use scoring:: Score ;
24
25
use time_estimates:: CrackTimes ;
25
26
#[ cfg( target_arch = "wasm32" ) ]
26
27
use wasm_bindgen:: prelude:: wasm_bindgen;
@@ -77,7 +78,7 @@ pub struct Entropy {
77
78
crack_times : time_estimates:: CrackTimes ,
78
79
/// Overall strength score from 0-4.
79
80
/// Any score less than 3 should be considered too weak.
80
- score : u8 ,
81
+ score : Score ,
81
82
/// Verbal feedback to help choose better passwords. Set when `score` <= 2.
82
83
feedback : Option < feedback:: Feedback > ,
83
84
/// The list of patterns the guess calculation was based on
@@ -104,7 +105,7 @@ impl Entropy {
104
105
105
106
/// Overall strength score from 0-4.
106
107
/// Any score less than 3 should be considered too weak.
107
- pub fn score ( & self ) -> u8 {
108
+ pub fn score ( & self ) -> Score {
108
109
self . score
109
110
}
110
111
@@ -133,8 +134,8 @@ pub fn zxcvbn(password: &str, user_inputs: &[&str]) -> Entropy {
133
134
guesses : 0 ,
134
135
guesses_log10 : f64:: NEG_INFINITY ,
135
136
crack_times : CrackTimes :: new ( 0 ) ,
136
- score : 0 ,
137
- feedback : feedback:: get_feedback ( 0 , & [ ] ) ,
137
+ score : Score :: Zero ,
138
+ feedback : feedback:: get_feedback ( Score :: Zero , & [ ] ) ,
138
139
sequence : Vec :: default ( ) ,
139
140
calc_time : Duration :: from_secs ( 0 ) ,
140
141
} ;
@@ -198,7 +199,7 @@ mod tests {
198
199
let password = "r0sebudmaelstrom11/20/91aaaa" ;
199
200
let entropy = zxcvbn ( password, & [ ] ) ;
200
201
assert_eq ! ( entropy. guesses_log10 as u16 , 14 ) ;
201
- assert_eq ! ( entropy. score, 4 ) ;
202
+ assert_eq ! ( entropy. score, Score :: Four ) ;
202
203
assert ! ( !entropy. sequence. is_empty( ) ) ;
203
204
assert ! ( entropy. feedback. is_none( ) ) ;
204
205
assert ! ( entropy. calc_time. as_nanos( ) > 0 ) ;
@@ -209,7 +210,7 @@ mod tests {
209
210
fn test_zxcvbn_empty ( ) {
210
211
let password = "" ;
211
212
let entropy = zxcvbn ( password, & [ ] ) ;
212
- assert_eq ! ( entropy. score, 0 ) ;
213
+ assert_eq ! ( entropy. score, Score :: Zero ) ;
213
214
assert_eq ! ( entropy. guesses, 0 ) ;
214
215
assert_eq ! ( entropy. guesses_log10, f64 :: NEG_INFINITY ) ;
215
216
assert_eq ! ( entropy. crack_times, CrackTimes :: new( 0 ) ) ;
@@ -221,23 +222,23 @@ mod tests {
221
222
fn test_zxcvbn_unicode ( ) {
222
223
let password = "𐰊𐰂𐰄𐰀𐰁" ;
223
224
let entropy = zxcvbn ( password, & [ ] ) ;
224
- assert_eq ! ( entropy. score, 1 ) ;
225
+ assert_eq ! ( entropy. score, Score :: One ) ;
225
226
}
226
227
227
228
#[ cfg_attr( not( target_arch = "wasm32" ) , test) ]
228
229
#[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test) ]
229
230
fn test_zxcvbn_unicode_2 ( ) {
230
231
let password = "r0sebudmaelstrom丂/20/91aaaa" ;
231
232
let entropy = zxcvbn ( password, & [ ] ) ;
232
- assert_eq ! ( entropy. score, 4 ) ;
233
+ assert_eq ! ( entropy. score, Score :: Four ) ;
233
234
}
234
235
235
236
#[ cfg_attr( not( target_arch = "wasm32" ) , test) ]
236
237
#[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test) ]
237
238
fn test_issue_13 ( ) {
238
239
let password = "Imaginative-Say-Shoulder-Dish-0" ;
239
240
let entropy = zxcvbn ( password, & [ ] ) ;
240
- assert_eq ! ( entropy. score, 4 ) ;
241
+ assert_eq ! ( entropy. score, Score :: Four ) ;
241
242
}
242
243
243
244
#[ cfg_attr( not( target_arch = "wasm32" ) , test) ]
@@ -247,7 +248,7 @@ mod tests {
247
248
let entropy = zxcvbn ( password, & [ ] ) ;
248
249
assert_eq ! ( entropy. guesses, 372_010_000 ) ;
249
250
assert ! ( ( entropy. guesses_log10 - 8.57055461430783 ) . abs( ) < f64 :: EPSILON ) ;
250
- assert_eq ! ( entropy. score, 3 ) ;
251
+ assert_eq ! ( entropy. score, Score :: Three ) ;
251
252
}
252
253
253
254
#[ cfg_attr( not( target_arch = "wasm32" ) , test) ]
@@ -257,7 +258,7 @@ mod tests {
257
258
let entropy = zxcvbn ( password, & [ ] ) ;
258
259
assert_eq ! ( entropy. guesses, 1_010_000 ) ;
259
260
assert ! ( ( entropy. guesses_log10 - 6.004321373782642 ) . abs( ) < f64 :: EPSILON ) ;
260
- assert_eq ! ( entropy. score, 2 ) ;
261
+ assert_eq ! ( entropy. score, Score :: Two ) ;
261
262
}
262
263
263
264
#[ cfg_attr( not( target_arch = "wasm32" ) , test) ]
@@ -266,7 +267,7 @@ mod tests {
266
267
let password = "!QASW@#EDFR$%TGHY^&UJKI*(OL" ;
267
268
let entropy = zxcvbn ( password, & [ ] ) ;
268
269
assert_eq ! ( entropy. guesses, u64 :: max_value( ) ) ;
269
- assert_eq ! ( entropy. score, 4 ) ;
270
+ assert_eq ! ( entropy. score, Score :: Four ) ;
270
271
}
271
272
272
273
#[ cfg_attr( not( target_arch = "wasm32" ) , test) ]
@@ -275,6 +276,6 @@ mod tests {
275
276
let password = "08märz2010" ;
276
277
let entropy = zxcvbn ( password, & [ ] ) ;
277
278
assert_eq ! ( entropy. guesses, 100010000 ) ;
278
- assert_eq ! ( entropy. score, 3 ) ;
279
+ assert_eq ! ( entropy. score, Score :: Three ) ;
279
280
}
280
281
}
0 commit comments