pub struct SecretKey(/* private fields */);
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
impl SecretKey
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<SecretKey, Error>
pub fn from_bytes(bytes: &[u8]) -> Result<SecretKey, Error>
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.
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 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<'d> Deserialize<'d> for SecretKey
impl<'d> Deserialize<'d> for SecretKey
Source§fn deserialize<D>(
deserializer: D,
) -> Result<SecretKey, <D as Deserializer<'d>>::Error>where
D: Deserializer<'d>,
fn deserialize<D>(
deserializer: D,
) -> Result<SecretKey, <D as Deserializer<'d>>::Error>where
D: Deserializer<'d>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for SecretKey
impl Serialize for SecretKey
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
Encode the hex strict representing
self
into the result. Lower case
letters are used (e.g. f9b4ca
)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
Encode the hex strict representing
self
into the result. Upper case
letters are used (e.g. F9B4CA
)