use serde::{Deserialize, Serialize};
use crate::{Key, Metadata, Origin, Status};
#[cfg(not(feature="std"))]
use alloc::vec::Vec;
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct KeyInfo {
pub id: u32,
pub status: Status,
pub origin: Origin,
pub algorithm: super::Algorithm,
pub metadata: Option<Metadata>,
pub external_prefix: Option<Vec<u8>>,
pub header: Vec<u8>,
}
impl From<Key<super::Material>> for KeyInfo {
fn from(mut value: Key<super::Material>) -> Self {
Self {
id: value.id(),
algorithm: value.algorithm(),
metadata: value.take_metadata(),
origin: value.origin(),
status: value.status(),
header: value.header(),
external_prefix: value.material().prefix().map(Into::into),
}
}
}
impl From<&Key<super::Material>> for KeyInfo {
fn from(value: &Key<super::Material>) -> Self {
Self {
id: value.id(),
algorithm: value.algorithm(),
metadata: value.metadata().cloned(),
origin: value.origin(),
status: value.status(),
header: value.header(),
external_prefix: value.material().prefix().map(Into::into),
}
}
}
impl From<KeyInfo> for u32 {
fn from(key: KeyInfo) -> Self {
key.id
}
}
impl From<&KeyInfo> for u32 {
fn from(key: &KeyInfo) -> Self {
key.id
}
}
pub type KeyringInfo = crate::KeyringInfo<KeyInfo>;