diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2019-02-12 20:47:27 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2019-02-12 20:49:03 +0100 |
commit | 6665fd05a9a72bdaa1c56d30cb15fbf939ea84d9 (patch) | |
tree | 560fdbb65001cc9c96ac23881bdd4e1717fdedf0 | |
parent | 8b29cd55797cc58527e8c2722cd2995334b0b8a9 (diff) | |
download | checkpw-6665fd05a9a72bdaa1c56d30cb15fbf939ea84d9.tar.gz checkpw-6665fd05a9a72bdaa1c56d30cb15fbf939ea84d9.tar.bz2 checkpw-6665fd05a9a72bdaa1c56d30cb15fbf939ea84d9.zip |
Run cargo fmt on sources.
-rw-r--r-- | rustfmt.toml | 13 | ||||
-rw-r--r-- | src/lib.rs | 17 | ||||
-rw-r--r-- | src/main.rs | 13 |
3 files changed, 29 insertions, 14 deletions
diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..b6643ec --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,13 @@ +max_width = 100 +hard_tabs = false +tab_spaces = 4 +newline_style = "Auto" +use_small_heuristics = "Default" +reorder_imports = true +reorder_modules = true +remove_nested_parens = true +edition = "2018" +merge_derives = true +use_try_shorthand = false +use_field_init_shorthand = false +force_explicit_abi = true @@ -21,9 +21,7 @@ use ring::digest; // Convert a slice of bytes into a string of hex values // fn to_hex(data: &[u8]) -> String { - data.iter() - .map(|b| format!("{:02X}", b)) - .collect() + data.iter().map(|b| format!("{:02X}", b)).collect() } #[test] @@ -58,13 +56,20 @@ impl Password { pub fn new(pw: &str) -> Password { let (range, rest) = to_k_anon(digest::digest(&digest::SHA1, &pw.as_bytes())); - Password { range, rest, } + Password { range, rest } } pub fn is_pwned(&self, hashes: &str) -> usize { if let Some(pos) = hashes.find(&self.rest) { if let Some(res) = hashes[pos..].lines().take(1).collect::<Vec<_>>().pop() { - return res.split(':').skip(1).collect::<Vec<_>>().pop().unwrap().parse().unwrap(); + return res + .split(':') + .skip(1) + .collect::<Vec<_>>() + .pop() + .unwrap() + .parse() + .unwrap(); } } @@ -103,7 +108,7 @@ fn test_matching_response_with_multiple_matches() { assert_eq!(42, pw.is_pwned(&hashes)); } -pub fn check(pw: Password) -> Result<usize, reqwest::Error>{ +pub fn check(pw: Password) -> Result<usize, reqwest::Error> { let uri = &format!("https://api.pwnedpasswords.com/range/{}", pw.range); let hashes = reqwest::get(uri)?.text()?; Ok(pw.is_pwned(&hashes)) diff --git a/src/main.rs b/src/main.rs index b89a381..3a2f4cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,16 +15,15 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use checkpw::{check, Password}; -use std::{env, error::Error, thread, time, process}; +use std::{env, error::Error, process, thread, time}; fn print_usage() { println!("Usage: checkpw <pw>..."); } fn main() { - let (args, passwords) : (Vec<String>, Vec<String>) = env::args() - .skip(1) - .partition(|arg| arg.starts_with('-')); + let (args, passwords): (Vec<String>, Vec<String>) = + env::args().skip(1).partition(|arg| arg.starts_with('-')); if args.is_empty() && passwords.is_empty() { print_usage(); @@ -37,8 +36,7 @@ fn main() { for pw in passwords { if first_round { first_round = false; - } - else { + } else { thread::sleep(time::Duration::new(1, 0)); } @@ -48,8 +46,7 @@ fn main() { if num > 0 { println!("Password is PWNED! It was found in {} breaches.", num); pwn_count += 1; - } - else { + } else { println!("Password was not found in any breaches"); } } |