@@ -525,7 +525,6 @@ doc_comment::doctest!("../README.md", readme);
525525#[ allow( dead_code) ]
526526mod tests {
527527 use super :: { credential:: CredentialApi , Entry , Error , Result } ;
528- use rand:: Rng ;
529528 use std:: collections:: HashMap ;
530529
531530 /// Create a platform-specific credential given the constructor, service, and user
@@ -612,22 +611,21 @@ mod tests {
612611 /// the conflicts, and then do any needed cleanup once everything
613612 /// is working correctly. So we export this function for tests to use.
614613 pub fn generate_random_string_of_len ( len : usize ) -> String {
615- // from the Rust Cookbook:
616- // https://rust-lang-nursery.github.io/rust-cookbook/algorithms/randomness.html
617- #[ allow( unused_imports) ]
618- use rand:: Rng ;
619- use rand:: { distributions:: Alphanumeric , thread_rng} ;
620- thread_rng ( )
621- . sample_iter ( & Alphanumeric )
622- . take ( len)
623- . map ( char:: from)
624- . collect ( )
614+ use fastrand;
615+ use std:: iter:: repeat_with;
616+ repeat_with ( fastrand:: alphanumeric) . take ( len) . collect ( )
625617 }
626618
627619 pub fn generate_random_string ( ) -> String {
628620 generate_random_string_of_len ( 30 )
629621 }
630622
623+ fn generate_random_bytes_of_len ( len : usize ) -> Vec < u8 > {
624+ use fastrand;
625+ use std:: iter:: repeat_with;
626+ repeat_with ( || fastrand:: u8 ( ..) ) . take ( len) . collect ( )
627+ }
628+
631629 pub fn test_empty_service_and_user < F > ( f : F )
632630 where
633631 F : Fn ( & str , & str ) -> Entry ,
@@ -684,9 +682,8 @@ mod tests {
684682 {
685683 let name = generate_random_string ( ) ;
686684 let entry = f ( & name, & name) ;
687- let mut secret: [ u8 ; 16 ] = [ 0 ; 16 ] ;
688- rand:: rngs:: OsRng . fill ( & mut secret) ;
689- test_round_trip_secret ( "non-ascii password" , & entry, & secret) ;
685+ let secret = generate_random_bytes_of_len ( 24 ) ;
686+ test_round_trip_secret ( "non-ascii password" , & entry, secret. as_slice ( ) ) ;
690687 }
691688
692689 pub fn test_update < F > ( f : F )
0 commit comments