Skip to main content

Mac0Message

Struct Mac0Message 

Source
pub struct Mac0Message {
    pub protected: Header,
    pub unprotected: Header,
    pub payload: Option<Vec<u8>>,
    /* private fields */
}
Expand description

Fields§

§protected: Header

Protected header parameters (e.g. alg), authenticated by the tag.

§unprotected: Header

Unprotected header parameters (e.g. kid).

§payload: Option<Vec<u8>>

The payload, or None when detached.

Implementations§

Source§

impl Mac0Message

Source

pub const TAG: u64 = iana::CBORTagCOSEMac0

The on-the-wire CBOR tag for COSE_Mac0.

Source

pub fn new(payload: Option<Vec<u8>>) -> Self

Creates a new message with the given payload.

Source

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.

Source

pub fn prepare_tag( &mut self, alg: Option<Label>, kid: Option<&[u8]>, external_aad: Option<&[u8]>, ) -> Result<Vec<u8>, Error>

Prepares this embedded-payload message for an externally produced tag.

The returned bytes are the MAC_structure that must be MACed. After an async or remote MAC service returns the tag bytes, call set_tag and then to_vec.

Source

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.

Source

pub fn set_tag(&mut self, tag: impl Into<Vec<u8>>) -> Result<(), Error>

Stores externally produced tag bytes on this message.

Source

pub fn compute( &mut self, macer: &dyn Macer, external_aad: Option<&[u8]>, ) -> Result<(), Error>

Computes the authentication tag with macer.

Source

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.

Source

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.

Source

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.

Source

pub fn to_vec(&self) -> Result<Vec<u8>, Error>

Encodes a computed message to tagged COSE_Mac0 bytes.

Source

pub fn to_untagged_vec(&self) -> Result<Vec<u8>, Error>

Encodes a computed message to canonical COSE_Mac0 bytes without the CBOR tag.

Source

pub fn from_slice(data: &[u8]) -> Result<Self, Error>

Decodes a COSE_Mac0 message (tagged or untagged) without verifying it.

Source

pub fn verify( &self, macer: &dyn Macer, external_aad: Option<&[u8]>, ) -> Result<(), Error>

Verifies the authentication tag with macer.

Source

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.

Source

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.

Source

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.

Source

pub fn tag(&self) -> &[u8]

Returns the authentication tag (empty until computed/decoded).

Source

pub fn protected_raw(&self) -> &[u8]

Returns the protected-header bytes used in the MAC structure.

Trait Implementations§

Source§

impl Clone for Mac0Message

Source§

fn clone(&self) -> Mac0Message

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Mac0Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Mac0Message

Source§

fn default() -> Mac0Message

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Mac0Message

Source§

fn eq(&self, other: &Mac0Message) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Mac0Message

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.