aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2017-05-26 01:58:33 -0700
committerbnewbold <bnewbold@robocracy.org>2017-05-26 01:58:33 -0700
commit0294cfc029ca3402c1070165a6c585fc56b3f199 (patch)
treec5dea65a2787b579150014767bbb54a0b7ec7499 /src
parente41e8ab92d038a99c97439e489071211da3329cb (diff)
downloadbad-hashish-0294cfc029ca3402c1070165a6c585fc56b3f199.tar.gz
bad-hashish-0294cfc029ca3402c1070165a6c585fc56b3f199.zip
WIP
Diffstat (limited to 'src')
-rw-r--r--src/bin/bhash.rs76
-rw-r--r--src/lib.rs26
2 files changed, 102 insertions, 0 deletions
diff --git a/src/bin/bhash.rs b/src/bin/bhash.rs
new file mode 100644
index 0000000..691db2a
--- /dev/null
+++ b/src/bin/bhash.rs
@@ -0,0 +1,76 @@
+// bad-hashish: a tool for recursively, remotely multi-hashing files
+// Copyright (C) 2017 Bryan Newbold <bnewbold@robocracy.org>
+// GPLv3
+
+extern crate bad_hashish;
+
+#[macro_use]
+extern crate error_chain;
+
+extern crate clap;
+extern crate tree_magic;
+extern crate flate2;
+extern crate tar;
+extern crate crypto;
+
+use clap::App;
+use bad_hashish::Result;
+use std::path::Path;
+use std::io::{self, BufReader};
+use std::io::prelude::*;
+use std::fs::File;
+use flate2::read::GzDecoder;
+use tar::Archive;
+use crypto::digest::Digest;
+use crypto::sha1::Sha1;
+
+
+fn run() -> Result<()> {
+
+ let matches = App::new("bad-hashish")
+ .version(env!("CARGO_PKG_VERSION"))
+ .about("a tool for recursively, remotely multi-hashing files")
+ .arg_from_usage("<FILE>... 'files to hash from'")
+ .get_matches();
+
+ for f in matches.values_of("FILE").unwrap() {
+ let path: &Path = Path::new(f);
+ println!("{} ({})", f, tree_magic::from_filepath(path));
+
+ if tree_magic::match_filepath("application/zip", path) {
+ println!("It's a zip.");
+ } else if tree_magic::match_filepath("application/gzip", path) {
+ println!("It's gzip.");
+ let f = File::open(path)?;
+ let mut gz = GzDecoder::new(f)?;
+
+ let mut reader = BufReader::with_capacity(4*1024*1024, gz);
+ let is_tar: bool = {
+ let buf = reader.fill_buf()?;
+ println!("Inside is: {}", tree_magic::from_u8(&buf));
+ tree_magic::match_u8("application/x-tar", &buf)
+ };
+
+ if is_tar {
+ println!("It's a tar inside");
+ let mut a = Archive::new(reader);
+ for inner in a.entries().unwrap() {
+ let mut inner = inner.unwrap();
+ let mut hasher = Sha1::new();
+ let mut buf: [u8; 1*1024*1024] = [0; 1*1024*1024];
+ loop {
+ let got = inner.read(&mut buf[..])?;
+ if got <= 0 { break };
+ hasher.input(&buf[0..got]);
+ }
+ println!("\t{} {:?}", hasher.result_str(), inner.header().path().unwrap());
+ }
+ }
+ }
+ }
+
+ Ok(())
+}
+
+// At least for now...
+quick_main!(run);
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..3897634
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,26 @@
+// bad-hashish: a tool for recursively, remotely multi-hashing files
+// Copyright (C) 2017 Bryan Newbold <bnewbold@robocracy.org>
+// GPLv3
+
+#[macro_use]
+extern crate log;
+
+#[macro_use]
+extern crate error_chain;
+
+
+mod errors {
+ // Create the Error, ErrorKind, ResultExt, and Result types
+ error_chain! {
+ foreign_links {
+ Io(::std::io::Error);
+ }
+ }
+}
+pub use errors::*;
+
+pub fn bhash() -> Result<()> {
+
+
+ Ok(())
+}