pub struct Mac0Message {
pub protected: Header,
pub unprotected: Header,
pub payload: Option<Vec<u8>>,
/* private fields */
}Expand description
A COSE_Mac0 message.
Reference: https://datatracker.ietf.org/doc/html/rfc9052#name-maced-messages-with-implici.
Fields§
§protected: HeaderProtected header parameters (e.g. alg), authenticated by the tag.
unprotected: HeaderUnprotected header parameters (e.g. kid).
payload: Option<Vec<u8>>The payload, or None when detached.
Implementations§
Source§impl Mac0Message
impl Mac0Message
Sourcepub fn to_be_maced(
protected_raw: &[u8],
external_aad: &[u8],
payload: &[u8],
) -> Result<Vec<u8>, Error>
pub fn to_be_maced( protected_raw: &[u8], external_aad: &[u8], payload: &[u8], ) -> Result<Vec<u8>, Error>
Encodes the MAC_structure to be authenticated (RFC 9052 §6.3).
This is the low-level helper for external or async MAC code. New
messages should usually call prepare_tag or
prepare_detached_tag so the protected
header bytes stored in the message match the bytes being MACed.
Sourcepub fn prepare_tag(
&mut self,
alg: Option<Label>,
kid: Option<&[u8]>,
external_aad: Option<&[u8]>,
) -> Result<Vec<u8>, Error>
pub fn prepare_tag( &mut self, alg: Option<Label>, kid: Option<&[u8]>, external_aad: Option<&[u8]>, ) -> Result<Vec<u8>, Error>
Sourcepub fn prepare_detached_tag(
&mut self,
alg: Option<Label>,
kid: Option<&[u8]>,
detached_payload: &[u8],
external_aad: Option<&[u8]>,
) -> Result<Vec<u8>, Error>
pub fn prepare_detached_tag( &mut self, alg: Option<Label>, kid: Option<&[u8]>, detached_payload: &[u8], external_aad: Option<&[u8]>, ) -> Result<Vec<u8>, Error>
Prepares this detached-payload message for an externally produced tag.
The message’s on-the-wire payload is set to nil; detached_payload is
used only in the MAC_structure.
Sourcepub fn set_tag(&mut self, tag: impl Into<Vec<u8>>) -> Result<(), Error>
pub fn set_tag(&mut self, tag: impl Into<Vec<u8>>) -> Result<(), Error>
Stores externally produced tag bytes on this message.
Sourcepub fn compute(
&mut self,
macer: &dyn Macer,
external_aad: Option<&[u8]>,
) -> Result<(), Error>
pub fn compute( &mut self, macer: &dyn Macer, external_aad: Option<&[u8]>, ) -> Result<(), Error>
Computes the authentication tag with macer.
Sourcepub fn compute_detached(
&mut self,
macer: &dyn Macer,
detached_payload: &[u8],
external_aad: Option<&[u8]>,
) -> Result<(), Error>
pub fn compute_detached( &mut self, macer: &dyn Macer, detached_payload: &[u8], external_aad: Option<&[u8]>, ) -> Result<(), Error>
Computes the authentication tag over a detached payload.
The message’s on-the-wire payload is set to nil; detached_payload
is used only in the MAC_structure.
Sourcepub fn compute_and_encode(
&mut self,
macer: &dyn Macer,
external_aad: Option<&[u8]>,
) -> Result<Vec<u8>, Error>
pub fn compute_and_encode( &mut self, macer: &dyn Macer, external_aad: Option<&[u8]>, ) -> Result<Vec<u8>, Error>
Computes the tag and encodes the message to tagged COSE_Mac0 bytes.
Sourcepub fn compute_detached_and_encode(
&mut self,
macer: &dyn Macer,
detached_payload: &[u8],
external_aad: Option<&[u8]>,
) -> Result<Vec<u8>, Error>
pub fn compute_detached_and_encode( &mut self, macer: &dyn Macer, detached_payload: &[u8], external_aad: Option<&[u8]>, ) -> Result<Vec<u8>, Error>
Computes a detached-payload tag and encodes the message.
Sourcepub fn to_vec(&self) -> Result<Vec<u8>, Error>
pub fn to_vec(&self) -> Result<Vec<u8>, Error>
Encodes a computed message to tagged COSE_Mac0 bytes.
Sourcepub fn to_untagged_vec(&self) -> Result<Vec<u8>, Error>
pub fn to_untagged_vec(&self) -> Result<Vec<u8>, Error>
Encodes a computed message to canonical COSE_Mac0 bytes without the CBOR tag.
Sourcepub fn from_slice(data: &[u8]) -> Result<Self, Error>
pub fn from_slice(data: &[u8]) -> Result<Self, Error>
Decodes a COSE_Mac0 message (tagged or untagged) without verifying it.
Sourcepub fn verify(
&self,
macer: &dyn Macer,
external_aad: Option<&[u8]>,
) -> Result<(), Error>
pub fn verify( &self, macer: &dyn Macer, external_aad: Option<&[u8]>, ) -> Result<(), Error>
Verifies the authentication tag with macer.
Sourcepub fn verify_detached(
&self,
macer: &dyn Macer,
detached_payload: &[u8],
external_aad: Option<&[u8]>,
) -> Result<(), Error>
pub fn verify_detached( &self, macer: &dyn Macer, detached_payload: &[u8], external_aad: Option<&[u8]>, ) -> Result<(), Error>
Verifies the authentication tag over a detached payload.
Sourcepub fn verify_and_decode(
macer: &dyn Macer,
data: &[u8],
external_aad: Option<&[u8]>,
) -> Result<Self, Error>
pub fn verify_and_decode( macer: &dyn Macer, data: &[u8], external_aad: Option<&[u8]>, ) -> Result<Self, Error>
Decodes and verifies a COSE_Mac0 message in one step.
Sourcepub fn verify_detached_and_decode(
macer: &dyn Macer,
data: &[u8],
detached_payload: &[u8],
external_aad: Option<&[u8]>,
) -> Result<Self, Error>
pub fn verify_detached_and_decode( macer: &dyn Macer, data: &[u8], detached_payload: &[u8], external_aad: Option<&[u8]>, ) -> Result<Self, Error>
Decodes and verifies a detached-payload COSE_Mac0 message in one step.
Sourcepub fn protected_raw(&self) -> &[u8] ⓘ
pub fn protected_raw(&self) -> &[u8] ⓘ
Returns the protected-header bytes used in the MAC structure.
Trait Implementations§
Source§impl Clone for Mac0Message
impl Clone for Mac0Message
Source§fn clone(&self) -> Mac0Message
fn clone(&self) -> Mac0Message
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Mac0Message
impl Debug for Mac0Message
Source§impl Default for Mac0Message
impl Default for Mac0Message
Source§fn default() -> Mac0Message
fn default() -> Mac0Message
Source§impl PartialEq for Mac0Message
impl PartialEq for Mac0Message
Source§fn eq(&self, other: &Mac0Message) -> bool
fn eq(&self, other: &Mac0Message) -> bool
self and other values to be equal, and is used by ==.