diff options
| author | Stefan Kreutz <mail@skreutz.com> | 2022-05-28 15:15:39 +0200 | 
|---|---|---|
| committer | Stefan Kreutz <mail@skreutz.com> | 2022-05-28 15:15:39 +0200 | 
| commit | 988c7921eacee0cf0b519788c143fe428972b0dc (patch) | |
| tree | 960de0b9d552c6b8dc28475acc0276ec66ae8e5f /wpa-psk-cli/src/bin | |
| parent | 7b9bff64d6c13cc8ea592c2ef6fec96d7062f0c5 (diff) | |
| download | wpa-psk-988c7921eacee0cf0b519788c143fe428972b0dc.tar | |
Extract wpa-psk-cli cratewpa-psk-cli-0.1.0wpa-psk-0.2.0
Diffstat (limited to 'wpa-psk-cli/src/bin')
| -rw-r--r-- | wpa-psk-cli/src/bin/wpa-psk.rs | 48 | 
1 files changed, 48 insertions, 0 deletions
diff --git a/wpa-psk-cli/src/bin/wpa-psk.rs b/wpa-psk-cli/src/bin/wpa-psk.rs new file mode 100644 index 0000000..181585c --- /dev/null +++ b/wpa-psk-cli/src/bin/wpa-psk.rs @@ -0,0 +1,48 @@ +use std::process::exit; + +use clap::Parser; +use wpa_psk::{bytes_to_hex, wpa_psk, wpa_psk_unchecked, Passphrase, Ssid}; + +/// Compute the WPA-PSK of a Wi-Fi SSID and passphrase. +#[derive(Debug, Parser)] +#[clap(about, version, author)] +struct Args { +    /// An SSID consisting of 1 up to 32 arbitrary bytes. +    ssid: String, + +    /// A passphrase consisting of 8 up to 63 printable ASCII characters. +    passphrase: String, + +    /// Don't check the given SSID and passphrase. +    #[clap(short, long)] +    force: bool, +} + +fn main() { +    exit(match run() { +        Ok(_) => 0, +        Err(err) => { +            eprintln!("{}", err); +            1 +        } +    }) +} + +fn run() -> Result<(), Box<dyn std::error::Error>> { +    let args = Args::try_parse()?; +    let psk = if args.force { +        wpa_psk_unchecked(args.ssid.as_bytes(), args.passphrase.as_bytes()) +    } else { +        let ssid = Ssid::try_from(args.ssid.as_bytes())?; +        let passphrase = Passphrase::try_from(args.passphrase.as_bytes())?; +        wpa_psk(&ssid, &passphrase) +    }; +    println!("0x{}", bytes_to_hex(&psk)); +    Ok(()) +} + +#[test] +fn verify_clap_app() { +    use clap::IntoApp; +    Args::command().debug_assert() +}  |