diff options
author | Stefan Kreutz <mail@skreutz.com> | 2022-01-03 23:32:14 +0100 |
---|---|---|
committer | Stefan Kreutz <mail@skreutz.com> | 2022-01-03 23:32:14 +0100 |
commit | e254a5635ef014ffc6982a02d41741ea0160cac6 (patch) | |
tree | 8118e63616087e01ade2c1207231006bd0e10b65 /posts | |
parent | 497b967ab3173a7b9630e0b03574ea1586c559a1 (diff) | |
download | blog-e254a5635ef014ffc6982a02d41741ea0160cac6.tar |
Add wpa-psk-rs release post
Diffstat (limited to 'posts')
-rw-r--r-- | posts/my-first-rust-crate.md | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/posts/my-first-rust-crate.md b/posts/my-first-rust-crate.md new file mode 100644 index 0000000..074df14 --- /dev/null +++ b/posts/my-first-rust-crate.md @@ -0,0 +1,37 @@ +--- +title: "My first Rust crate" +description: "A command-line application and Rust library to compute the WPA-PSK of a Wi-Fi SSID and passphrase." +published: 2022-01-03 +--- + +Recently I decided to give Rust another try -- if only to compare it to Haskell. +After reading through the decent documentation, especially [*the book*](https://doc.rust-lang.org/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](https://hostap.epitest.fi/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 [crates.io](https://crates.io/crates/wpa-psk/0.1.0) and [docs.rs](https://docs.rs/wpa-psk/0.1.0/wpa_psk/). + +The command-line interface looks like this: + + $ wpa-psk "123abcABC.,-" "456defDEF *<:D" + 0x8a366e5bc51cd5d8fbbeffacc5f1af23fac30e3ac93cdcc368fafbbf63a1085c + + $ wpa-psk --force "bar" "2short" + 0xcb5de4e4d23b2ab0bf5b9ba0fe8132c1e2af3bb52298ec801af8ad520cea3437 + +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); + assert_eq!( + bytes_to_hex(&psk), + "150c047b6fad724512a17fa431687048ee503d14c1ea87681d4f241beb04f5ee" + ); + +Note the validating newtypes `Ssid` and `Passphrase`. +I like that. +Feels like Haskell :) |