Skip to main content

SignedPayload

Struct SignedPayload 

Source
pub struct SignedPayload;
Expand description

Signed payload encoding and verification utilities

Transport-agnostic helpers for creating and verifying signed messages. Used by hive-lite CannedMessage and HIVE protocol messages.

Implementations§

Source§

impl SignedPayload

Source

pub fn encode(marker: u8, payload: &[u8], identity: &DeviceIdentity) -> Vec<u8>

Encode a signed payload

Creates wire format: [marker:1][payload:N][signature:64]

The signature covers marker || payload, binding the message type to the content.

§Arguments
  • marker - Message type identifier
  • payload - Application data to sign
  • identity - Signer’s identity (holds private key)
§Returns

Wire bytes ready for transmission

Source

pub fn encode_with_signature( marker: u8, payload: &[u8], signature: &[u8; 64], ) -> Vec<u8>

Encode with pre-computed signature

Use when the signature is computed externally (e.g., by secure enclave).

§Arguments
  • marker - Message type identifier
  • payload - Application data
  • signature - Pre-computed Ed25519 signature over (marker || payload)
Source

pub fn decode(wire: &[u8]) -> Option<DecodedPayload<'_>>

Decode a signed payload without verification

Extracts marker, payload, and signature from wire format. Does NOT verify the signature - call verify() separately.

§Arguments
  • wire - Wire bytes in format [marker:1][payload:N][signature:64]
§Returns

Some(DecodedPayload) if wire is at least 65 bytes, None otherwise

Source

pub fn verify(wire: &[u8], public_key: &[u8; 32]) -> bool

Verify a signed payload

Checks that the signature is valid for the given public key.

§Arguments
  • wire - Wire bytes in format [marker:1][payload:N][signature:64]
  • public_key - Signer’s Ed25519 public key
§Returns

true if signature is valid, false otherwise

Source

pub fn decode_verified<'a>( wire: &'a [u8], public_key: &[u8; 32], ) -> Option<DecodedPayload<'a>>

Decode and verify in one step

Convenience method that decodes and verifies, returning the decoded payload only if verification succeeds.

§Arguments
  • wire - Wire bytes
  • public_key - Expected signer’s public key
§Returns

Some(DecodedPayload) if valid, None if malformed or signature invalid

Source

pub const fn payload_size(wire_size: usize) -> usize

Get the payload size from total wire size

Useful for pre-allocating buffers.

Source

pub const fn wire_size(payload_size: usize) -> usize

Get the wire size from payload size

Useful for pre-allocating buffers.

Source

pub fn peek_marker(wire: &[u8]) -> Option<u8>

Extract the marker byte without full decode

Quick check for message type routing.

Source

pub fn extract_signature(wire: &[u8]) -> Option<&[u8; 64]>

Extract signature bytes without full verification

Useful for caching or deferred verification.

Auto Trait Implementations§

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

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.