prs_lib/crypto/proto/
gpg.rs

1//! Crypto GPG protocol.
2
3/// Represents a GPG key.
4#[derive(Clone)]
5pub struct Key {
6    /// Full fingerprint.
7    pub fingerprint: String,
8
9    /// Displayable user ID strings.
10    pub user_ids: Vec<String>,
11}
12
13impl Key {
14    /// Key fingerprint.
15    pub fn fingerprint(&self, short: bool) -> String {
16        if short {
17            &self.fingerprint[self.fingerprint.len() - 16..]
18        } else {
19            &self.fingerprint
20        }
21        .trim()
22        .to_uppercase()
23    }
24
25    /// Key displayable user data.
26    pub fn display_user(&self) -> String {
27        self.user_ids.join("; ")
28    }
29
30    /// Transform into generic key.
31    pub fn into_key(self) -> crate::crypto::Key {
32        crate::crypto::Key::Gpg(self)
33    }
34}
35
36impl PartialEq for Key {
37    fn eq(&self, other: &Self) -> bool {
38        self.fingerprint.trim().to_uppercase() == other.fingerprint.trim().to_uppercase()
39    }
40}