use crate::cose_keys::CoseKey;
use minicbor::{Decode, Encode};
use suit_cbor::bstr_wrapper;
#[allow(dead_code)]
pub(crate) const MAX_SUPPORTED_ACCESSTOKEN_LEN: usize = 256;
#[derive(Decode, Encode, Debug)]
#[cbor(map)]
#[non_exhaustive]
pub struct HeaderMap<'a> {
#[n(1)]
pub alg: Option<CoseAlg>,
#[cbor(b(4), with = "minicbor::bytes")]
pub(crate) kid: Option<&'a [u8]>,
#[cbor(b(5), with = "minicbor::bytes")]
pub(crate) iv: Option<&'a [u8]>,
#[b(-1)]
pub(crate) ephemeral_key: Option<CoseKey<'a>>,
}
impl HeaderMap<'_> {
#[allow(unused)]
pub fn updated_with(&self, other: &Self) -> Self {
Self {
alg: self.alg.or(other.alg),
kid: self.kid.or(other.kid),
iv: self.iv.or(other.iv),
ephemeral_key: self
.ephemeral_key
.as_ref()
.copied()
.or(other.ephemeral_key.as_ref().copied()),
}
}
}
#[derive(Decode, Debug, Encode, PartialEq, Copy, Clone)]
#[cbor(index_only)]
#[non_exhaustive]
pub enum CoseAlg {
#[n(-3)]
A128KW,
#[n(-5)]
A256KW,
#[n(-29)]
ECDHESA128KW,
#[n(-9)]
ES256P256,
#[n(-7)]
ES256,
#[n(-19)]
ED25519,
#[n(-46)]
HSSLMS,
#[n(4)]
HMAC25664,
#[n(5)]
HMAC256256,
}
bstr_wrapper!(BstrHeaderMap, HeaderMap<'a>);