Skip to main content

Signature

Struct Signature 

Source
pub struct Signature<P: ParameterSet> { /* private fields */ }
Expand description

Represents a signature using the specified parameter set.

§Usage

use parameter_sets::ML_DSA_44 as P;

let msg: &[u8] = b"Hello, world!";

let signature = sk.sign(msg);

// There are different ways to obtain a byte representation of the
// signature.
let signature_encoding = signature.to_bytes();
let encoded_signature_via_SignatureEncoding: &[u8] = &signature_encoding;
let encoded_signature_via_AsBytes = signature.as_bytes();
assert_eq!(encoded_signature_via_SignatureEncoding, encoded_signature_via_AsBytes);

let encoded_signature = encoded_signature_via_AsBytes;

let recv_sig: Signature<P> = encoded_signature.try_into()
    .expect("Failed to parse the received signature");
assert_eq!(recv_sig, signature);

// Equivalently, using the FromBytes trait
let decoded_signature = Signature::<P>::from_bytes(encoded_signature)
    .expect("Failed to decode the received signature");
assert_eq!(decoded_signature, signature);

If the crate is built without the rand feature, then the sign method (which takes only the msg as an argument) will not be available. In that case, you must generate your own random bytes and use the signing methods provided by the SeededSigner trait.

Trait Implementations§

Source§

impl<P: ParameterSet> AsRef<[u8]> for Signature<P>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<P: Clone + ParameterSet> Clone for Signature<P>

Source§

fn clone(&self) -> Signature<P>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<P: ParameterSet> ContextSigner<Signature<P>> for SigningKey<P>

Available on crate feature rand only.
Source§

fn try_sign_with_ctx( &self, msg: &[u8], ctx: &[u8], ) -> Result<Signature<P>, Error>

Attempt to sign the given message, returning a digital signature on success, or an error if something went wrong. Read more
Source§

fn sign_with_context(&self, msg: &[u8], ctx: &[u8]) -> S

Sign the given message and return a digital signature
Source§

impl<P: Debug + ParameterSet> Debug for Signature<P>

Source§

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

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

impl<P: Eq + ParameterSet> Eq for Signature<P>

Source§

impl<P: ParameterSet> From<Signature<P>> for GenericArray<u8, <P as SignatureLen>::LEN>

Source§

fn from(sig: Signature<P>) -> Self

Converts to this type from the input type.
Source§

impl<P: PartialEq + ParameterSet> PartialEq for Signature<P>

Source§

fn eq(&self, other: &Signature<P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<P: ParameterSet> SeededContextSigner<Signature<P>> for SigningKey<P>

Source§

fn try_sign_with_ctx_and_seed( &self, seed: &[u8], msg: &[u8], ctx: &[u8], ) -> Result<Signature<P>, Error>

Attempt to sign the given message, returning a digital signature on success, or an error if something went wrong. Read more
Source§

fn sign_with_context_and_seed(&self, seed: &[u8], msg: &[u8], ctx: &[u8]) -> S

Sign the given message and return a digital signature
Source§

impl<P: ParameterSet> SeededSigner<Signature<P>> for SigningKey<P>

Source§

fn try_sign_with_seed( &self, seed: &[u8], msg: &[u8], ) -> Result<Signature<P>, Error>

Attempt to sign the given message, returning a digital signature on success, or an error if something went wrong. Read more
Source§

fn sign_with_seed(&self, seed: &[u8], msg: &[u8]) -> S

Sign the given message and return a digital signature
Source§

impl<P: ParameterSet> SignatureEncoding for Signature<P>

Source§

type Repr = GenericArray<u8, <P as SignatureLen>::LEN>

Byte representation of a signature.
Source§

fn to_bytes(&self) -> Self::Repr

Encode signature as its byte representation.
Source§

fn encoded_len(&self) -> usize

Get the length of this signature when encoded.
Source§

impl<P: ParameterSet> Signer<Signature<P>> for SigningKey<P>

Available on crate feature rand only.
Source§

fn try_sign(&self, msg: &[u8]) -> Result<Signature<P>, Error>

Attempt to sign the given message, returning a digital signature on success, or an error if something went wrong. Read more
Source§

fn sign(&self, msg: &[u8]) -> S

Sign the given message and return a digital signature.
Source§

impl<P: PartialEq + ParameterSet> StructuralPartialEq for Signature<P>

Source§

impl<P: ParameterSet> TryFrom<&[u8]> for Signature<P>

Source§

type Error = Error

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

fn try_from(bytes: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<P: ParameterSet> Verifier<Signature<P>> for VerifyingKey<P>

Source§

fn verify(&self, msg: &[u8], signature: &Signature<P>) -> Result<(), Error>

Use Self (e.g. a verifying key) to verify that the provided signature is authentic for a given message bytestring. Read more

Auto Trait Implementations§

§

impl<P> Freeze for Signature<P>

§

impl<P> RefUnwindSafe for Signature<P>

§

impl<P> Send for Signature<P>

§

impl<P> Sync for Signature<P>

§

impl<P> Unpin for Signature<P>
where <<P as SignatureLen>::LEN as ArrayLength>::ArrayType<u8>: Unpin,

§

impl<P> UnsafeUnpin for Signature<P>

§

impl<P> UnwindSafe for Signature<P>

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> AsBytes for T
where T: AsRef<[u8]>,

Source§

fn as_bytes(&self) -> &[u8]

Returns a reference to the underlying byte slice.
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, E> FromBytes for T
where T: for<'a> TryFrom<&'a [u8], Error = E>,

Source§

type Error = E

The error type returned when parsing from bytes fails.
Source§

fn from_bytes(input: &[u8]) -> Result<T, <T as FromBytes>::Error>

Try to build an instance of this object from a byte slice. Read more
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> ToOwned for T
where T: Clone,

Source§

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

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.