pub struct SecretKey(_);
Expand description

An EdDSA secret key.

Instances of this secret are automatically overwritten with zeroes when they fall out of scope.

Implementations§

source§

impl SecretKey

source

pub fn to_bytes(&self) -> [u8; 32]

Convert this secret key to a byte array.

source

pub fn as_bytes<'a>(&'a self) -> &'a [u8; 32]

View this secret key as a byte array.

source

pub fn from_bytes(bytes: &[u8]) -> Result<SecretKey, SignatureError>

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.

source

pub fn generate<T>(csprng: &mut T) -> SecretKeywhere T: CryptoRng + RngCore,

Generate a SecretKey from a csprng.

Example
extern crate rand;
extern crate ed25519_dalek;

use rand::rngs::OsRng;
use ed25519_dalek::PublicKey;
use ed25519_dalek::SecretKey;
use ed25519_dalek::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 AsRef<[u8]> for SecretKey

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Debug for SecretKey

source§

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

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

impl Drop for SecretKey

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a> From<&'a SecretKey> for ExpandedSecretKey

source§

fn from(secret_key: &'a SecretKey) -> ExpandedSecretKey

Construct an ExpandedSecretKey from a SecretKey.

Examples
use rand::rngs::OsRng;
use ed25519_dalek::{SecretKey, ExpandedSecretKey};

let mut csprng = OsRng{};
let secret_key: SecretKey = SecretKey::generate(&mut csprng);
let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from(&secret_key);
source§

impl<'a> From<&'a SecretKey> for PublicKey

source§

fn from(secret_key: &SecretKey) -> PublicKey

Derive this public key from its corresponding SecretKey.

source§

impl Zeroize for 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§

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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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 Twhere V: MultiLane<T>,

source§

fn vzip(self) -> V