Struct dryoc::keypair::KeyPair

source ·
pub struct KeyPair<PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> {
    pub public_key: PublicKey,
    pub secret_key: SecretKey,
}
Expand description

Public/private keypair for use with crate::dryocbox::DryocBox, aka libsodium box

Fields§

§public_key: PublicKey

Public key

§secret_key: SecretKey

Secret key

Implementations§

source§

impl KeyPair<Locked<HeapByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>, Locked<HeapByteArray<CRYPTO_BOX_SECRETKEYBYTES>>>

source

pub fn new_locked_keypair() -> Result<Self, Error>

Available on crate feature nightly only.

Returns a new locked keypair.

source

pub fn gen_locked_keypair() -> Result<Self, Error>

Available on crate feature nightly only.

Returns a new randomly generated locked keypair.

source§

impl KeyPair<LockedRO<HeapByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>, LockedRO<HeapByteArray<CRYPTO_BOX_SECRETKEYBYTES>>>

source

pub fn gen_readonly_locked_keypair() -> Result<Self, Error>

Available on crate feature nightly only.

Returns a new randomly generated locked, read-only keypair.

source§

impl<PublicKey: NewByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: NewByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> KeyPair<PublicKey, SecretKey>

source

pub fn new() -> Self

Creates a new, empty keypair.

source

pub fn gen() -> Self

Generates a random keypair.

source

pub fn from_secret_key(secret_key: SecretKey) -> Self

Derives a keypair from secret_key, and consumes it, and returns a new keypair.

source

pub fn from_seed<Seed: Bytes>(seed: &Seed) -> Self

Derives a keypair from seed, returning a new keypair.

source§

impl KeyPair<StackByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, StackByteArray<CRYPTO_BOX_SECRETKEYBYTES>>

source

pub fn gen_with_defaults() -> Self

Randomly generates a new keypair, using default types (stack-allocated byte arrays). Provided for convenience.

source§

impl<'a, PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + TryFrom<&'a [u8]> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + TryFrom<&'a [u8]> + Zeroize> KeyPair<PublicKey, SecretKey>

source

pub fn from_slices( public_key: &'a [u8], secret_key: &'a [u8] ) -> Result<Self, Error>

Constructs a new keypair from key slices, consuming them. Does not check validity or authenticity of keypair.

source§

impl<PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> KeyPair<PublicKey, SecretKey>

source

pub fn kx_new_client_session<SessionKey: NewByteArray<CRYPTO_KX_SESSIONKEYBYTES> + Zeroize>( &self, server_public_key: &PublicKey ) -> Result<Session<SessionKey>, Error>

Creates new client session keys using this keypair and server_public_key, assuming this keypair is for the client.

source

pub fn kx_new_server_session<SessionKey: NewByteArray<CRYPTO_KX_SESSIONKEYBYTES> + Zeroize>( &self, client_public_key: &PublicKey ) -> Result<Session<SessionKey>, Error>

Creates new server session keys using this keypair and client_public_key, assuming this keypair is for the server.

Trait Implementations§

source§

impl<PublicKey: Clone + ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: Clone + ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> Clone for KeyPair<PublicKey, SecretKey>

source§

fn clone(&self) -> KeyPair<PublicKey, SecretKey>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<PublicKey: Debug + ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: Debug + ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> Debug for KeyPair<PublicKey, SecretKey>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<PublicKey: NewByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: NewByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> Default for KeyPair<PublicKey, SecretKey>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de, PublicKey, SecretKey> Deserialize<'de> for KeyPair<PublicKey, SecretKey>where PublicKey: Deserialize<'de> + ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: Deserialize<'de> + ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> Drop for KeyPair<PublicKey, SecretKey>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> PartialEq<KeyPair<PublicKey, SecretKey>> for KeyPair<PublicKey, SecretKey>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<PublicKey, SecretKey> Serialize for KeyPair<PublicKey, SecretKey>where PublicKey: Serialize + ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: Serialize + ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<PublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize> Zeroize for KeyPair<PublicKey, SecretKey>

source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

Auto Trait Implementations§

§

impl<PublicKey, SecretKey> RefUnwindSafe for KeyPair<PublicKey, SecretKey>where PublicKey: RefUnwindSafe, SecretKey: RefUnwindSafe,

§

impl<PublicKey, SecretKey> Send for KeyPair<PublicKey, SecretKey>where PublicKey: Send, SecretKey: Send,

§

impl<PublicKey, SecretKey> Sync for KeyPair<PublicKey, SecretKey>where PublicKey: Sync, SecretKey: Sync,

§

impl<PublicKey, SecretKey> Unpin for KeyPair<PublicKey, SecretKey>where PublicKey: Unpin, SecretKey: Unpin,

§

impl<PublicKey, SecretKey> UnwindSafe for KeyPair<PublicKey, SecretKey>where PublicKey: UnwindSafe, SecretKey: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,