11use bytes:: buf:: Chain ;
22use bytes:: Bytes ;
3- use digest:: { Digest , OutputSizeUser } ;
4- use generic_array:: GenericArray ;
3+ use digest:: Digest ;
54use sha1:: Sha1 ;
65use sha2:: Sha256 ;
76
@@ -74,10 +73,7 @@ impl AuthPlugin {
7473 }
7574}
7675
77- fn scramble_sha1 (
78- password : & str ,
79- nonce : & Chain < Bytes , Bytes > ,
80- ) -> GenericArray < u8 , <Sha1 as OutputSizeUser >:: OutputSize > {
76+ fn scramble_sha1 ( password : & str , nonce : & Chain < Bytes , Bytes > ) -> Vec < u8 > {
8177 // SHA1( password ) ^ SHA1( seed + SHA1( SHA1( password ) ) )
8278 // https://mariadb.com/kb/en/connection/#mysql_native_password-plugin
8379
@@ -99,13 +95,10 @@ fn scramble_sha1(
9995
10096 xor_eq ( & mut pw_hash, & pw_seed_hash_hash) ;
10197
102- pw_hash
98+ pw_hash. to_vec ( )
10399}
104100
105- fn scramble_sha256 (
106- password : & str ,
107- nonce : & Chain < Bytes , Bytes > ,
108- ) -> GenericArray < u8 , <Sha256 as OutputSizeUser >:: OutputSize > {
101+ fn scramble_sha256 ( password : & str , nonce : & Chain < Bytes , Bytes > ) -> Vec < u8 > {
109102 // XOR(SHA256(password), SHA256(SHA256(SHA256(password)), seed))
110103 // Order matches the server-side verification in MySQL's sha2_password
111104 // (generate_sha2_scramble): stage2 digest first, then the nonce.
@@ -127,7 +120,7 @@ fn scramble_sha256(
127120
128121 xor_eq ( & mut pw_hash, & pw_seed_hash_hash) ;
129122
130- pw_hash
123+ pw_hash. to_vec ( )
131124}
132125
133126async fn encrypt_rsa < ' s > (
@@ -185,15 +178,14 @@ fn to_asciz(s: &str) -> Vec<u8> {
185178
186179#[ cfg( feature = "rsa" ) ]
187180mod rsa_backend {
188- use rand:: thread_rng;
189181 use rsa:: { pkcs8:: DecodePublicKey , Oaep , RsaPublicKey } ;
190182
191183 use super :: Error ;
192184
193185 pub ( super ) fn encrypt ( rsa_pub_key : & [ u8 ] , pass : & [ u8 ] ) -> Result < Vec < u8 > , Error > {
194186 let pkey = parse_rsa_pub_key ( rsa_pub_key) ?;
195- let padding = Oaep :: new :: < sha1:: Sha1 > ( ) ;
196- pkey. encrypt ( & mut thread_rng ( ) , padding, pass)
187+ let padding = Oaep :: < sha1:: Sha1 > :: new ( ) ;
188+ pkey. encrypt ( & mut rand :: rng ( ) , padding, pass)
197189 . map_err ( Error :: protocol)
198190 }
199191
0 commit comments