[−][src]Struct hypercore::SecretKey
An EdDSA secret key.
Methods
impl SecretKey
[src]
pub fn expand<D>(&self) -> ExpandedSecretKey where
D: Digest<OutputSize = UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>> + Default,
[src]
D: Digest<OutputSize = UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>> + Default,
Expand this SecretKey
into an ExpandedSecretKey
.
pub fn to_bytes(&self) -> [u8; 32]
[src]
Convert this secret key to a byte array.
pub fn as_bytes(&'a self) -> &'a [u8; 32]
[src]
View this secret key as a byte array.
pub fn from_bytes(bytes: &[u8]) -> Result<SecretKey, SignatureError>
[src]
Construct a SecretKey
from a slice of bytes.
Example
use ed25519_dalek::SecretKey; use ed25519_dalek::SECRET_KEY_LENGTH; use ed25519_dalek::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)?;
Returns
A Result
whose okay value is an EdDSA SecretKey
or whose error value
is an SignatureError
wrapping the internal error that occurred.
pub fn generate<T>(csprng: &mut T) -> SecretKey where
T: CryptoRng + Rng,
[src]
T: CryptoRng + Rng,
Generate a SecretKey
from a csprng
.
Example
extern crate rand; extern crate sha2; extern crate ed25519_dalek; use rand::Rng; use rand::OsRng; use sha2::Sha512; use ed25519_dalek::PublicKey; use ed25519_dalek::SecretKey; use ed25519_dalek::Signature; let mut csprng: OsRng = OsRng::new().unwrap(); let secret_key: SecretKey = SecretKey::generate(&mut csprng);
Afterwards, you can generate the corresponding public—provided you also
supply a hash function which implements the Digest
and Default
traits, and which returns 512 bits of output—via:
let public_key: PublicKey = PublicKey::from_secret::<Sha512>(&secret_key);
The standard hash function used for most ed25519 libraries is SHA-512,
which is available with use sha2::Sha512
as in the example above.
Other suitable hash functions include Keccak-512 and Blake2b-512.
Input
A CSPRNG with a fill_bytes()
method, e.g. rand::ChaChaRng
Trait Implementations
impl Drop for SecretKey
[src]
Overwrite secret key material with null bytes when it goes out of scope.
impl Debug for SecretKey
[src]
impl Default for SecretKey
[src]
Auto Trait Implementations
impl Sync for SecretKey
impl Send for SecretKey
impl Unpin for SecretKey
impl RefUnwindSafe for SecretKey
impl UnwindSafe for SecretKey
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Clear for T where
T: InitializableFromZeroed + ?Sized,
T: InitializableFromZeroed + ?Sized,
fn clear(&mut self)
impl<T> InitializableFromZeroed for T where
T: Default,
T: Default,
unsafe fn initialize(place: *mut T)
impl<T> Same<T> for T
type Output = T
Should always be Self