pub struct Key(pub [u8; 32]);
Expand description
Represents a WireGuard encryption key.
WireGuard makes no meaningful distinction between public, private and preshared keys - any sequence of 32 bytes can be used as either of those.
This means that you need to be careful when working with
Key
s, especially ones created from external data.
Tuple Fields§
§0: [u8; 32]
Implementations§
Source§impl Key
impl Key
Sourcepub fn generate_private() -> Self
pub fn generate_private() -> Self
Generates and returns a new private key.
Generates and returns a new preshared key.
Sourcepub fn get_public(&self) -> Self
pub fn get_public(&self) -> Self
Generates a public key for this private key.
pub fn as_bytes(&self) -> &[u8] ⓘ
Sourcepub fn to_base64(&self) -> String
pub fn to_base64(&self) -> String
Converts the key to a standardized base64 representation, as used by the wg
utility and wg-quick
.
Sourcepub fn from_base64(key: &str) -> Result<Self, InvalidKey>
pub fn from_base64(key: &str) -> Result<Self, InvalidKey>
Converts a base64 representation of the key to the raw bytes.
This can fail, as not all text input is valid base64 - in this case
Err(InvalidKey)
is returned.
pub fn from_hex(hex_str: &str) -> Result<Self, InvalidKey>
Trait Implementations§
impl Eq for Key
impl StructuralPartialEq for Key
Auto Trait Implementations§
impl Freeze for Key
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnwindSafe for Key
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more