vodozemac

Struct 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

Source§

type Output = T

Should always be Self
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<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>,