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
impl CoseMac0
Sourcepub fn new(
protected_header: BTreeMap<i64, Value>,
unprotected_header: BTreeMap<i64, Value>,
payload: Vec<u8>,
) -> Self
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 protectedunprotected_header- Parameters that are not cryptographically protectedpayload- 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);Sourcepub fn create_tag(&mut self, key: &[u8]) -> Result<(), Error>
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 createdErr(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");pub fn verify(&self, key: &[u8]) -> Result<(), Error>
pub fn to_cbor(&self) -> Result<Vec<u8>, Error>
pub fn from_cbor(cbor_data: &[u8]) -> Result<Self, Error>
pub fn get_payload(&self) -> &[u8] ⓘ
pub fn get_kid(&self) -> Option<Vec<u8>>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CoseMac0
impl RefUnwindSafe for CoseMac0
impl Send for CoseMac0
impl Sync for CoseMac0
impl Unpin for CoseMac0
impl UnwindSafe for CoseMac0
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more