Struct CoseMac0

Source
pub struct CoseMac0 { /* private fields */ }
Expand description

COSE_Mac0 structure as defined in RFC 8152 Section 6.2.

This structure represents a MAC-protected message with a single recipient. It consists of:

  • Protected header: Cryptographically protected parameters
  • Unprotected header: Parameters not cryptographically protected
  • Payload: The content being protected
  • Tag: The authentication tag

The COSE_Mac0 structure is used to create and verify HMAC-based authentication codes for CAT tokens.

Implementations§

Source§

impl CoseMac0

Source

pub fn new( protected_header: BTreeMap<i64, Value>, unprotected_header: BTreeMap<i64, Value>, payload: Vec<u8>, ) -> Self

Creates a new COSE_Mac0 structure.

§Arguments
  • protected_header - Parameters that are cryptographically protected
  • unprotected_header - Parameters that are not cryptographically protected
  • payload - The content being protected
§Returns

A new COSE_Mac0 structure with an empty tag. The tag must be created using the create_tag method before the structure can be used.

§Examples
let protected_header = BTreeMap::new();
let unprotected_header = BTreeMap::new();
let payload = vec![1, 2, 3];

let cose_mac0 = CoseMac0::new(protected_header, unprotected_header, payload);
Source

pub fn create_tag(&mut self, key: &[u8]) -> Result<(), Error>

Creates an authentication tag for the COSE_Mac0 structure.

This method computes an HMAC-SHA256 tag over the MAC_structure as defined in RFC 8152 Section 6.3. The MAC_structure includes:

  • The context string “MAC0”
  • The protected header
  • The external AAD (empty in this implementation)
  • The payload
§Arguments
  • key - The cryptographic key to use for creating the tag
§Returns
  • Ok(()) - If the tag was successfully created
  • Err(Error) - If an error occurred during tag creation
§Examples
let mut cose_mac0 = CoseMac0::new(protected_header, unprotected_header, payload);
cose_mac0.create_tag(&key).expect("Failed to create tag");
Source

pub fn verify(&self, key: &[u8]) -> Result<(), Error>

Source

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

Source

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

Source

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

Source

pub fn get_kid(&self) -> Option<Vec<u8>>

Trait Implementations§

Source§

impl Debug for CoseMac0

Source§

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

Formats the value using the given formatter. Read more

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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V