use alloc::{sync::Arc, vec::Vec};
use serde::{Deserialize, Serialize};
use crate::{key::Key, Metadata, Status};
use super::Algorithm;
#[derive(Debug, Clone, Serialize, Deserialize, Eq)]
pub struct MacKeyInfo {
pub id: u32,
pub origin: crate::Origin,
pub algorithm: Algorithm,
pub status: Status,
pub metadata: Option<Arc<Metadata>>,
pub external_prefix: Option<Vec<u8>>,
pub header: Vec<u8>,
}
impl PartialEq for MacKeyInfo {
fn eq(&self, other: &Self) -> bool {
self.id == other.id && self.algorithm == other.algorithm
}
}
impl MacKeyInfo {
pub(super) fn new(key: &Key<super::Material>) -> Self {
Self {
id: key.id(),
algorithm: key.algorithm(),
origin: key.origin(),
status: key.status(),
external_prefix: key.material().prefix().map(|p| p.to_vec()),
header: key.header().to_vec(),
metadata: key.metadata(),
}
}
}
impl From<MacKeyInfo> for u32 {
fn from(value: MacKeyInfo) -> Self {
value.id
}
}
impl From<&MacKeyInfo> for u32 {
fn from(value: &MacKeyInfo) -> Self {
value.id
}
}
impl From<&Key<super::Material>> for MacKeyInfo {
fn from(key: &Key<super::Material>) -> Self {
Self::new(key)
}
}