Struct SignedMessage

Source
pub struct SignedMessage<T, S: SignatureEncoding> { /* private fields */ }
Expand description

A wrapper for a message of type T with support for in-place signing and verifying.

This struct provides functionality for creating and verifying signed messages with the following format:

[ msg-hdr | payload | trailer | signature ]

Where:

  • msg-hdr: Message header containing ID, TTL, and flags
  • payload: The message payload of type T
  • trailer: Optional additional data
  • signature: The cryptographic signature

§Type Parameters

  • T - The type of the message payload
  • S - The type of signature encoding used

Implementations§

Source§

impl<S: SignatureEncoding, T: AnyBitPattern + NoUninit> SignedMessage<T, S>

Source

pub const HEADER_SIZE: usize = 36usize

Size of the message header in bytes.

Source

pub const fn size(trailer: usize) -> usize

Calculates the total size of a signed message.

§Arguments
  • trailer - Size of the trailer data in bytes
§Returns

The total size in bytes needed for the signed message

Source

pub fn new(id: &MsgId, ttl: u32, flags: u16, trailer: usize) -> Self

Creates a new signed message with the specified parameters.

§Arguments
  • id - Message identifier
  • ttl - Time-to-live value
  • flags - Message flags
  • trailer - Size of trailer data in bytes
§Returns

A new SignedMessage instance

Source

pub fn from_buffer( buffer: Vec<u8>, id: &MsgId, ttl: u32, flags: u16, trailer: usize, ) -> Self

Creates a signed message from an existing buffer.

§Arguments
  • buffer - Existing buffer to use
  • id - Message identifier
  • ttl - Time-to-live value
  • flags - Message flags
  • trailer - Size of trailer data in bytes
§Returns

A new SignedMessage instance using the provided buffer

Source

pub fn payload(&mut self) -> (&mut T, &mut [u8])

Returns mutable references to the message payload and trailer.

§Returns

A tuple containing:

  • Mutable reference to the payload object
  • Mutable reference to the trailer bytes
Source

pub fn sign<K: Signer<S>>(self, signing_key: &K) -> Vec<u8>

Signs the message and returns the underlying byte vector.

§Arguments
  • signing_key - The key used to sign the message
§Returns

The signed message as a byte vector

Source

pub fn build<F, K: Signer<S>>( id: &MsgId, ttl: u32, trailer: usize, signing_key: &K, f: F, ) -> Vec<u8>
where F: FnOnce(&mut T, &mut [u8]),

Builds and signs a message using a closure to set the payload.

§Arguments
  • id - Message identifier
  • ttl - Time-to-live value
  • trailer - Size of trailer data in bytes
  • signing_key - The key used to sign the message
  • f - Closure that sets the payload and trailer content
§Returns

The signed message as a byte vector

Source

pub fn verify_with_trailer<'msg, V: Verifier<S>>( buffer: &'msg [u8], trailer: usize, verify_key: &V, ) -> Option<(&'msg T, &'msg [u8])>

Verifies a signed message and returns references to the payload and trailer.

§Arguments
  • buffer - The signed message buffer
  • trailer - Size of trailer data in bytes
  • verify_key - The key used to verify the signature
§Returns

A tuple containing references to the payload and trailer, or None if verification fails

Source

pub fn verify<'msg, V: Verifier<S>>( buffer: &'msg [u8], verify_key: &V, ) -> Option<&'msg T>

Verifies a signed message and returns a reference to the payload.

§Arguments
  • buffer - The signed message buffer
  • verify_key - The key used to verify the signature
§Returns

A reference to the payload, or None if verification fails

Source§

impl<S: SignatureEncoding> SignedMessage<(), S>

Source

pub fn verify_buffer<V: Verifier<S>>( buffer: &[u8], verify_key: &V, ) -> Option<Range<usize>>

Verifies a message in the buffer and returns the range containing the payload.

§Arguments
  • buffer - The signed message buffer
  • verify_key - The key used to verify the signature
§Returns

The range of bytes containing the payload, or None if verification fails

Auto Trait Implementations§

§

impl<T, S> Freeze for SignedMessage<T, S>

§

impl<T, S> RefUnwindSafe for SignedMessage<T, S>

§

impl<T, S> Send for SignedMessage<T, S>
where T: Send,

§

impl<T, S> Sync for SignedMessage<T, S>
where T: Sync,

§

impl<T, S> Unpin for SignedMessage<T, S>
where T: Unpin, <S as SignatureEncoding>::Repr: Unpin,

§

impl<T, S> UnwindSafe for SignedMessage<T, S>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. 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, 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more