Debian Codegraph @

src/connection/sasl.rs

raw symbols SCIP
1 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::connectionrust-analyzer cargo sqlx-postgres 0.8.3 connection/::streamrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/::PgStreamrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#;
2 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::errorrust-analyzer cargo sqlx-postgres 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#;
3 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::messagerust-analyzer cargo sqlx-postgres 0.8.3 message/::{Authenticationrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/Authentication#, AuthenticationSaslrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/AuthenticationSasl#, SaslInitialResponserust-analyzer cargo sqlx-postgres 0.8.3 message/sasl/SaslInitialResponse#, SaslResponserust-analyzer cargo sqlx-postgres 0.8.3 message/sasl/SaslResponse#};
4 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::PgConnectOptionsrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#;
5 use hmacrust-analyzer cargo hmac 0.12.1 crate/::{Hmacrust-analyzer cargo hmac 0.12.1 optim/Hmac#, Macrust-analyzer cargo digest 0.10.7 mac/Mac#};
6 use randrust-analyzer cargo rand 0.8.7 crate/::Rngrust-analyzer cargo rand 0.8.7 rng/Rng#;
7 use sha2rust-analyzer cargo sha2 0.10.9 crate/::{Digestrust-analyzer cargo digest 0.10.7 digest/Digest#, Sha256rust-analyzer cargo sha2 0.10.9 Sha256#};
8 use stringpreprust-analyzer cargo stringprep 0.1.5 crate/::saslpreprust-analyzer cargo stringprep 0.1.5 saslprep().;
9
10 use base64rust-analyzer cargo base64 0.23.1 crate/::preluderust-analyzer cargo base64 0.23.1 prelude/::{Enginerust-analyzer cargo base64 0.23.1 engine/Engine# as _, BASE64_STANDARDrust-analyzer cargo base64 0.23.1 engine/general_purpose/STANDARD.};
11
12 const GS2_HEADERrust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/GS2_HEADER.: &str = "n,,";
13 const CHANNEL_ATTRrust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/CHANNEL_ATTR.: &str = "c";
14 const USERNAME_ATTRrust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/USERNAME_ATTR.: &str = "n";
15 const CLIENT_PROOF_ATTRrust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/CLIENT_PROOF_ATTR.: &str = "p";
16 const NONCE_ATTRrust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/NONCE_ATTR.: &str = "r";
17
18 pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) async fn authenticaterust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/authenticate().(
19 stream: &mut PgStreamrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#,
20 options: &PgConnectOptionsrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#,
21 data: AuthenticationSaslrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/AuthenticationSasl#,
22 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> {
23 let mut has_sasl = false;
24 let mut has_sasl_plus = false;
25 let mut unknown = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
26
27 for mechanism in data.mechanismsrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/impl#[AuthenticationSasl]mechanisms().() {
28 match mechanism {
29 "SCRAM-SHA-256" => {
30 has_sasl = true;
31 }
32
33 "SCRAM-SHA-256-PLUS" => {
34 has_sasl_plus = true;
35 }
36
37 _ => {
38 unknown.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(mechanism.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().());
39 }
40 }
41 }
42
43 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_sasl_plus && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_sasl {
44 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol!!(
45 "unsupported SASL authentication mechanisms: {}",
46 unknown.joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().(", ")
47 ));
48 }
49
50 // channel-binding = "c=" base64
51 let mut channel_binding = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{CHANNEL_ATTR}=");
52 BASE64_STANDARDrust-analyzer cargo base64 0.23.1 engine/general_purpose/STANDARD..encode_stringrust-analyzer cargo base64 0.23.1 engine/Engine#encode_string().(GS2_HEADERrust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/GS2_HEADER., &mut channel_binding);
53
54 // "n=" saslname ;; Usernames are prepared using SASLprep.
55 let username = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}={}", USERNAME_ATTRrust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/USERNAME_ATTR., options.usernamerust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#username.);
56 let username = match saslpreprust-analyzer cargo stringprep 0.1.5 saslprep().(&username) {
57 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v) => v,
58 // TODO(danielakhterov): Remove panic when we have proper support for configuration errors
59 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Failed to saslprep username"),
60 };
61
62 // nonce = "r=" c-nonce [s-nonce] ;; Second part provided by server.
63 let nonce = gen_noncerust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/gen_nonce().();
64
65 // client-first-message-bare = [reserved-mext ","] username "," nonce ["," extensions]
66 let client_first_message_bare = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{username},{nonce}");
67
68 let client_first_message = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{GS2_HEADER}{client_first_message_bare}");
69
70 stream
71 .sendrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]send().(SaslInitialResponserust-analyzer cargo sqlx-postgres 0.8.3 message/sasl/SaslInitialResponse# {
72 responserust-analyzer cargo sqlx-postgres 0.8.3 message/sasl/SaslInitialResponse#response.: &client_first_message,
73 plusrust-analyzer cargo sqlx-postgres 0.8.3 message/sasl/SaslInitialResponse#plus.: false,
74 })
75 .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
76
77 let cont = match stream.recv_expectrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]recv_expect().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
78 Authenticationrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/Authentication#::SaslContinuerust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/Authentication#SaslContinue#(data) => data,
79
80 auth => {
81 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol!!(
82 "expected SASLContinue but received {:?}",
83 auth
84 ));
85 }
86 };
87
88 // SaltedPassword := Hi(Normalize(password), salt, i)
89 let salted_password = hirust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/hi().(
90 options.passwordrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#password..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().().unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().(),
91 &cont.saltrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/AuthenticationSaslContinue#salt.,
92 cont.iterationsrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/AuthenticationSaslContinue#iterations.,
93 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
94
95 // ClientKey := HMAC(SaltedPassword, "Client Key")
96 let mut mac = Hmacrust-analyzer cargo hmac 0.12.1 optim/Hmac#::<Sha256rust-analyzer cargo sha2 0.10.9 Sha256#>::new_from_slicerust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]new_from_slice().(&salted_password).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::protocolrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]protocol().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
97 mac.updaterust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]update().(b"Client Key");
98
99 let client_key = mac.finalizerust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]finalize().().into_bytesrust-analyzer cargo digest 0.10.7 mac/impl#[`CtOutput<T>`]into_bytes().();
100
101 // StoredKey := H(ClientKey)
102 let stored_key = Sha256rust-analyzer cargo sha2 0.10.9 Sha256#::digestrust-analyzer cargo digest 0.10.7 digest/impl#[D][Digest]digest().(client_key);
103
104 // client-final-message-without-proof
105 let client_final_message_wo_proof = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
106 "{channel_binding},r={nonce}",
107 channel_binding = channel_binding,
108 nonce = &cont.noncerust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/AuthenticationSaslContinue#nonce.
109 );
110
111 // AuthMessage := client-first-message-bare + "," + server-first-message + "," + client-final-message-without-proof
112 let auth_message = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
113 "{client_first_message_bare},{server_first_message},{client_final_message_wo_proof}",
114 client_first_message_bare = client_first_message_bare,
115 server_first_message = cont.messagerust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/AuthenticationSaslContinue#message.,
116 client_final_message_wo_proof = client_final_message_wo_proof
117 );
118
119 // ClientSignature := HMAC(StoredKey, AuthMessage)
120 let mut mac = Hmacrust-analyzer cargo hmac 0.12.1 optim/Hmac#::<Sha256rust-analyzer cargo sha2 0.10.9 Sha256#>::new_from_slicerust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]new_from_slice().(&stored_key).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::protocolrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]protocol().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
121 mac.updaterust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]update().(auth_message.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().());
122
123 let client_signature = mac.finalizerust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]finalize().().into_bytesrust-analyzer cargo digest 0.10.7 mac/impl#[`CtOutput<T>`]into_bytes().();
124
125 // ClientProof := ClientKey XOR ClientSignature
126 let client_proof: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = client_key
127 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
128 .ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(client_signature.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().())
129 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(&a, &b)| a rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitXor<Self>`]bitxor().^rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitXor<Self>`]bitxor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitXor<Self>`]bitxor().b)
130 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
131
132 // ServerKey := HMAC(SaltedPassword, "Server Key")
133 let mut mac = Hmacrust-analyzer cargo hmac 0.12.1 optim/Hmac#::<Sha256rust-analyzer cargo sha2 0.10.9 Sha256#>::new_from_slicerust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]new_from_slice().(&salted_password).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::protocolrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]protocol().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
134 mac.updaterust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]update().(b"Server Key");
135
136 let server_key = mac.finalizerust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]finalize().().into_bytesrust-analyzer cargo digest 0.10.7 mac/impl#[`CtOutput<T>`]into_bytes().();
137
138 // ServerSignature := HMAC(ServerKey, AuthMessage)
139 let mut mac = Hmacrust-analyzer cargo hmac 0.12.1 optim/Hmac#::<Sha256rust-analyzer cargo sha2 0.10.9 Sha256#>::new_from_slicerust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]new_from_slice().(&server_key).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::protocolrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]protocol().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
140 mac.updaterust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]update().(auth_message.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().());
141
142 // client-final-message = client-final-message-without-proof "," proof
143 let mut client_final_message = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{client_final_message_wo_proof},{CLIENT_PROOF_ATTR}=");
144 BASE64_STANDARDrust-analyzer cargo base64 0.23.1 engine/general_purpose/STANDARD..encode_stringrust-analyzer cargo base64 0.23.1 engine/Engine#encode_string().(client_proof, &mut client_final_message);
145
146 stream.sendrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]send().(SaslResponserust-analyzer cargo sqlx-postgres 0.8.3 message/sasl/SaslResponse#(&client_final_message)).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
147
148 let data = match stream.recv_expectrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]recv_expect().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
149 Authenticationrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/Authentication#::SaslFinalrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/Authentication#SaslFinal#(data) => data,
150
151 auth => {
152 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol!!("expected SASLFinal but received {:?}", auth));
153 }
154 };
155
156 // authentication is only considered valid if this verification passes
157 mac.verify_slicerust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]verify_slice().(&data.verifierrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/AuthenticationSaslFinal#verifier.).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::protocolrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]protocol().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
158
159 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
160 }
161
162 // nonce is a sequence of random printable bytes
163 fn gen_noncerust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/gen_nonce().() -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
164 let mut rng = randrust-analyzer cargo rand 0.8.7 crate/::thread_rngrust-analyzer cargo rand 0.8.7 rngs/thread/thread_rng().();
165 let count = rng.gen_rangerust-analyzer cargo rand 0.8.7 rng/Rng#gen_range().(64..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#128);
166
167 // printable = %x21-2B / %x2D-7E
168 // ;; Printable ASCII except ",".
169 // ;; Note that any "printable" is also
170 // ;; a valid "value".
171 let nonce: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::repeatrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/repeat/repeat().(())
172 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|()| {
173 let mut c = rng.gen_rangerust-analyzer cargo rand 0.8.7 rng/Rng#gen_range().(0x21u8..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#0x7F);
174
175 while c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0x2C {
176 c = rng.gen_rangerust-analyzer cargo rand 0.8.7 rng/Rng#gen_range().(0x21u8..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#0x7F);
177 }
178
179 c
180 })
181 .takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(count)
182 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|c| c as char)
183 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
184
185 rng.gen_rangerust-analyzer cargo rand 0.8.7 rng/Rng#gen_range().(32..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#128);
186 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{NONCE_ATTR}={nonce}")
187 }
188
189 // Hi(str, salt, i):
190 fn hirust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/hi().<'a>(s: &'a str, salt: &'a [u8], iter_count: u32) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<[u8; 32], Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> {
191 let mut mac = Hmacrust-analyzer cargo hmac 0.12.1 optim/Hmac#::<Sha256rust-analyzer cargo sha2 0.10.9 Sha256#>::new_from_slicerust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]new_from_slice().(s.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::protocolrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]protocol().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
192
193 mac.updaterust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]update().(salt);
194 mac.updaterust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]update().(&1u32.to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_be_bytes().());
195
196 let mut u = mac.finalize_resetrust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]finalize_reset().().into_bytesrust-analyzer cargo digest 0.10.7 mac/impl#[`CtOutput<T>`]into_bytes().();
197 let mut hi = u;
198
199 for _ in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#iter_count {
200 mac.updaterust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]update().(u.as_slicerust-analyzer cargo generic-array 0.14.7 impl#[`GenericArray<T, N>`]as_slice().());
201 u = mac.finalize_resetrust-analyzer cargo digest 0.10.7 mac/impl#[T][Mac]finalize_reset().().into_bytesrust-analyzer cargo digest 0.10.7 mac/impl#[`CtOutput<T>`]into_bytes().();
202 hi = hi.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(u.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(&a, &b)| a rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitXor<Self>`]bitxor().^rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitXor<Self>`]bitxor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitXor<Self>`]bitxor().b).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
203 }
204
205 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(hi.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
206 }
207
208 #[cfg(all(test, not(debug_assertions)))]
209 #[benchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/bench:]
210 fn bench_sasl_hi(b: &mut test::Bencher) {
211 use test::black_box;
212
213 let mut rng = randrust-analyzer cargo rand 0.8.7 crate/::thread_rngrust-analyzer cargo rand 0.8.7 rngs/thread/thread_rng().();
214 let nonce: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::repeatrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/repeat/repeat().(())
215 .map(|()| rng.sample(randrust-analyzer cargo rand 0.8.7 crate/::distributionsrust-analyzer cargo rand 0.8.7 distributions/::Alphanumericrust-analyzer cargo rand 0.8.7 distributions/other/Alphanumeric#))
216 .take(64)
217 .collect();
218 b.iter(|| {
219 let _ = hirust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/hi().(
220 test::black_box("secret_password"),
221 test::black_box(&nonce),
222 test::black_box(4096),
223 );
224 });
225 }