Skip to main content

Ed25519SecretKey

Struct Ed25519SecretKey 

Source
pub struct Ed25519SecretKey(/* private fields */);
Available on (crate features hmac or hkdf or kmac or ed25519 or x25519 or phc-strings or argon2 or scrypt) and crate feature ed25519 only.
Expand description

Ed25519 secret key bytes.

Provides typed signing and public-key derivation instead of vague &[u8] parameters at the call site.

Implementations§

Source§

impl Ed25519SecretKey

Source

pub const LENGTH: usize = SECRET_KEY_LENGTH

Secret key length in bytes.

Source

pub const fn from_bytes(bytes: [u8; 32]) -> Self

Construct a secret key from its byte representation.

Source

pub fn expose_secret(&self) -> SecretBytes<{ Self::LENGTH }>

Explicitly extract the secret key bytes into a zeroizing wrapper.

Source

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

Borrow the secret key bytes.

Source

pub fn public_key(&self) -> Ed25519PublicKey

Derive the matching Ed25519 public key.

Source

pub fn sign(&self, message: &[u8]) -> Ed25519Signature

Sign a message with this secret key.

Source§

impl Ed25519SecretKey

Source

pub fn generate(fill: impl FnOnce(&mut [u8; 32])) -> Self

Construct a secret key by filling bytes from the provided closure.

let sk = Ed25519SecretKey::generate(|buf| buf.fill(0xA5));
assert_eq!(sk.as_bytes(), &[0xA5; Ed25519SecretKey::LENGTH]);
Source

pub fn random() -> Self

Available on crate feature getrandom only.

Generate a random instance using the operating system’s CSPRNG.

§Panics

Panics if the platform entropy source is unavailable.

Source

pub fn try_random() -> Result<Self, Error>

Available on crate feature getrandom only.

Try to generate a random instance from the platform entropy source.

§Errors

Returns a getrandom error if the platform entropy source is unavailable.

Source§

impl Ed25519SecretKey

Source

pub fn display_secret(&self) -> DisplaySecret<'_>

Returns a wrapper that displays the key bytes as lowercase hex.

This is an explicit opt-in for showing secret key material. The wrapper implements Display.

Trait Implementations§

Source§

impl Clone for Ed25519SecretKey

Source§

fn clone(&self) -> Ed25519SecretKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ConstantTimeEq for Ed25519SecretKey

Source§

fn ct_eq(&self, other: &Self) -> bool

Returns true if self and other are equal. Read more
Source§

impl Debug for Ed25519SecretKey

Source§

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

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

impl<'de> Deserialize<'de> for Ed25519SecretKey

Available on crate feature serde-secrets only.
Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Drop for Ed25519SecretKey

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl FromStr for Ed25519SecretKey

Source§

type Err = InvalidHexError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for Ed25519SecretKey

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Ed25519SecretKey

Available on crate feature serde-secrets only.
Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Ed25519SecretKey

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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

Source§

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,