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
impl SignedPayload
Sourcepub fn encode(marker: u8, payload: &[u8], identity: &DeviceIdentity) -> Vec<u8> ⓘ
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 identifierpayload- Application data to signidentity- Signer’s identity (holds private key)
§Returns
Wire bytes ready for transmission
Sourcepub fn encode_with_signature(
marker: u8,
payload: &[u8],
signature: &[u8; 64],
) -> Vec<u8> ⓘ
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 identifierpayload- Application datasignature- Pre-computed Ed25519 signature over (marker || payload)
Sourcepub fn decode(wire: &[u8]) -> Option<DecodedPayload<'_>>
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
Sourcepub fn decode_verified<'a>(
wire: &'a [u8],
public_key: &[u8; 32],
) -> Option<DecodedPayload<'a>>
pub fn decode_verified<'a>( wire: &'a [u8], public_key: &[u8; 32], ) -> Option<DecodedPayload<'a>>
Sourcepub const fn payload_size(wire_size: usize) -> usize
pub const fn payload_size(wire_size: usize) -> usize
Get the payload size from total wire size
Useful for pre-allocating buffers.
Sourcepub const fn wire_size(payload_size: usize) -> usize
pub const fn wire_size(payload_size: usize) -> usize
Get the wire size from payload size
Useful for pre-allocating buffers.
Sourcepub fn peek_marker(wire: &[u8]) -> Option<u8>
pub fn peek_marker(wire: &[u8]) -> Option<u8>
Extract the marker byte without full decode
Quick check for message type routing.