Skip to content

Commit b27dfbc

Browse files
minor: fix clippy errors (#216)
1 parent 44d0ce9 commit b27dfbc

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/client/auth/scram.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,13 @@ fn xor(lhs: &[u8], rhs: &[u8]) -> Vec<u8> {
266266
}
267267

268268
fn mac<M: Mac>(key: &[u8], input: &[u8]) -> Result<Vec<u8>> {
269-
let mut mac =
270-
M::new_varkey(key).or_else(|_| Err(Error::unknown_authentication_error("SCRAM")))?;
269+
let mut mac = M::new_varkey(key).map_err(|_| Error::unknown_authentication_error("SCRAM"))?;
271270
mac.input(input);
272271
Ok(mac.result().code().to_vec())
273272
}
274273

275274
fn mac_verify<M: Mac>(key: &[u8], input: &[u8], signature: &[u8]) -> Result<()> {
276-
let mut mac =
277-
M::new_varkey(key).or_else(|_| Err(Error::unknown_authentication_error("SCRAM")))?;
275+
let mut mac = M::new_varkey(key).map_err(|_| Error::unknown_authentication_error("SCRAM"))?;
278276
mac.input(input);
279277
match mac.verify(signature) {
280278
Ok(_) => Ok(()),
@@ -396,9 +394,9 @@ impl ServerFirst {
396394
};
397395
let done = response
398396
.get_bool("done")
399-
.or_else(|_| Err(Error::invalid_authentication_response("SCRAM")))?;
400-
let message = str::from_utf8(payload)
401-
.or_else(|_| Err(Error::invalid_authentication_response("SCRAM")))?;
397+
.map_err(|_| Error::invalid_authentication_response("SCRAM"))?;
398+
let message =
399+
str::from_utf8(payload).map_err(|_| Error::invalid_authentication_response("SCRAM"))?;
402400

403401
let parts: Vec<&str> = message.split(',').collect();
404402

@@ -409,7 +407,7 @@ impl ServerFirst {
409407
let full_nonce = parse_kvp(parts[0], NONCE_KEY)?;
410408

411409
let salt = base64::decode(parse_kvp(parts[1], SALT_KEY)?.as_str())
412-
.or_else(|_| Err(Error::invalid_authentication_response("SCRAM")))?;
410+
.map_err(|_| Error::invalid_authentication_response("SCRAM"))?;
413411

414412
let i: usize = match parse_kvp(parts[2], ITERATION_COUNT_KEY)?.parse() {
415413
Ok(num) => num,
@@ -563,12 +561,12 @@ impl ServerFinal {
563561
.ok_or_else(|| Error::invalid_authentication_response("SCRAM"))?;
564562
let done = response
565563
.get_bool("done")
566-
.or_else(|_| Err(Error::invalid_authentication_response("SCRAM")))?;
564+
.map_err(|_| Error::invalid_authentication_response("SCRAM"))?;
567565
let payload = response
568566
.get_binary_generic("payload")
569-
.or_else(|_| Err(Error::invalid_authentication_response("SCRAM")))?;
570-
let message = str::from_utf8(payload)
571-
.or_else(|_| Err(Error::invalid_authentication_response("SCRAM")))?;
567+
.map_err(|_| Error::invalid_authentication_response("SCRAM"))?;
568+
let message =
569+
str::from_utf8(payload).map_err(|_| Error::invalid_authentication_response("SCRAM"))?;
572570

573571
let first = message
574572
.chars()
@@ -615,7 +613,7 @@ impl ServerFinal {
615613
ServerFinalBody::Verifier(ref body) => {
616614
let server_key = scram.hmac(salted_password, b"Server Key")?;
617615
let body_decoded = base64::decode(body.as_bytes())
618-
.or_else(|_| Err(Error::invalid_authentication_response("SCRAM")))?;
616+
.map_err(|_| Error::invalid_authentication_response("SCRAM"))?;
619617

620618
scram.hmac_verify(
621619
server_key.as_slice(),

src/sdam/description/server.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl ServerDescription {
138138
.map(|hostname| hostname.to_lowercase())
139139
.collect();
140140

141-
std::mem::replace(hosts, normalized_hostnames);
141+
*hosts = normalized_hostnames;
142142
}
143143

144144
if let Some(ref mut passives) = reply.command_response.passives {
@@ -147,7 +147,7 @@ impl ServerDescription {
147147
.map(|hostname| hostname.to_lowercase())
148148
.collect();
149149

150-
std::mem::replace(passives, normalized_hostnames);
150+
*passives = normalized_hostnames;
151151
}
152152

153153
if let Some(ref mut arbiters) = reply.command_response.arbiters {
@@ -156,11 +156,11 @@ impl ServerDescription {
156156
.map(|hostname| hostname.to_lowercase())
157157
.collect();
158158

159-
std::mem::replace(arbiters, normalized_hostnames);
159+
*arbiters = normalized_hostnames;
160160
}
161161

162162
if let Some(ref mut me) = reply.command_response.me {
163-
std::mem::replace(me, me.to_lowercase());
163+
*me = me.to_lowercase();
164164
}
165165
}
166166

0 commit comments

Comments
 (0)