pub struct Header(/* private fields */);Expand description
A COSE Headers / Generic_Headers map (RFC 9052 §3).
The underlying representation is a CoseMap, with header-specific
accessors for common parameters. It dereferences to CoseMap so custom
header parameters can still be inserted with raw labels and values.
Implementations§
Source§impl Header
impl Header
Sourcepub fn from_slice(data: &[u8]) -> Result<Self, Error>
pub fn from_slice(data: &[u8]) -> Result<Self, Error>
Decodes a header map from CBOR bytes.
Sourcepub fn as_mut_map(&mut self) -> &mut CoseMap
pub fn as_mut_map(&mut self) -> &mut CoseMap
Returns a mutable reference to the underlying map.
Sourcepub fn iter(&self) -> Iter<'_, Label, Value>
pub fn iter(&self) -> Iter<'_, Label, Value>
Iterates over the (label, value) entries in label order.
Sourcepub fn alg(&self) -> Result<Option<Label>, Error>
pub fn alg(&self) -> Result<Option<Label>, Error>
Returns the algorithm identifier (alg, label 1), if present.
COSE algorithm identifiers are int / tstr; this crate represents
that shape with Label.
Sourcepub fn set_alg(&mut self, alg: impl Into<Label>) -> &mut Self
pub fn set_alg(&mut self, alg: impl Into<Label>) -> &mut Self
Sets the algorithm identifier (alg, label 1).
Sourcepub fn kid(&self) -> Result<Option<&[u8]>, Error>
pub fn kid(&self) -> Result<Option<&[u8]>, Error>
Returns the key identifier (kid, label 4), if present.
Sourcepub fn set_kid(&mut self, kid: impl Into<Vec<u8>>) -> &mut Self
pub fn set_kid(&mut self, kid: impl Into<Vec<u8>>) -> &mut Self
Sets the key identifier (kid, label 4).
Sourcepub fn content_type(&self) -> Result<Option<Label>, Error>
pub fn content_type(&self) -> Result<Option<Label>, Error>
Returns the content type (content type, label 3), if present.
The value is tstr / uint (RFC 9052 §3.1); this crate represents that
shape with Label.
Sourcepub fn set_content_type(&mut self, content_type: impl Into<Label>) -> &mut Self
pub fn set_content_type(&mut self, content_type: impl Into<Label>) -> &mut Self
Sets the content type (content type, label 3).
Sourcepub fn iv(&self) -> Result<Option<&[u8]>, Error>
pub fn iv(&self) -> Result<Option<&[u8]>, Error>
Returns the full initialization vector (iv, label 5), if present.
Sourcepub fn set_iv(&mut self, iv: impl Into<Vec<u8>>) -> &mut Self
pub fn set_iv(&mut self, iv: impl Into<Vec<u8>>) -> &mut Self
Sets the full initialization vector (iv, label 5).
Sourcepub fn partial_iv(&self) -> Result<Option<&[u8]>, Error>
pub fn partial_iv(&self) -> Result<Option<&[u8]>, Error>
Returns the partial initialization vector (Partial IV, label 6), if present.
Sourcepub fn set_partial_iv(&mut self, partial_iv: impl Into<Vec<u8>>) -> &mut Self
pub fn set_partial_iv(&mut self, partial_iv: impl Into<Vec<u8>>) -> &mut Self
Sets the partial initialization vector (Partial IV, label 6).
Sourcepub fn crit(&self) -> Result<Option<Vec<Label>>, Error>
pub fn crit(&self) -> Result<Option<Vec<Label>>, Error>
Returns the critical protected header labels (crit, label 2), if present.
Sourcepub fn set_crit<I, L>(&mut self, labels: I) -> &mut Self
pub fn set_crit<I, L>(&mut self, labels: I) -> &mut Self
Sets the critical protected header labels (crit, label 2).
Sourcepub fn ensure_crit_understood(&self, understood: &[Label]) -> Result<(), Error>
pub fn ensure_crit_understood(&self, understood: &[Label]) -> Result<(), Error>
Enforces RFC 9052 §3.1 critical-header processing: every label listed in
crit must be understood, otherwise processing the message is a fatal
error.
A label is considered understood when it is one of the common header
parameters this crate models natively (see is_understood_header) or
when the caller lists it in understood. Applications that process
untrusted messages SHOULD call this on the protected header of each
layer (and each COSE_Signature) after decoding, passing the
application-specific labels they are able to process.
Returns Ok(()) when there is no crit parameter or when every listed
label is understood.
Methods from Deref<Target = CoseMap>§
Sourcepub fn contains_key(&self, key: impl Into<Label>) -> bool
pub fn contains_key(&self, key: impl Into<Label>) -> bool
Returns true if the map contains the given label.
Sourcepub fn get(&self, key: impl Into<Label>) -> Option<&Value>
pub fn get(&self, key: impl Into<Label>) -> Option<&Value>
Returns the raw Value for a label, if present.
Sourcepub fn insert(
&mut self,
key: impl Into<Label>,
value: impl Into<Value>,
) -> Option<Value>
pub fn insert( &mut self, key: impl Into<Label>, value: impl Into<Value>, ) -> Option<Value>
Inserts a value, returning the previous value for the label if any.
Sourcepub fn remove(&mut self, key: impl Into<Label>) -> Option<Value>
pub fn remove(&mut self, key: impl Into<Label>) -> Option<Value>
Removes and returns the value for a label, if present.
Sourcepub fn iter(&self) -> Iter<'_, Label, Value>
pub fn iter(&self) -> Iter<'_, Label, Value>
Iterates over the (label, value) entries in label order.
Sourcepub fn get_i64(&self, key: impl Into<Label>) -> Result<Option<i64>, Error>
pub fn get_i64(&self, key: impl Into<Label>) -> Result<Option<i64>, Error>
Returns the value for a label as an i64.
Returns Ok(None) when the label is absent and an
Error::UnexpectedType when the value is not an in-range integer.
Sourcepub fn get_bytes(&self, key: impl Into<Label>) -> Result<Option<&[u8]>, Error>
pub fn get_bytes(&self, key: impl Into<Label>) -> Result<Option<&[u8]>, Error>
Returns the value for a label as a byte string.
Sourcepub fn get_text(&self, key: impl Into<Label>) -> Result<Option<&str>, Error>
pub fn get_text(&self, key: impl Into<Label>) -> Result<Option<&str>, Error>
Returns the value for a label as a text string.
Sourcepub fn get_label(&self, key: impl Into<Label>) -> Result<Option<Label>, Error>
pub fn get_label(&self, key: impl Into<Label>) -> Result<Option<Label>, Error>
Returns the value for a label as an int / tstr COSE identifier.
Sourcepub fn get_bool(&self, key: impl Into<Label>) -> Result<Option<bool>, Error>
pub fn get_bool(&self, key: impl Into<Label>) -> Result<Option<bool>, Error>
Returns the value for a label as a boolean.