summaryrefslogtreecommitdiffstats
path: root/src/openpgp/types.rs
blob: 5ad3263157229785e3464d9a52c8d71091a9f599 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//! Types for working with OpenPGP.

/// Uniquely identifies OpenPGP keys.
pub struct KeyId(u64);

impl KeyId {
    /// Returns a KeyID with the given `id`.
    pub fn new(id: u64) -> KeyId {
        KeyId(id)
    }

    /// Returns a KeyID with the given `id` encoded as hexadecimal string.
    pub fn from_hex(id: &str) -> Option<KeyId> {
        u64::from_str_radix(id, 16).ok().map(|id| Self::new(id))
    }

    /// Returns a hexadecimal representation of the key id.
    pub fn as_hex(&self) -> String {
        format!("{:x}", self.0)
    }
}