My first Rust crate

Posted on

Recently I decided to give Rust another try – if only to compare it to Haskell. After reading through the decent documentation, especially the book, I felt prepared to write some remotely useful application: a command-line application to compute the WPA pre-shared key of a Wi-Fi from its SSID and passphrase.

Why? Because I needed to manually connect to some wireless networks with special and sometimes downright invalid SSIDs and passphrases. Of course, the popular wpa_supplicant comes with a similar tool, wpa_passphrase(8). But where’s the fun in that?

So here it is: my very first Rust crate, wpa-psk, on and

The command-line interface looks like this:

$ wpa-psk "123abcABC.,-" "456defDEF *<:D"

$ wpa-psk --force "bar" "2short"

And the Rust interface looks like this:

let ssid = Ssid::try_from("home")?;
let passphrase = Passphrase::try_from("0123-4567-89")?;
let psk = wpa_psk(&ssid, &passphrase);

Note the validating newtypes Ssid and Passphrase. I like that. Feels like Haskell :)