Struct vodozemac::Ed25519SecretKey
source · [−]pub struct Ed25519SecretKey(_);
Expand description
An Ed25519 secret key, used to create digital signatures.
Implementations
sourceimpl Ed25519SecretKey
impl Ed25519SecretKey
sourcepub fn from_slice(bytes: &[u8]) -> Result<Self, KeyError>
pub fn from_slice(bytes: &[u8]) -> Result<Self, KeyError>
Try to create a Ed25519SecretKey
from a slice of bytes.
sourcepub fn to_base64(&self) -> String
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.
sourcepub fn from_base64(key: &str) -> Result<Self, KeyError>
pub fn from_base64(key: &str) -> Result<Self, KeyError>
Try to create a Ed25519SecretKey
from a base64 encoded string.
sourcepub fn public_key(&self) -> Ed25519PublicKey
pub fn public_key(&self) -> Ed25519PublicKey
Get the public key that matches this Ed25519SecretKey
.
sourcepub fn sign(&self, message: &[u8]) -> Ed25519Signature
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
sourceimpl Default for Ed25519SecretKey
impl Default for Ed25519SecretKey
sourceimpl<'de> Deserialize<'de> for Ed25519SecretKey
impl<'de> Deserialize<'de> for Ed25519SecretKey
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Serialize for Ed25519SecretKey
impl Serialize for Ed25519SecretKey
Auto Trait Implementations
impl RefUnwindSafe for Ed25519SecretKey
impl Send for Ed25519SecretKey
impl Sync for Ed25519SecretKey
impl Unpin for Ed25519SecretKey
impl UnwindSafe for Ed25519SecretKey
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more