Struct vodozemac::Ed25519SecretKey

source ·
pub struct Ed25519SecretKey(/* private fields */);
Expand description

An Ed25519 secret key, used to create digital signatures.

Implementations§

source§

impl Ed25519SecretKey

source

pub const LENGTH: usize = 32usize

The number of bytes a Ed25519 secret key has.

source

pub fn new() -> Self

Create a new random Ed25519SecretKey.

source

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

Get the byte representation of the secret key.

Warning: This creates a copy of the key which won’t be zeroized, the caller of the method needs to make sure to zeroize the returned array.

source

pub fn from_slice(bytes: &[u8; 32]) -> Self

Try to create a Ed25519SecretKey from a slice of bytes.

source

pub fn to_base64(&self) -> String

Convert the secret key to a base64 encoded string.

This can be useful if the secret key needs to be sent over the network or persisted.

Warning: The string should be zeroized after it has been used, otherwise an unintentional copy of the key might exist in memory.

source

pub fn from_base64(input: &str) -> Result<Self, KeyError>

Try to create a Ed25519SecretKey from a base64 encoded string.

source

pub fn public_key(&self) -> Ed25519PublicKey

Get the public key that matches this Ed25519SecretKey.

source

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

Sign the given slice of bytes with this Ed25519SecretKey.

The signature can be verified using the public key.

§Examples
use vodozemac::{Ed25519SecretKey, Ed25519PublicKey};

let secret = Ed25519SecretKey::new();
let message = "It's dangerous to go alone";

let signature = secret.sign(message.as_bytes());

let public_key = secret.public_key();

public_key.verify(message.as_bytes(), &signature).expect("The signature has to be valid");

Trait Implementations§

source§

impl Default for Ed25519SecretKey

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

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

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

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

impl Serialize for Ed25519SecretKey

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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 T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,