summaryrefslogtreecommitdiffstats
path: root/src/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@pep-project.org>2017-12-07 14:42:41 +0100
committerJustus Winter <justus@pep-project.org>2017-12-07 18:53:18 +0100
commit9826b979eeeaf385d5bbf5f3a5b877c698273709 (patch)
treeea0676e3d8a50f4219e8c0ff07fe5bbfefd6ae7c /src/openpgp
parent4eddd4d175860139fa3f477ca8c426e92ffa7b50 (diff)
Add types for working with OpenPGP.
- Add KeyId to identify keys.
Diffstat (limited to 'src/openpgp')
-rw-r--r--src/openpgp/mod.rs1
-rw-r--r--src/openpgp/types.rs21
2 files changed, 22 insertions, 0 deletions
diff --git a/src/openpgp/mod.rs b/src/openpgp/mod.rs
index d0175ea5..683b8448 100644
--- a/src/openpgp/mod.rs
+++ b/src/openpgp/mod.rs
@@ -4,5 +4,6 @@
// wrong place). Hence, that here as well.
pub mod parse;
+pub mod types;
include!("openpgp.rs");
diff --git a/src/openpgp/types.rs b/src/openpgp/types.rs
new file mode 100644
index 00000000..5ad32631
--- /dev/null
+++ b/src/openpgp/types.rs
@@ -0,0 +1,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)
+ }
+}