Struct nkeys::XKey

source ·
pub struct XKey { /* private fields */ }
Expand description

The main interface used for reading and writing nkey-encoded curve key pairs.

Implementations§

source§

impl XKey

source

pub fn new() -> Self

Creates a new xkey.

NOTE: This is not available if using on a wasm32-unknown-unknown target due to the lack of rand support. Use new_from_raw instead

source

pub fn new_with_rand(rand: &mut (impl CryptoRng + RngCore)) -> Self

Create a new xkey pair from a random generator

NOTE: These generator should be a cryptographically secure random source.

NOTE: This is not available if using on a wasm32-unknown-unknown target due to the lack of rand support. Use new_from_raw instead

source

pub fn new_from_raw(random_bytes: [u8; 32]) -> Self

Create a new xkey pair using a pre-existing set of random bytes.

NOTE: These bytes should be generated from a cryptographically secure random source.

source

pub fn from_public_key(source: &str) -> Result<Self, Error>

Attempts to produce a public-only xkey from the given encoded public key string

source

pub fn from_seed(source: &str) -> Result<Self, Error>

Attempts to produce a full xkey pair from the given encoded seed string

source

pub fn seed(&self) -> Result<String, Error>

Attempts to return the encoded, human-readable string for this key pair’s seed. Remember that this value should be treated as a secret. Do not store it for any longer than necessary

source

pub fn public_key(&self) -> String

Returns the encoded, human-readable public key of this key pair

source

pub fn private_key(&self) -> Result<String, Error>

source

pub fn key_pair_type(&self) -> KeyPairType

Returns the type of this key pair.

source

pub fn open(&self, input: &[u8], sender: &Self) -> Result<Vec<u8>, Error>

source

pub fn seal(&self, input: &[u8], recipient: &Self) -> Result<Vec<u8>, Error>

Seal is compatible with nacl.Box.Seal() and can be used in similar situations for small messages. We generate the nonce from crypto rand by default.

NOTE: This is not available if using on a wasm32-unknown-unknown target due to the lack of rand support. Use seal_with_nonce instead

source

pub fn seal_with_rand( &self, input: &[u8], recipient: &Self, rand: impl CryptoRng + RngCore, ) -> Result<Vec<u8>, Error>

NOTE: This is not available if using on a wasm32-unknown-unknown target due to the lack of rand support. Use seal_with_nonce instead

source

pub fn seal_with_nonce( &self, input: &[u8], recipient: &Self, nonce: Nonce, ) -> Result<Vec<u8>, Error>

NOTE: Nonce bytes should be generated from a cryptographically secure random source, and only be used once.

Trait Implementations§

source§

impl Clone for XKey

source§

fn clone(&self) -> XKey

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 Debug for XKey

source§

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

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

impl Default for XKey

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for XKey

§

impl RefUnwindSafe for XKey

§

impl Send for XKey

§

impl Sync for XKey

§

impl Unpin for XKey

§

impl UnwindSafe for XKey

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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 for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

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 T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

source§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

source§

fn vzip(self) -> V