navajo 0.0.4

cryptographic APIs
Documentation

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>,
    /// The prefix provided during creation of an external key, if any.
    pub external_prefix: Option<Vec<u8>>,
    /// The header is prepended to all [`Tag`]s generated with this key unless
    /// [`Tag::omit_header`] was invoked.
    ///
    /// - For external keys, this will be the prefix if supplied.
    /// - For keys generated by Navajo, this will be a version byte and the key ID.
    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>;