1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#![deny(missing_docs, missing_debug_implementations)]
extern crate base64;
extern crate byteorder;
extern crate digest;
extern crate sha1;
extern crate typenum;
#[macro_use] extern crate failure;
#[macro_use] extern crate bitflags;
#[cfg(feature = "dalek")]
extern crate ed25519_dalek as dalek;
mod ascii_armor;
mod packet;
mod key;
mod sig;
pub use key::PgpKey;
pub use sig::{PgpSig, SubPacket, SigType};
pub type Fingerprint = [u8; 20];
pub type Signature = [u8; 64];
bitflags! {
pub struct KeyFlags: u8 {
const NONE = 0x00;
const CERTIFY = 0x01;
const SIGN = 0x02;
const ENCRYPT_COMS = 0x04;
const ENCRYPT_STORAGE = 0x08;
const AUTHENTICATION = 0x20;
}
}
#[derive(Fail, Debug)]
pub enum PgpError {
#[fail(display = "Invalid ASCII armor format")]
InvalidAsciiArmor,
#[fail(display = "Packet header incorrectly formatted")]
InvalidPacketHeader,
#[fail(display = "Unsupported packet length format")]
UnsupportedPacketLength,
#[fail(display = "Unsupported form of signature packet")]
UnsupportedSignaturePacket,
#[fail(display = "First hashed subpacket of signature must be the key fingerprint")]
MissingFingerprintSubpacket,
#[fail(display = "Unsupported form of public key packet")]
UnsupportedPublicKeyPacket,
}
struct Base64<'a>(&'a [u8]);
impl<'a> std::fmt::Debug for Base64<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(&base64::encode(self.0))
}
}