hashglass 0.1.0

Fast pentester-focused hash identifier — mode + cost + ready hashcat command. Handles secretsdump / containers / mixed dumps. Identification only.
Documentation
//! Input resolution.
//!
//! The UX has no subcommands: hashglass decides string-vs-file by asking
//! whether the single positional argument is a path that exists on disk
//! (per the plan's `resolve_input`). M1 identifies a raw string; file and
//! stdin batch modes are M3, and are surfaced here as explicit variants so
//! `main` can give a clear "not yet" message instead of silently trying to
//! identify a filename as if it were a hash.

use std::path::{Path, PathBuf};

/// What the positional argument resolved to.
#[derive(Debug, Clone, PartialEq)]
pub enum Input {
    /// A raw hash string to identify (M1).
    Raw(String),
    /// An existing file path — batch identify, arrives in M3.
    File(PathBuf),
    /// `-` — read hashes from stdin, arrives in M3.
    Stdin,
}

/// Resolve a single positional argument to an [`Input`].
///
/// `-` means stdin; an argument naming an existing file means file input;
/// anything else is treated as a raw hash string.
pub fn resolve(arg: &str) -> Input {
    if arg == "-" {
        return Input::Stdin;
    }
    let path = Path::new(arg);
    if path.is_file() {
        return Input::File(path.to_path_buf());
    }
    Input::Raw(arg.to_string())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn dash_is_stdin() {
        assert_eq!(resolve("-"), Input::Stdin);
    }

    #[test]
    fn a_hash_string_is_raw() {
        let arg = "$1$28772684$iEwNOgGugqO9.bIz5sk8k/";
        assert_eq!(resolve(arg), Input::Raw(arg.to_string()));
    }

    #[test]
    fn existing_file_is_file() {
        // Cargo.toml is guaranteed to exist at the crate root during tests.
        let cargo = concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml");
        assert!(matches!(resolve(cargo), Input::File(_)));
    }
}