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 flagspayload
: The message payload of type Ttrailer
: Optional additional datasignature
: The cryptographic signature
§Type Parameters
T
- The type of the message payloadS
- The type of signature encoding used
Implementations§
Source§impl<S: SignatureEncoding, T: AnyBitPattern + NoUninit> SignedMessage<T, S>
impl<S: SignatureEncoding, T: AnyBitPattern + NoUninit> SignedMessage<T, S>
Sourcepub const HEADER_SIZE: usize = 36usize
pub const HEADER_SIZE: usize = 36usize
Size of the message header in bytes.
Sourcepub fn from_buffer(
buffer: Vec<u8>,
id: &MsgId,
ttl: u32,
flags: u16,
trailer: usize,
) -> Self
pub fn from_buffer( buffer: Vec<u8>, id: &MsgId, ttl: u32, flags: u16, trailer: usize, ) -> Self
Sourcepub fn payload(&mut self) -> (&mut T, &mut [u8])
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
Sourcepub fn build<F, K: Signer<S>>(
id: &MsgId,
ttl: u32,
trailer: usize,
signing_key: &K,
f: F,
) -> Vec<u8> ⓘ
pub fn build<F, K: Signer<S>>( id: &MsgId, ttl: u32, trailer: usize, signing_key: &K, f: F, ) -> Vec<u8> ⓘ
Builds and signs a message using a closure to set the payload.
§Arguments
id
- Message identifierttl
- Time-to-live valuetrailer
- Size of trailer data in bytessigning_key
- The key used to sign the messagef
- Closure that sets the payload and trailer content
§Returns
The signed message as a byte vector
Sourcepub fn verify_with_trailer<'msg, V: Verifier<S>>(
buffer: &'msg [u8],
trailer: usize,
verify_key: &V,
) -> Option<(&'msg T, &'msg [u8])>
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 buffertrailer
- Size of trailer data in bytesverify_key
- The key used to verify the signature
§Returns
A tuple containing references to the payload and trailer,
or None
if verification fails
Source§impl<S: SignatureEncoding> SignedMessage<(), S>
impl<S: SignatureEncoding> SignedMessage<(), S>
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>
impl<T, S> UnwindSafe for SignedMessage<T, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more