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
impl VerifyingKey
pub const LEN: usize = 32usize
Sourcepub fn try_from_bytes(bytes: &[u8; 32]) -> Result<Self, TryFromBytesError>
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).
pub fn into_inner(self) -> VerifyingKey
Sourcepub fn verify(
&self,
message: impl AsRef<[u8]>,
context: Context<'_>,
signature: &Signature,
) -> Result<(), SignatureError>
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());Sourcepub fn verify_digest(
&self,
message_digest: Sha512,
context: Context<'_>,
signature: &Signature,
) -> Result<(), SignatureError>
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());