VerifyingKey

Struct VerifyingKey 

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

An ed25519 public key. Used for verifying messages.

We recommend deserializing bytes into this type using Self::try_from_bytes(). Then you can either use this type, which has simpler function signatures, or you can call Self::into_inner() and use the lower level ed25519_dalek crate directly, which is slightly less opinionated and has more customization of options made available.

Implementations§

Source§

impl VerifyingKey

Source

pub const LEN: usize = 32usize

Source

pub fn try_from_bytes(bytes: &[u8; 32]) -> Result<Self, TryFromBytesError>

Instantiates PubKey from some bytes. Performs all necessary validation that the key is valid and of sufficient strength.

Note that we will reject any keys that are too weak (aka low order).

Source

pub fn into_inner(self) -> VerifyingKey

Source

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

Verifies 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 verify_digest( &self, message_digest: Sha512, context: Context<'_>, signature: &Signature, ) -> Result<(), SignatureError>

Same as verify, 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 sig = signing_key.sign("this is my message", CTX);

let mut digest = Sha512::new();
digest.update("this is ");
digest.update("my message");
assert!(verifying_key.verify_digest(digest, CTX, &sig).is_ok());

Trait Implementations§

Source§

impl Debug for VerifyingKey

Source§

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

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

impl Hash for VerifyingKey

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for VerifyingKey

Source§

fn eq(&self, other: &VerifyingKey) -> 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 TryFrom<VerifyingKey> for VerifyingKey

Source§

type Error = TryFromBytesError

The type returned in the event of a conversion error.
Source§

fn try_from(value: VerifyingKey) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for VerifyingKey

Source§

impl StructuralPartialEq for VerifyingKey

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.