use data_encoding::{BASE64_MIME, BASE64_NOPAD};
use sha2::{Digest, Sha256};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct PublicKey {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub expires: Option<jiff::Timestamp>,
pub key: String,
}
impl PublicKey {
pub fn fingerprint(&self) -> String {
let wire = BASE64_MIME.decode(self.key.as_bytes()).unwrap_or_default();
format!("SHA256:{}", BASE64_NOPAD.encode(&Sha256::digest(&wire)))
}
}
pub struct SKey {
pub public_key: PublicKey,
}
impl SKey {
pub fn new(public_key: PublicKey) -> Self {
SKey { public_key }
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Signature {
pub version: u64,
pub key: PublicKey,
pub signature: String,
pub date: jiff::Timestamp,
}