Struct ed25519_dalek::Context

source ·
pub struct Context<'k, 'v, K> { /* private fields */ }
Available on crate feature digest only.
Expand description

Ed25519 contexts as used by Ed25519ph.

Contexts are domain separator strings that can be used to isolate uses of the algorithm between different protocols (which is very hard to reliably do otherwise) and between different uses within the same protocol.

To create a context, call either of the following:

For more information, see RFC8032 § 8.3.

§Example

use ed25519_dalek::{Signature, SigningKey, VerifyingKey, Sha512};
use ed25519_dalek::{DigestSigner, DigestVerifier};

let context_str = b"Local Channel 3";
let prehashed_message = Sha512::default().chain_update(b"Stay tuned for more news at 7");

// Signer
let signing_context = signing_key.with_context(context_str).unwrap();
let signature = signing_context.sign_digest(prehashed_message.clone());

// Verifier
let verifying_context = verifying_key.with_context(context_str).unwrap();
let verified: bool = verifying_context
    .verify_digest(prehashed_message, &signature)
    .is_ok();

Implementations§

source§

impl<'k, 'v, K> Context<'k, 'v, K>

source

pub const MAX_LENGTH: usize = 255usize

Maximum length of the context value in octets.

source

pub fn key(&self) -> &'k K

Borrow the key.

source

pub fn value(&self) -> &'v [u8]

Borrow the context string value.

Trait Implementations§

source§

impl<'k, 'v, K: Clone> Clone for Context<'k, 'v, K>

source§

fn clone(&self) -> Context<'k, 'v, K>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'k, 'v, K: Debug> Debug for Context<'k, 'v, K>

source§

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

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

impl<D> DigestSigner<D, Signature> for Context<'_, '_, SigningKey>
where D: Digest<OutputSize = U64>,

Equivalent to SigningKey::sign_prehashed with context set to Some containing self.value().

§Note

The RFC only permits SHA-512 to be used for prehashing. This function technically works, and is probably safe to use, with any secure hash function with 512-bit digests, but anything outside of SHA-512 is NOT specification-compliant. We expose crate::Sha512 for user convenience.

source§

fn try_sign_digest(&self, msg_digest: D) -> Result<Signature, SignatureError>

Attempt to sign the given prehashed message Digest, returning a digital signature on success, or an error if something went wrong.
source§

fn sign_digest(&self, digest: D) -> S

Sign the given prehashed message Digest, returning a signature. Read more
source§

impl<MsgDigest> DigestVerifier<MsgDigest, Signature> for Context<'_, '_, VerifyingKey>
where MsgDigest: Digest<OutputSize = U64>,

Equivalent to VerifyingKey::verify_prehashed with context set to Some containing self.value().

source§

fn verify_digest( &self, msg_digest: MsgDigest, signature: &Signature ) -> Result<(), SignatureError>

Verify the signature against the given Digest output.

Auto Trait Implementations§

§

impl<'k, 'v, K> RefUnwindSafe for Context<'k, 'v, K>
where K: RefUnwindSafe,

§

impl<'k, 'v, K> Send for Context<'k, 'v, K>
where K: Sync,

§

impl<'k, 'v, K> Sync for Context<'k, 'v, K>
where K: Sync,

§

impl<'k, 'v, K> Unpin for Context<'k, 'v, K>

§

impl<'k, 'v, K> UnwindSafe for Context<'k, 'v, K>
where K: RefUnwindSafe,

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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.