Skip to main content

Psk

Struct Psk 

Source
pub struct Psk(/* private fields */);
Expand description

A WPA pre-shared key, validated at construction.

wpa_supplicant takes the psk field in two distinct forms and encodes them differently on the control socket: a passphrase is sent as a quoted string, while a precomputed 256-bit key is sent as raw, unquoted hex. An unquoted value is always read as a raw key, so a passphrase can never fall back to hex encoding the way an SSID can. The two constructors let the caller say which form it means instead of the library guessing from the string’s shape.

Use Psk::passphrase or Psk::raw when the kind is known; parse with str::parse to get wpa_supplicant.conf semantics (exactly 64 hex digits is a raw key, anything else a passphrase — unambiguous because a passphrase is at most 63 characters).

use wifi_ctrl::sta::Psk;

// The constructors say which form is meant.
let psk = Psk::passphrase("correct horse battery")?;
let _key = Psk::raw([0x42; 32]);

// Parsing follows wpa_supplicant.conf: anything but 64 hex digits is a passphrase,
// and passphrases outside 8-63 printable-ASCII characters are rejected.
let _parsed: Psk = "correct horse battery".parse()?;
assert!("short".parse::<Psk>().is_err());

// Debug never reveals key material.
assert_eq!(format!("{psk:?}"), "Psk(<redacted>)");

Implementations§

Source§

impl Psk

Source

pub fn passphrase(passphrase: impl Into<String>) -> Result<Self>

A WPA passphrase: 8-63 printable-ASCII characters (spaces included).

A literal double-quote is rejected even though WPA formally allows it: the control socket has no escape for one inside a quoted value, so it has no safe representation. Anything else outside printable ASCII has no valid representation either. Both yield ClientError::InvalidPsk.

assert!(Psk::passphrase("password123").is_ok());
assert!(Psk::passphrase("2short").is_err());
assert!(Psk::passphrase("pass\"word123").is_err()); // no escape for a quote
Source

pub fn raw(key: [u8; 32]) -> Self

A precomputed 256-bit key, as produced by wpa_passphrase or equivalent PBKDF2 derivation.

Trait Implementations§

Source§

impl Clone for Psk

Source§

fn clone(&self) -> Psk

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Psk

Never print key material: Request (and SetNetwork inside it) is logged at debug level with {:?}.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for Psk

Source§

type Err = ClientError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more

Auto Trait Implementations§

§

impl Freeze for Psk

§

impl RefUnwindSafe for Psk

§

impl Send for Psk

§

impl Sync for Psk

§

impl Unpin for Psk

§

impl UnsafeUnpin for Psk

§

impl UnwindSafe for Psk

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.