disable hashing has opt

master
Avril 5 years ago
parent 38fbe63e41
commit 770146bb69
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,4 +1,5 @@
VERSION:= v0.2.0
FEATURES:= --features hash
all: clean deps sign trust
@ -14,7 +15,7 @@ trust:
ln -sf generator-$(VERSION) generator
generator:
cd generator-native && cargo build --release
cd generator-native && cargo build --release $(FEATURES)
ln -sf generator-native/target/release/generator-native generator
cp -f `readlink generator` ./generator-$(VERSION)

@ -48,6 +48,9 @@ pub fn parse() -> Result<OperationMode, &'static str>
}
i += 1;
},
"-u" if look => {
opt |= Opt::NoHash;
},
"-" if look => look=false,
other => {
files.push(other.to_owned());

@ -47,7 +47,7 @@ fn usage() -> ! {
{
let prog = &arg::program_name();
version(true);
println!("Usage: {} [-s] [-e <exec string>] [-o <output file>] [-] <files...>", prog);
println!("Usage: {} [-s] [-e <exec string>] [-o <output file>] [-u] [-] <files...>", prog);
println!("Usage: {} -h", prog);
println!("Usage: {} -v|-V", prog);
println!();
@ -58,6 +58,10 @@ fn usage() -> ! {
println!(" -s\t\tSilent mode.");
println!(" -e <exec>\tScript to run after extraction.");
println!(" -o <file>\tOutput filename.");
#[cfg(feature = "hash")]
println!(" -u\t\tUnchecked mode. Do not compute hashes of inputs.");
#[cfg(not(feature = "hash"))]
println!(" -u\t\tUnchecked mode. (default as generator is not compiled with `hash` feature).");
}
std::process::exit(1)
}
@ -67,7 +71,11 @@ type Sha256Hash = [u8; 32];
#[cfg(not(feature = "hash"))]
type Sha256Hash = ();
fn write_file<From, To>(from: From, to: &mut To) -> io::Result<(Sha256Hash, usize)>
const WF_BUFFER_SIZE: usize = 1024;
const WF_GROUP_SIZE: usize = 16;
#[allow(unused_variables)]
fn write_file<From, To>(from: From, to: &mut To, hash: bool) -> io::Result<(Sha256Hash, usize)>
where From: Read,
To: Write + ?Sized
{
@ -78,25 +86,32 @@ where From: Read,
let mut hash_output = [0u8; 32];
let mut count =0;
let mut digest = Sha256::new();
for buf in from.into_iter(8)
.map(|byte| (digest.input(&[byte]), format!("0x{:02x},", byte)).1)
.group_at(8)
let lambda: Box<dyn FnMut(u8) -> String> = if hash {
Box::new(|byte| (digest.input(&[byte]), format!("0x{:02x},", byte)).1)
} else {
Box::new(|byte| format!("0x{:02x},", byte))
};
for buf in from.into_iter(WF_BUFFER_SIZE)
.map(lambda)
.group_at(WF_GROUP_SIZE)
.map(|bytes| (count += bytes.len(), bytes).1)
.map(|strs| format!("\t{}", strs.join(" ")))
{
writeln!(to, "{}", buf)?;
}
copy_slice(&mut hash_output[..], &digest.result()[..]);
if hash {
copy_slice(&mut hash_output[..], &digest.result()[..]);
}
Ok((hash_output, count))
}
#[cfg(not(feature = "hash"))]
{
let mut count =0;
for buf in from.into_iter(8)
for buf in from.into_iter(WF_BUFFER_SIZE)
.map(|byte| format!("0x{:02x},", byte))
.group_at(8)
.group_at(WF_GROUP_SIZE)
.map(|bytes| (count += bytes.len(), bytes).1)
.map(|strs| format!("\t{}", strs.join(" ")))
{
@ -152,6 +167,7 @@ fn main() -> Result<(), Box<dyn Error>>
_ => None
});
let silent = options.has_tag(&Opt::Silent);
let no_hash = options.has_tag(&Opt::NoHash);
println!("Writing to {}...", output);
let mut fp = OpenOptions::new()
@ -187,7 +203,7 @@ fn main() -> Result<(), Box<dyn Error>>
.read(true)
.open(file)?;
sizes.push(match write_file(file, &mut fp) {
sizes.push(match write_file(file, &mut fp, !no_hash) {
Ok((hash, size)) => {
hashes.push(hash);
println!(" OK");
@ -211,6 +227,7 @@ fn main() -> Result<(), Box<dyn Error>>
writeln!(fp, "\n}};")?;
#[cfg(feature="hash")]
if !no_hash
{
println!("Adding hashes...");
writeln!(fp, "#define DATA_HASHED")?;
@ -237,7 +254,7 @@ fn main() -> Result<(), Box<dyn Error>>
}
};
match write!(fp, "\t\"{}\",", translate::c_escape(file)) {
match writeln!(fp, "\t\"{}\",", translate::c_escape(file)) {
Err(error) => {
println!(" FAILED: write: {}", error);
@ -247,7 +264,7 @@ fn main() -> Result<(), Box<dyn Error>>
};
println!(" OK");
}
writeln!(fp, "\n}};")?;
writeln!(fp, "}};")?;
},
arg::OperationMode::Help => {
usage();

@ -9,6 +9,7 @@ pub enum Opt
Silent,
Execute(String),
Output(String),
NoHash,
}
#[derive(Debug, Clone, PartialEq, Eq)]

Binary file not shown.

Binary file not shown.

@ -1 +1 @@
5f91ab8d00829daa41c25de2a911333ef2558088fdabece4ccf6a3d83b6a0405
eda8606ee47824d0d887f2a946412549416a1e0cc65005e06a25cb8177a11a88

Loading…
Cancel
Save