[][src]Struct private_box::Keypair

#[repr(C)]pub struct Keypair {
    pub secret: SecretKey,
    pub public: PublicKey,
}

A public/secret long-term key pair.

This is an Ed25519 key pair.

Fields

secret: SecretKey

The secret half of the key pair. Keep private.

public: PublicKey

The public half of the key pair. Feel free to share.

Implementations

impl Keypair[src]

pub const SIZE: usize[src]

Size of a key pair, in bytes (== 64).

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

Deserialize a keypair from a byte slice.

The slice length must be 64; where the first 32 bytes are the secret key, and the second 32 bytes are the public key (libsodium's standard layout).

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

Deserialize from the bas64 representation. Ignores optional .ed25519 suffix.

Example

let s = "R6DKoOCt1Cj/IB2/ocvj2Eyp8AgmFdoJ9hH2TO4Tl8Yfapd5Lmw4pSpoY0WBEnqpHjz6UB4/QL2Wr0hWVAyi1w==.ed25519";
if let Some(keypair) = ssb_crypto::Keypair::from_base64(s) {
  // let auth = keypair.sign("hello".to_bytes());
  // ...
} else {
    panic!()
}

pub fn as_base64(&self) -> String[src]

Does not include ".ed25519" suffix or a sigil prefix.

Example

let s = "R6DKoOCt1Cj/IB2/ocvj2Eyp8AgmFdoJ9hH2TO4Tl8Yfapd5Lmw4pSpoY0WBEnqpHjz6UB4/QL2Wr0hWVAyi1w==";
let kp = ssb_crypto::Keypair::from_base64(s).unwrap();
assert_eq!(kp.as_base64(), s);

pub fn generate() -> Keypair[src]

Generate a new random keypair.

pub fn from_seed(seed: &[u8]) -> Option<Keypair>[src]

Create a keypair from the given seed bytes. Slice length must be 32.

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

Generate a new random keypair using the given cryptographically-secure random number generator.

pub fn sign(&self, b: &[u8]) -> Signature[src]

Generate a signature for a given byte slice.

Trait Implementations

impl AsBytes for Keypair[src]

impl Clone for Keypair[src]

impl Debug for Keypair[src]

impl FromBytes for Keypair[src]

impl<'_> Into<Keypair> for &'_ Keypair[src]

Auto Trait Implementations

impl RefUnwindSafe for Keypair

impl Send for Keypair

impl Sync for Keypair

impl Unpin for Keypair

impl UnwindSafe for Keypair

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>,