[][src]Struct ssb_crypto::NetworkKey

#[repr(C)]pub struct NetworkKey(pub [u8; 32]);

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.

Implementations

impl NetworkKey[src]

pub const SIZE: usize[src]

The size of a NetworkKey, in bytes (32).

pub const SSB_MAIN_NET: NetworkKey[src]

The NetworkKey for the primary ssb network.

pub fn from_slice(s: &[u8]) -> Option<Self>[src]

Deserialize from a slice of bytes. Returns None if the slice length isn't 32.

pub fn generate_with_rng<R>(r: &mut R) -> NetworkKey where
    R: CryptoRng + RngCore
[src]

Generate a random network key using the given cryptographically-secure random number generator.

pub fn from_base64(s: &str) -> Option<Self>[src]

Deserialize from the base-64 representation.

impl NetworkKey[src]

pub fn authenticate(&self, b: &[u8]) -> NetworkAuth[src]

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));

pub fn verify(&self, auth: &NetworkAuth, b: &[u8]) -> bool[src]

Verify that an authentication code was generated by this key, given the same byte slice.

pub fn generate() -> NetworkKey[src]

Generate a random network key.

Examples

use ssb_crypto::NetworkKey;
let key = NetworkKey::generate();
assert_ne!(key, NetworkKey::SSB_MAIN_NET);

Trait Implementations

impl AsBytes for NetworkKey[src]

impl Clone for NetworkKey[src]

impl Debug for NetworkKey[src]

impl Drop for NetworkKey[src]

impl PartialEq<NetworkKey> for NetworkKey[src]

impl StructuralPartialEq for NetworkKey[src]

impl Zeroize for NetworkKey[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<Z> Zeroize for Z where
    Z: DefaultIsZeroes
[src]