Skip to content
This repository was archived by the owner on Oct 18, 2021. It is now read-only.

Commit 0f348be

Browse files
authored
rustfmt all the things (#237)
1 parent 84b3cc0 commit 0f348be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1413
-824
lines changed

src/apm/event.rs

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ pub struct CommandStarted {
1515

1616
impl Display for CommandStarted {
1717
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
18-
fmt.write_fmt(format_args!("COMMAND.{} {} STARTED: {}",
19-
self.command_name,
20-
self.connection_string,
21-
self.command))
18+
fmt.write_fmt(format_args!(
19+
"COMMAND.{} {} STARTED: {}",
20+
self.command_name,
21+
self.connection_string,
22+
self.command
23+
))
2224
}
2325
}
2426

@@ -43,27 +45,35 @@ pub enum CommandResult<'a> {
4345
impl<'a> Display for CommandResult<'a> {
4446
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
4547
match *self {
46-
CommandResult::Success { duration,
47-
ref reply,
48-
ref command_name,
49-
ref connection_string,
50-
.. } => {
51-
fmt.write_fmt(format_args!("COMMAND.{} {} COMPLETED: {} ({} ns)",
52-
command_name,
53-
connection_string,
54-
reply,
55-
duration.separated_string()))
48+
CommandResult::Success {
49+
duration,
50+
ref reply,
51+
ref command_name,
52+
ref connection_string,
53+
..
54+
} => {
55+
fmt.write_fmt(format_args!(
56+
"COMMAND.{} {} COMPLETED: {} ({} ns)",
57+
command_name,
58+
connection_string,
59+
reply,
60+
duration.separated_string()
61+
))
5662
}
57-
CommandResult::Failure { duration,
58-
ref command_name,
59-
failure,
60-
ref connection_string,
61-
.. } => {
62-
fmt.write_fmt(format_args!("COMMAND.{} {} FAILURE: {} ({} ns)",
63-
command_name,
64-
connection_string,
65-
failure,
66-
duration.separated_string()))
63+
CommandResult::Failure {
64+
duration,
65+
ref command_name,
66+
failure,
67+
ref connection_string,
68+
..
69+
} => {
70+
fmt.write_fmt(format_args!(
71+
"COMMAND.{} {} FAILURE: {} ({} ns)",
72+
command_name,
73+
connection_string,
74+
failure,
75+
duration.separated_string()
76+
))
6777
}
6878
}
6979
}

src/auth.rs

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ impl Authenticator {
6161
let bytes = format!("n,,{}", message).into_bytes();
6262
let binary = Binary(Generic, bytes);
6363

64-
let start_doc = doc! {
64+
let start_doc =
65+
doc! {
6566
"saslStart" => 1,
6667
"autoAuthorize" => 1,
6768
"payload" => binary,
@@ -82,7 +83,11 @@ impl Authenticator {
8283

8384
let response = match String::from_utf8(data) {
8485
Ok(string) => string,
85-
Err(_) => return Err(ResponseError(String::from("Invalid UTF-8 payload returned"))),
86+
Err(_) => {
87+
return Err(ResponseError(
88+
String::from("Invalid UTF-8 payload returned"),
89+
))
90+
}
8691
};
8792

8893
Ok(InitialData {
@@ -95,28 +100,38 @@ impl Authenticator {
95100

96101
fn next(&self, password: String, initial_data: InitialData) -> Result<AuthData> {
97102
// Parse out rnonce, salt, and iteration count
98-
let (rnonce_opt, salt_opt, i_opt) = scan_fmt!(&initial_data.response[..],
99-
"r={},s={},i={}",
100-
String,
101-
String,
102-
u32);
103-
104-
let rnonce_b64 = rnonce_opt
105-
.ok_or_else(|| ResponseError(String::from("Invalid rnonce returned")))?;
103+
let (rnonce_opt, salt_opt, i_opt) = scan_fmt!(
104+
&initial_data.response[..],
105+
"r={},s={},i={}",
106+
String,
107+
String,
108+
u32
109+
);
110+
111+
let rnonce_b64 = rnonce_opt.ok_or_else(|| {
112+
ResponseError(String::from("Invalid rnonce returned"))
113+
})?;
106114

107115
// Validate rnonce to make sure server isn't malicious
108116
if !rnonce_b64.starts_with(&initial_data.nonce[..]) {
109-
return Err(MaliciousServerError(MaliciousServerErrorType::InvalidRnonce));
117+
return Err(MaliciousServerError(
118+
MaliciousServerErrorType::InvalidRnonce,
119+
));
110120
}
111121

112-
let salt_b64 = salt_opt
113-
.ok_or_else(|| ResponseError(String::from("Invalid salt returned")))?;
122+
let salt_b64 = salt_opt.ok_or_else(|| {
123+
ResponseError(String::from("Invalid salt returned"))
124+
})?;
114125

115-
let salt = base64::decode(salt_b64.as_bytes())
116-
.or_else(|e| Err(ResponseError(format!("Invalid base64 salt returned: {}", e))))?;
126+
let salt = base64::decode(salt_b64.as_bytes()).or_else(|e| {
127+
Err(ResponseError(
128+
format!("Invalid base64 salt returned: {}", e),
129+
))
130+
})?;
117131

118-
let i = i_opt
119-
.ok_or_else(|| ResponseError(String::from("Invalid iteration count returned")))?;
132+
let i = i_opt.ok_or_else(|| {
133+
ResponseError(String::from("Invalid iteration count returned"))
134+
})?;
120135

121136
// Hash password
122137
let mut md5 = Md5::new();
@@ -142,10 +157,12 @@ impl Authenticator {
142157

143158
// Create auth message
144159
let without_proof = format!("c=biws,r={}", rnonce_b64);
145-
let auth_message = format!("{},{},{}",
146-
initial_data.message,
147-
initial_data.response,
148-
without_proof);
160+
let auth_message = format!(
161+
"{},{},{}",
162+
initial_data.message,
163+
initial_data.response,
164+
without_proof
165+
);
149166

150167
// Compute client signature
151168
let mut client_signature_hmac = Hmac::new(Sha1::new(), &stored_key[..]);
@@ -154,8 +171,9 @@ impl Authenticator {
154171

155172
// Sanity check
156173
if client_key.len() != client_signature.len() {
157-
return Err(DefaultError(String::from("Generated client key and/or client signature \
158-
is invalid")));
174+
return Err(DefaultError(String::from(
175+
"Generated client key and/or client signature is invalid",
176+
)));
159177
}
160178

161179
// Compute proof by xor'ing key and signature
@@ -169,11 +187,12 @@ impl Authenticator {
169187
let final_message = format!("{},p={}", without_proof, b64_proof);
170188
let binary = Binary(Generic, final_message.into_bytes());
171189

172-
let next_doc = doc! {
173-
"saslContinue" => 1,
174-
"payload" => binary,
175-
"conversationId" => (initial_data.conversation_id.clone())
176-
};
190+
let next_doc =
191+
doc! {
192+
"saslContinue" => 1,
193+
"payload" => binary,
194+
"conversationId" => (initial_data.conversation_id.clone())
195+
};
177196

178197
let response = try!(self.db.command(next_doc, Suppressed, None));
179198

@@ -185,11 +204,12 @@ impl Authenticator {
185204
}
186205

187206
fn finish(&self, conversation_id: Bson, auth_data: AuthData) -> Result<()> {
188-
let final_doc = doc! {
189-
"saslContinue" => 1,
190-
"payload" => (Binary(Generic, vec![])),
191-
"conversationId" => conversation_id
192-
};
207+
let final_doc =
208+
doc! {
209+
"saslContinue" => 1,
210+
"payload" => (Binary(Generic, vec![])),
211+
"conversationId" => conversation_id
212+
};
193213

194214
// Compute server key
195215
let mut server_key_hmac = Hmac::new(Sha1::new(), &auth_data.salted_password[..]);
@@ -210,21 +230,27 @@ impl Authenticator {
210230
let payload_str = match String::from_utf8(payload.to_owned()) {
211231
Ok(string) => string,
212232
Err(_) => {
213-
return Err(ResponseError(String::from("Invalid UTF-8 payload returned")))
233+
return Err(ResponseError(
234+
String::from("Invalid UTF-8 payload returned"),
235+
))
214236
}
215237
};
216238

217239
// Check that the signature exists
218240
let verifier = match scan_fmt!(&payload_str[..], "v={}", String) {
219241
Some(string) => string,
220-
None => return Err(
221-
MaliciousServerError(MaliciousServerErrorType::NoServerSignature)),
242+
None => {
243+
return Err(MaliciousServerError(
244+
MaliciousServerErrorType::NoServerSignature,
245+
))
246+
}
222247
};
223248

224249
// Check that the signature is valid
225250
if verifier.ne(&base64::encode(&server_signature)[..]) {
226-
return Err(
227-
MaliciousServerError(MaliciousServerErrorType::InvalidServerSignature));
251+
return Err(MaliciousServerError(
252+
MaliciousServerErrorType::InvalidServerSignature,
253+
));
228254
}
229255
}
230256

src/coll/batch.rs

Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ pub struct UpdateModel {
2828
}
2929

3030
impl UpdateModel {
31-
pub fn new(filter: Document,
32-
update: Document,
33-
upsert: Option<bool>,
34-
multi: bool)
35-
-> UpdateModel {
31+
pub fn new(
32+
filter: Document,
33+
update: Document,
34+
upsert: Option<bool>,
35+
multi: bool,
36+
) -> UpdateModel {
3637
UpdateModel {
3738
filter: filter,
3839
update: update,
@@ -44,10 +45,11 @@ impl UpdateModel {
4445

4546
impl From<UpdateModel> for Document {
4647
fn from(model: UpdateModel) -> Self {
47-
let mut document = doc! {
48-
"q" => (model.filter),
49-
"u" => (model.update)
50-
};
48+
let mut document =
49+
doc! {
50+
"q" => (model.filter),
51+
"u" => (model.update)
52+
};
5153

5254
if let Some(upsert) = model.upsert {
5355
document.insert("upsert", Bson::Boolean(upsert));
@@ -73,33 +75,53 @@ impl From<WriteModel> for Batch {
7375
match model {
7476
WriteModel::InsertOne { document } => Batch::Insert(vec![document]),
7577
WriteModel::DeleteOne { filter } => {
76-
Batch::Delete(vec![DeleteModel {
77-
filter: filter,
78-
multi: false,
79-
}])
78+
Batch::Delete(vec![
79+
DeleteModel {
80+
filter: filter,
81+
multi: false,
82+
},
83+
])
8084
}
8185
WriteModel::DeleteMany { filter } => {
82-
Batch::Delete(vec![DeleteModel {
83-
filter: filter,
84-
multi: true,
85-
}])
86+
Batch::Delete(vec![
87+
DeleteModel {
88+
filter: filter,
89+
multi: true,
90+
},
91+
])
8692
}
87-
WriteModel::ReplaceOne { filter, replacement: update, upsert } |
88-
WriteModel::UpdateOne { filter, update, upsert } => {
89-
Batch::Update(vec![UpdateModel {
90-
filter: filter,
91-
update: update,
92-
upsert: upsert,
93-
multi: false,
94-
}])
93+
WriteModel::ReplaceOne {
94+
filter,
95+
replacement: update,
96+
upsert,
97+
} |
98+
WriteModel::UpdateOne {
99+
filter,
100+
update,
101+
upsert,
102+
} => {
103+
Batch::Update(vec![
104+
UpdateModel {
105+
filter: filter,
106+
update: update,
107+
upsert: upsert,
108+
multi: false,
109+
},
110+
])
95111
}
96-
WriteModel::UpdateMany { filter, update, upsert } => {
97-
Batch::Update(vec![UpdateModel {
98-
filter: filter,
99-
update: update,
100-
upsert: upsert,
101-
multi: true,
102-
}])
112+
WriteModel::UpdateMany {
113+
filter,
114+
update,
115+
upsert,
116+
} => {
117+
Batch::Update(vec![
118+
UpdateModel {
119+
filter: filter,
120+
update: update,
121+
upsert: upsert,
122+
multi: true,
123+
},
124+
])
103125
}
104126
}
105127
}
@@ -153,16 +175,28 @@ impl Batch {
153175
}
154176
Batch::Update(ref mut models) => {
155177
match model {
156-
WriteModel::ReplaceOne { filter, replacement: update, upsert } |
157-
WriteModel::UpdateOne { filter, update, upsert } => {
178+
WriteModel::ReplaceOne {
179+
filter,
180+
replacement: update,
181+
upsert,
182+
} |
183+
WriteModel::UpdateOne {
184+
filter,
185+
update,
186+
upsert,
187+
} => {
158188
models.push(UpdateModel {
159189
filter: filter,
160190
update: update,
161191
upsert: upsert,
162192
multi: false,
163193
})
164194
}
165-
WriteModel::UpdateMany { filter, update, upsert } => {
195+
WriteModel::UpdateMany {
196+
filter,
197+
update,
198+
upsert,
199+
} => {
166200
models.push(UpdateModel {
167201
filter: filter,
168202
update: update,

0 commit comments

Comments
 (0)