pub struct Psk(/* private fields */);Implementations§
Source§impl Psk
impl Psk
Sourcepub fn null() -> Psk
pub fn null() -> Psk
A null PSK (all zeroes).
This should only be used when PSK authentication is not required and only encryption is desired. Using a null PSK provides confidentiality but not authentication.
Sourcepub fn generate() -> Psk
pub fn generate() -> Psk
Generate a random PSK using a cryptographically secure random number generator.
This is the recommended way to create a PSK for secure authentication. The PSK must then be shared with the other party through a secure out-of-band channel (QR code, NFC, secure messaging, etc.).
§Example
use ap_noise::Psk;
let psk = Psk::generate();Sourcepub fn from_bytes(bytes: [u8; 32]) -> Psk
pub fn from_bytes(bytes: [u8; 32]) -> Psk
Construct a PSK from a 32-byte array.
Sourcepub fn to_hex(&self) -> String
pub fn to_hex(&self) -> String
Encode the PSK as a hexadecimal string.
This is the recommended format for storing or transmitting PSKs (e.g., in QR codes, configuration files, or secure storage). The resulting string is 64 characters long.
§Example
use ap_noise::Psk;
use rand::thread_rng;
let psk = Psk::generate();
let encoded = psk.to_hex();
assert_eq!(encoded.len(), 64);Sourcepub fn from_hex(s: &str) -> Result<Psk, NoiseProtocolError>
pub fn from_hex(s: &str) -> Result<Psk, NoiseProtocolError>
Decode a PSK from a hexadecimal string.
Returns an error if the string is not valid hex or does not decode to exactly 32 bytes.
§Example
use ap_noise::Psk;
use rand::thread_rng;
let psk = Psk::generate();
let encoded = psk.to_hex();
let decoded = Psk::from_hex(&encoded).unwrap();
assert_eq!(psk.to_bytes(), decoded.to_bytes());