aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-03-22 20:06:43 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-03-22 20:06:43 +0100
commite397107b65258f81b69f43050b503bc8f8756697 (patch)
tree2379d784a614bac4999a8ff8c2722935f75181e9 /src
parente21b2fddd58cacb4dbd99699c2bd83cb5bf2a349 (diff)
downloadcheckpw-e397107b65258f81b69f43050b503bc8f8756697.tar.gz
checkpw-e397107b65258f81b69f43050b503bc8f8756697.tar.bz2
checkpw-e397107b65258f81b69f43050b503bc8f8756697.zip
Replace Hyper/tokio mess with Reqwest.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs48
1 files changed, 13 insertions, 35 deletions
diff --git a/src/main.rs b/src/main.rs
index b742d95..3f82135 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,18 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
-extern crate futures;
-extern crate hyper;
-extern crate hyper_tls;
+extern crate reqwest;
extern crate ring;
-extern crate tokio_core;
-
-use futures::{Future, Stream};
-use hyper::Client;
-use hyper_tls::HttpsConnector;
-use ring::digest;
use std::env;
-use tokio_core::reactor::Core;
+use ring::digest;
//
// Convert a slice of bytes into a string of hex values
@@ -83,31 +75,17 @@ fn test_creating_new_password() {
assert_eq!(&pw.rest, "910077770C8340F63CD2DCA2AC1F120444F");
}
-fn check(pw: Password) -> Result<(), Box<::std::error::Error>> {
- let mut core = Core::new()?;
- let client = Client::configure()
- .connector(HttpsConnector::new(4, &core.handle())?)
- .build(&core.handle());
-
- let uri = format!("https://api.pwnedpasswords.com/range/{}", pw.range).parse()?;
+fn check(pw: Password) {
+ let uri = &format!("https://api.pwnedpasswords.com/range/{}", pw.range);
+ let hashes = reqwest::get(uri).unwrap().text().unwrap();
- let req = client.get(uri).and_then(|res| {
- res.body().concat2().and_then(move |body| {
- let hashes = std::str::from_utf8(&body)?;
- if let Some(pos) = hashes.find(&pw.rest) {
- println!("Password is PWNED!");
- if let Some(res) = hashes[pos..].lines().take(1).collect::<Vec<_>>().pop() {
- let count = res.split(':').skip(1).collect::<Vec<_>>().pop().unwrap();
- println!("The password {} was found in {} breaches", pw.pw, count);
- }
- }
- Ok(())
- })
- });
-
- core.run(req)?;
-
- Ok(())
+ if let Some(pos) = hashes.find(&pw.rest) {
+ println!("Password is PWNED!");
+ if let Some(res) = hashes[pos..].lines().take(1).collect::<Vec<_>>().pop() {
+ let count = res.split(':').skip(1).collect::<Vec<_>>().pop().unwrap();
+ println!("The password {} was found in {} breaches", pw.pw, count);
+ }
+ }
}
fn print_usage() {
@@ -125,6 +103,6 @@ fn main() {
}
for pw in passwords {
- check(Password::new(&pw)).unwrap();
+ check(Password::new(&pw));
}
}