#[repr(C)]pub struct NetworkKey(pub [u8; 32]);Expand description
The network key, or network identifier, used during the secret handshake to prove that both parties are participating in the same ssb network.
The main ssb network uses a publicly-known key, which is
available as NetworkKey::SSB_MAIN_NET.
This is an HMAC key; specifically HMAC-SHA-512-256.
Tuple Fields§
§0: [u8; 32]Implementations§
Source§impl NetworkKey
impl NetworkKey
Sourcepub const SSB_MAIN_NET: NetworkKey
pub const SSB_MAIN_NET: NetworkKey
The NetworkKey for the primary ssb network.
Sourcepub fn from_slice(s: &[u8]) -> Option<Self>
pub fn from_slice(s: &[u8]) -> Option<Self>
Deserialize from a slice of bytes.
Returns None if the slice length isn’t 32.
Sourcepub fn generate_with_rng<R>(r: &mut R) -> NetworkKey
pub fn generate_with_rng<R>(r: &mut R) -> NetworkKey
Generate a random network key using the given cryptographically-secure random number generator.
Sourcepub fn from_base64(s: &str) -> Option<Self>
pub fn from_base64(s: &str) -> Option<Self>
Deserialize from the base-64 representation.
Source§impl NetworkKey
impl NetworkKey
Sourcepub fn authenticate(&self, b: &[u8]) -> NetworkAuth
pub fn authenticate(&self, b: &[u8]) -> NetworkAuth
Generate an authentication code for the given byte slice.
§Examples
use ssb_crypto::NetworkKey;
let netkey = NetworkKey::SSB_MAIN_NET;
let bytes = [1, 2, 3, 4];
let auth = netkey.authenticate(&bytes);
assert!(netkey.verify(&auth, &bytes));Sourcepub fn verify(&self, auth: &NetworkAuth, b: &[u8]) -> bool
pub fn verify(&self, auth: &NetworkAuth, b: &[u8]) -> bool
Verify that an authentication code was generated by this key, given the same byte slice.
Sourcepub fn generate() -> NetworkKey
pub fn generate() -> NetworkKey
Generate a random network key.
§Examples
use ssb_crypto::NetworkKey;
let key = NetworkKey::generate();
assert_ne!(key, NetworkKey::SSB_MAIN_NET);Trait Implementations§
Source§impl AsBytes for NetworkKey
impl AsBytes for NetworkKey
Source§impl Clone for NetworkKey
impl Clone for NetworkKey
Source§fn clone(&self) -> NetworkKey
fn clone(&self) -> NetworkKey
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for NetworkKey
impl Debug for NetworkKey
Source§impl PartialEq for NetworkKey
impl PartialEq for NetworkKey
Source§impl Zeroize for NetworkKey
impl Zeroize for NetworkKey
impl StructuralPartialEq for NetworkKey
Auto Trait Implementations§
impl Freeze for NetworkKey
impl RefUnwindSafe for NetworkKey
impl Send for NetworkKey
impl Sync for NetworkKey
impl Unpin for NetworkKey
impl UnwindSafe for NetworkKey
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