# `VintageNetWiFi.WPA2`
[🔗](https://github.com/nerves-networking/vintage_net_wifi/blob/v0.12.9/lib/vintage_net_wifi/wpa2.ex#L5)

WPA2 preshared key calculations

WPA2 doesn't use passphrases directly, but instead hashes them with the
SSID and uses the result for the network key. The algorithm that runs
the hash takes some time so it's useful to compute the PSK from the
passphrase once rather than specifying it each time.

# `invalid_passphrase_error`

```elixir
@type invalid_passphrase_error() ::
  :password_too_short | :password_too_long | :invalid_characters
```

# `invalid_ssid_error`

```elixir
@type invalid_ssid_error() :: :ssid_too_short | :ssid_too_long
```

# `psk`

```elixir
@type psk() :: &lt;&lt;_::512&gt;&gt;
```

A WPA2 preshared key

# `to_psk`

```elixir
@spec to_psk(String.t(), psk() | String.t()) ::
  {:ok, psk()} | {:error, invalid_ssid_error() | invalid_passphrase_error()}
```

Convert a WiFi WPA2 passphrase into a PSK

If a passphrase looks like a PSK, then it's assumed that it already is a PSK
and is passed through.

See IEEE Std 802.11i-2004 Appendix H.4 for the algorithm.

# `validate_passphrase`

```elixir
@spec validate_passphrase(String.t()) :: :ok | {:error, invalid_passphrase_error()}
```

Validate the length and characters of a passphrase

A valid passphrase is between 8 and 63 characters long, and
only contains ASCII characters (values between 32 and 126, inclusive).

# `validate_ssid`

```elixir
@spec validate_ssid(String.t()) :: :ok | {:error, invalid_ssid_error()}
```

Validate the length of the SSID

A valid SSID is between 1 and 32 characters long.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
