use super::{Algorithm, CandidateHash, Hash, MatchLevel, MessageLevel, VerificationSource};
-use std::borrow::Borrow;
use std::error::Error;
use std::io::Write;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
}
fn write_filename(mut stdout: &mut StandardStream, filename: &str) -> PrintResult {
- stdout.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)))?;
+ stdout.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)).set_bold(true))?;
write!(&mut stdout, "{}", filename_display(filename))?;
stdout.reset()?;
Ok(())
fn write_algorithm(mut stdout: &mut StandardStream, alg: Algorithm) -> PrintResult {
match alg {
Algorithm::Md5 => {
- stdout.set_color(ColorSpec::new().set_fg(Some(Color::Magenta)))?;
+ stdout.set_color(ColorSpec::new().set_fg(Some(Color::Magenta)).set_bold(true))?;
write!(&mut stdout, "MD5")?;
}
Algorithm::Sha1 => {
- stdout.set_color(ColorSpec::new().set_fg(Some(Color::Cyan)))?;
+ stdout.set_color(ColorSpec::new().set_fg(Some(Color::Cyan)).set_bold(true))?;
write!(&mut stdout, "SHA-1")?;
}
Algorithm::Sha256 => {
- stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green)))?;
+ stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green)).set_bold(true))?;
write!(&mut stdout, "SHA-256")?;
}
+ Algorithm::Sha512 => {
+ stdout.set_color(ColorSpec::new().set_fg(Some(Color::Blue)).set_bold(true))?;
+ write!(&mut stdout, "SHA-512")?;
+ }
}
stdout.reset()?;
Ok(())
fn print_hex_compare(print: &str, against: &str, mut stdout: &mut StandardStream) -> PrintResult {
for (p, a) in print.chars().zip(against.chars()) {
if p == a {
- stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green)))?;
+ stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green)).set_bold(true))?;
} else {
- stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red)))?;
+ stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red)).set_bold(true))?;
}
write!(&mut stdout, "{}", p)?;
}
verify_source: &VerificationSource,
candidate_filename: &Option<String>,
) -> PrintResult {
- stdout.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)))?;
+ stdout.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)).set_bold(true))?;
match &verify_source {
VerificationSource::CommandArgument => {
writeln!(&mut stdout, "command line argument")?;
}
- VerificationSource::Clipboard => {
- writeln!(&mut stdout, "pasted from clipboard")?;
- }
- VerificationSource::RawFile(raw_path) => match raw_path.to_string_lossy().borrow() {
+ VerificationSource::RawFile(raw_path) => match raw_path.as_str() {
"-" => {
writeln!(&mut stdout, "from standard input")?;
}
writeln!(&mut stdout, "from file '{}' containing raw hash", path)?;
}
},
- VerificationSource::DigestsFile(digest_path) => {
- match digest_path.to_string_lossy().borrow() {
- "-" => {
- writeln!(
- &mut stdout,
- "'{}' from digests on standard input",
- candidate_filename.as_ref().unwrap()
- )?;
- }
- path => {
- writeln!(
- &mut stdout,
- "'{}' in digests file '{}'",
- candidate_filename.as_ref().unwrap(),
- path
- )?;
- }
+ VerificationSource::DigestsFile(digest_path) => match digest_path.as_str() {
+ "-" => {
+ writeln!(
+ &mut stdout,
+ "'{}' from digests on standard input",
+ candidate_filename.as_ref().unwrap()
+ )?;
}
- }
+ path => {
+ writeln!(
+ &mut stdout,
+ "'{}' in digests file '{}'",
+ candidate_filename.as_ref().unwrap(),
+ path
+ )?;
+ }
+ },
}
stdout.reset()?;
Ok(())
write!(&mut stdout, "Result: ")?;
match match_level {
MatchLevel::Ok => {
- stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green)))?;
+ stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green)).set_bold(true))?;
writeln!(&mut stdout, "OK")?;
}
MatchLevel::Maybe => {
- stdout.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)))?;
+ stdout.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)).set_bold(true))?;
writeln!(&mut stdout, "MAYBE")?;
}
MatchLevel::Fail => {
- stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red)))?;
+ stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red)).set_bold(true))?;
writeln!(&mut stdout, "FAIL")?;
}
}