aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 3b0cae4..8509a5e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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))