pub struct SecretKey(/* private fields */);Expand description
An EdDSA secret key.
Implementations§
Source§impl SecretKey
impl SecretKey
Sourcepub fn from_bytes(bytes: Vec<u8>) -> Result<SecretKey, SignatureError>
pub fn from_bytes(bytes: Vec<u8>) -> Result<SecretKey, SignatureError>
Construct a SecretKey from a slice of bytes.
§Example
use xpx_chain_crypto::SecretKey;
use xpx_chain_crypto::SECRET_KEY_LENGTH;
use xpx_chain_crypto::SignatureError;
let secret_key_bytes: [u8; SECRET_KEY_LENGTH] = [
157, 097, 177, 157, 239, 253, 090, 096,
186, 132, 074, 244, 146, 236, 044, 196,
068, 073, 197, 105, 123, 050, 105, 025,
112, 059, 172, 003, 028, 174, 127, 096, ];
let secret_key: SecretKey = SecretKey::from_bytes(secret_key_bytes.to_vec())?;§Returns
A Result whose okay value is an EdDSA SecretKey or whose error value
is an SignatureError wrapping the internal error that occurred.
Sourcepub fn generate<T>(csprng: &mut T) -> SecretKey
pub fn generate<T>(csprng: &mut T) -> SecretKey
Generate a SecretKey from a csprng.
§Example
extern crate rand;
extern crate sha3;
extern crate xpx_chain_crypto;
use rand::Rng;
use rand::rngs::OsRng;
use sha3::Sha3_512;
use xpx_chain_crypto::PublicKey;
use xpx_chain_crypto::SecretKey;
use xpx_chain_crypto::Signature;
let mut csprng = OsRng{};
let secret_key: SecretKey = SecretKey::generate(&mut csprng);Afterwards, you can generate the corresponding public:
let public_key: PublicKey = (&secret_key).into();§Input
A CSPRNG with a fill_bytes() method, e.g. rand::OsRng
Trait Implementations§
Source§impl Drop for SecretKey
Overwrite secret key material with null bytes when it goes out of scope.
impl Drop for SecretKey
Overwrite secret key material with null bytes when it goes out of scope.
Source§impl<'a> From<&'a SecretKey> for ExpandedSecretKey
impl<'a> From<&'a SecretKey> for ExpandedSecretKey
Source§fn from(secret_key: &'a SecretKey) -> ExpandedSecretKey
fn from(secret_key: &'a SecretKey) -> ExpandedSecretKey
Construct an ExpandedSecretKey from a SecretKey.
§Examples
use rand::Rng;
use rand::thread_rng;
use sha3::Sha3_512;
use xpx_chain_crypto::{SecretKey, ExpandedSecretKey};
let mut csprng = thread_rng();
let secret_key: SecretKey = SecretKey::generate(&mut csprng);
let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from(&secret_key);Auto Trait Implementations§
impl Freeze for SecretKey
impl RefUnwindSafe for SecretKey
impl Send for SecretKey
impl Sync for SecretKey
impl Unpin for SecretKey
impl UnwindSafe for SecretKey
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
Mutably borrows from an owned value. Read more
Source§impl<T> Clear for Twhere
T: InitializableFromZeroed + ?Sized,
impl<T> Clear for Twhere
T: InitializableFromZeroed + ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> InitializableFromZeroed for Twhere
T: Default,
impl<T> InitializableFromZeroed for Twhere
T: Default,
Source§unsafe fn initialize(place: *mut T)
unsafe fn initialize(place: *mut T)
Called to initialize a place to a valid value, after it is set
to all-bits-zero. Read more