pub struct XKey { /* private fields */ }
Expand description
The main interface used for reading and writing nkey-encoded curve key pairs.
Implementations§
source§impl XKey
impl XKey
sourcepub fn new() -> Self
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
sourcepub fn new_with_rand(rand: &mut (impl CryptoRng + RngCore)) -> Self
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
sourcepub fn new_from_raw(random_bytes: [u8; 32]) -> Self
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.
sourcepub fn from_public_key(source: &str) -> Result<Self, Error>
pub fn from_public_key(source: &str) -> Result<Self, Error>
Attempts to produce a public-only xkey from the given encoded public key string
sourcepub fn from_seed(source: &str) -> Result<Self, Error>
pub fn from_seed(source: &str) -> Result<Self, Error>
Attempts to produce a full xkey pair from the given encoded seed string
sourcepub fn seed(&self) -> Result<String, Error>
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
sourcepub fn public_key(&self) -> String
pub fn public_key(&self) -> String
Returns the encoded, human-readable public key of this key pair
pub fn private_key(&self) -> Result<String, Error>
sourcepub fn key_pair_type(&self) -> KeyPairType
pub fn key_pair_type(&self) -> KeyPairType
Returns the type of this key pair.
pub fn open(&self, input: &[u8], sender: &Self) -> Result<Vec<u8>, Error>
sourcepub fn seal(&self, input: &[u8], recipient: &Self) -> Result<Vec<u8>, Error>
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
sourcepub fn seal_with_rand(
&self,
input: &[u8],
recipient: &Self,
rand: impl CryptoRng + RngCore,
) -> Result<Vec<u8>, Error>
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
Trait Implementations§
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> 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)