[][src]Struct ed25519_dalek::SecretKey

pub struct SecretKey(_);

An EdDSA secret key.

Methods

impl SecretKey
[src]

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

Convert this secret key to a byte array.

pub fn as_bytes<'a>(&'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]

Generate a SecretKey from a csprng.

Example

extern crate rand;
extern crate sha2;
extern crate ed25519_dalek;

use rand::Rng;
use rand::rngs::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:

let public_key: PublicKey = (&secret_key).into();

Input

A CSPRNG with a fill_bytes() method, e.g. rand::OsRng

Trait Implementations

impl Debug for SecretKey
[src]

impl<'a> From<&'a SecretKey> for PublicKey
[src]

fn from(secret_key: &SecretKey) -> PublicKey
[src]

Derive this public key from its corresponding SecretKey.

impl<'a> From<&'a SecretKey> for ExpandedSecretKey
[src]

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

Construct an ExpandedSecretKey from a SecretKey.

Examples

use rand::Rng;
use rand::thread_rng;
use sha2::Sha512;
use ed25519_dalek::{SecretKey, ExpandedSecretKey};

let mut csprng = thread_rng();
let secret_key: SecretKey = SecretKey::generate(&mut csprng);
let expanded_secret_key: ExpandedSecretKey = ExpandedSecretKey::from(&secret_key);

impl Drop for SecretKey
[src]

Overwrite secret key material with null bytes when it goes out of scope.

impl Default for SecretKey
[src]

impl AsRef<[u8]> for SecretKey
[src]

Auto Trait Implementations

impl Send for SecretKey

impl Sync for SecretKey

Blanket Implementations

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> From for T
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Clear for T where
    T: InitializableFromZeroed + ?Sized
[src]

impl<T> InitializableFromZeroed for T where
    T: Default
[src]

impl<T> Same for T

type Output = T

Should always be Self