SigningKey

Struct SigningKey 

Source
pub struct SigningKey(/* private fields */);
Expand description

An ed25519 private key. Used for signing messages.

Implementations§

Source§

impl SigningKey

Source

pub const LEN: usize = 32usize

Source

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

Source

pub fn into_inner(self) -> SigningKey

Source

pub fn random() -> Self

Generates a new random SigningKey.

Source

pub fn random_from_rng<R: CryptoRngCore + ?Sized>(rng: &mut R) -> Self

Generates a new random SigningKey from the given RNG.

Source

pub fn verifying_key(&self) -> VerifyingKey

Gets the public VerifyingKey that corresponds to this private SigningKey.

Source

pub fn sign(&self, message: impl AsRef<[u8]>, context: Context<'_>) -> Signature

Signs message using the ed25519ph algorithm.

§Example
use did_simple::crypto::{Context, ed25519::{SigningKey, VerifyingKey}};

let signing_key = SigningKey::random();
let verifying_key = signing_key.verifying_key();
const CTX: Context = Context::from_bytes("MySuperCoolProtocol".as_bytes());

let msg = "everyone can read and verify this message";
let sig = signing_key.sign(msg, CTX);

assert!(verifying_key.verify(msg, CTX, &sig).is_ok());
Source

pub fn sign_digest( &self, message_digest: Sha512, context: Context<'_>, ) -> Signature

Same as sign, but allows you to populate message_digest separately from signing.

This can be useful if for example, it is undesirable to buffer the message into a single slice, or the message is being streamed asynchronously. You can instead update the digest chunk by chunk, and pass the digest in after you are done reading all the data.

§Example
use did_simple::crypto::{Context, ed25519::{Sha512, Digest, SigningKey, VerifyingKey}};

let signing_key = SigningKey::random();
let verifying_key = signing_key.verifying_key();
const CTX: Context = Context::from_bytes("MySuperCoolProtocol".as_bytes());

let mut digest = Sha512::new();
digest.update("this is ");
digest.update("my message");
let sig = signing_key.sign_digest(digest, CTX);

assert!(verifying_key.verify("this is my message", CTX, &sig).is_ok());

Trait Implementations§

Source§

impl Debug for SigningKey

Source§

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

Formats the value using the given formatter. 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.