@@ -42,7 +42,11 @@ impl Credentials {
4242 }
4343 }
4444
45- pub fn with_blob ( username : String , encrypted_blob : & str , device_id : & str ) -> Credentials {
45+ pub fn with_blob (
46+ username : impl Into < String > ,
47+ encrypted_blob : impl AsRef < [ u8 ] > ,
48+ device_id : impl AsRef < [ u8 ] > ,
49+ ) -> Credentials {
4650 fn read_u8 < R : Read > ( stream : & mut R ) -> io:: Result < u8 > {
4751 let mut data = [ 0u8 ] ;
4852 stream. read_exact ( & mut data) ?;
@@ -67,7 +71,9 @@ impl Credentials {
6771 Ok ( data)
6872 }
6973
70- let secret = Sha1 :: digest ( device_id. as_bytes ( ) ) ;
74+ let username = username. into ( ) ;
75+
76+ let secret = Sha1 :: digest ( device_id. as_ref ( ) ) ;
7177
7278 let key = {
7379 let mut key = [ 0u8 ; 24 ] ;
@@ -88,9 +94,9 @@ impl Credentials {
8894 let mut data = base64:: decode ( encrypted_blob) . unwrap ( ) ;
8995 let cipher = Aes192 :: new ( GenericArray :: from_slice ( & key) ) ;
9096 let block_size = <Aes192 as BlockCipher >:: BlockSize :: to_usize ( ) ;
97+
9198 assert_eq ! ( data. len( ) % block_size, 0 ) ;
92- // replace to chunks_exact_mut with MSRV bump to 1.31
93- for chunk in data. chunks_mut ( block_size) {
99+ for chunk in data. chunks_exact_mut ( block_size) {
94100 cipher. decrypt_block ( GenericArray :: from_mut_slice ( chunk) ) ;
95101 }
96102
@@ -102,7 +108,7 @@ impl Credentials {
102108 data
103109 } ;
104110
105- let mut cursor = io:: Cursor :: new ( & blob) ;
111+ let mut cursor = io:: Cursor :: new ( blob. as_slice ( ) ) ;
106112 read_u8 ( & mut cursor) . unwrap ( ) ;
107113 read_bytes ( & mut cursor) . unwrap ( ) ;
108114 read_u8 ( & mut cursor) . unwrap ( ) ;
0 commit comments