Skip to content

Commit

Permalink
Add crevsum tool
Browse files Browse the repository at this point in the history
  • Loading branch information
dpc committed Dec 18, 2018
1 parent 56366d4 commit b221461
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 2 deletions.
15 changes: 14 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ members = [
"crev-bin",
"cargo-crev",
"recursive-digest",
"rblake2sum"
"rblake2sum",
"crevsum"
]
26 changes: 26 additions & 0 deletions crevsum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "crevsum"
version = "0.1.0"
authors = ["Dawid Ciężarkiewicz <dpc@dpc.pw>"]
edition = "2018"
description = "Recursive digest as calculated by `crev`"
keywords = ["data", "filesystem", "digest", "hash"]
license = "MPL-2.0 OR MIT OR Apache-2.0"
documentation = "https://docs.rs/rblake2sum"
homepage = "https://github.com/dpc/crev/tree/master/rblake2sum"
repository = "https://github.com/dpc/crev/tree/master/rblake2sum"
readme = "README.md"

[dependencies]
base64 = "0.9.0"

hex = "0.3"
crev-recursive-digest = { path = "../recursive-digest", version = "0.1" }
structopt = "0.2"
common_failures = "0.1"
failure = "0.1"


[dependencies.crev-common]
path = "../crev-common"
version = "0.1"
3 changes: 3 additions & 0 deletions crevsum/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `rblake2sum`

Calculate a recursive digest of paths, using [`crev-recursive-digest`](https://github.com/dpc/crev/tree/master/recursive-digest) algorithm.
1 change: 1 addition & 0 deletions crevsum/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
merge_imports = true
29 changes: 29 additions & 0 deletions crevsum/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extern crate structopt;

mod opts;

use common_failures::prelude::*;
use structopt::StructOpt;

use std::collections::HashSet;

fn main() -> Result<()> {
let opts = opts::Opts::from_args();

for path in opts.paths {
let digest = crev_recursive_digest::get_recursive_digest_for_dir::<
crev_common::Blake2b256,
_,
>(&path, &HashSet::new())?;
println!(
"{} {}",
if opts.base64 {
crev_common::base64_encode(&digest)
} else {
hex::encode(digest)
},
path.display()
);
}
Ok(())
}
14 changes: 14 additions & 0 deletions crevsum/src/opts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::path::PathBuf;
use structopt::StructOpt;

#[derive(Debug, StructOpt, Clone)]
#[structopt(
name = "rblake2sum",
about = "Calculate recursive blake2 digest for path or directory"
)]
pub struct Opts {
#[structopt(long = "base64")]
pub base64: bool,
#[structopt(parse(from_os_str))]
pub paths: Vec<PathBuf>,
}

0 comments on commit b221461

Please sign in to comment.