1use data_encoding::{BASE64_MIME, BASE64_NOPAD};
2use sha2::{Digest, Sha256};
3
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5pub struct PublicKey {
6 #[serde(default, skip_serializing_if = "Option::is_none")]
7 pub expires: Option<jiff::Timestamp>,
8 pub key: String,
9}
10
11impl PublicKey {
12 pub fn fingerprint(&self) -> String {
14 let wire = BASE64_MIME.decode(self.key.as_bytes()).unwrap_or_default();
15 format!("SHA256:{}", BASE64_NOPAD.encode(&Sha256::digest(&wire)))
16 }
17}
18
19pub struct SKey {
21 pub public_key: PublicKey,
22}
23
24impl SKey {
25 pub fn new(public_key: PublicKey) -> Self {
26 SKey { public_key }
27 }
28}
29
30#[derive(Debug, Serialize, Deserialize)]
32pub struct Signature {
33 pub version: u64,
34 pub key: PublicKey,
35 pub signature: String,
37 pub date: jiff::Timestamp,
38}