diff options
-rw-r--r-- | lib/openpgp.hs | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/lib/openpgp.hs b/lib/openpgp.hs index 9c8548b..d65b66b 100644 --- a/lib/openpgp.hs +++ b/lib/openpgp.hs | |||
@@ -8,9 +8,19 @@ import qualified Codec.Compression.Zlib.Raw as Zip | |||
8 | import qualified Codec.Compression.Zlib as Zlib | 8 | import qualified Codec.Compression.Zlib as Zlib |
9 | import qualified Codec.Compression.BZip as BZip2 | 9 | import qualified Codec.Compression.BZip as BZip2 |
10 | 10 | ||
11 | newtype Message = Message [Packet] deriving Show | 11 | import qualified BaseConvert as BaseConvert |
12 | |||
13 | newtype Message = Message [Packet] deriving (Show, Read, Eq) | ||
12 | 14 | ||
13 | data Packet = | 15 | data Packet = |
16 | OnePassSignaturePacket { | ||
17 | version::Word8, | ||
18 | signature_type::Word8, | ||
19 | hash_algorithm::HashAlgorithm, | ||
20 | key_algorithm::KeyAlgorithm, | ||
21 | key_id::String, | ||
22 | nested::Word8 | ||
23 | } | | ||
14 | CompressedDataPacket { | 24 | CompressedDataPacket { |
15 | algorithm::CompressionAlgorithm, | 25 | algorithm::CompressionAlgorithm, |
16 | message::Message | 26 | message::Message |
@@ -22,9 +32,30 @@ data Packet = | |||
22 | content::LZ.ByteString | 32 | content::LZ.ByteString |
23 | } | | 33 | } | |
24 | UserIDPacket String | 34 | UserIDPacket String |
25 | deriving Show | 35 | deriving (Show, Read, Eq) |
36 | |||
37 | data HashAlgorithm = MD5 | SHA1 | RIPEMD160 | SHA256 | SHA384 | SHA512 | SHA224 deriving (Show, Read, Eq) | ||
38 | data KeyAlgorithm = RSA | ELGAMAL | DSA | ECC | ECDSA | DH deriving (Show, Read, Eq) | ||
39 | data CompressionAlgorithm = Uncompressed | ZIP | ZLIB | BZip2 deriving (Show, Read, Eq) | ||
26 | 40 | ||
27 | data CompressionAlgorithm = Uncompressed | ZIP | ZLIB | BZip2 deriving Show | 41 | hash_algorithms :: (Num a) => a -> HashAlgorithm |
42 | hash_algorithms 1 = MD5 | ||
43 | hash_algorithms 2 = SHA1 | ||
44 | hash_algorithms 3 = RIPEMD160 | ||
45 | hash_algorithms 8 = SHA256 | ||
46 | hash_algorithms 9 = SHA384 | ||
47 | hash_algorithms 10 = SHA512 | ||
48 | hash_algorithms 11 = SHA224 | ||
49 | |||
50 | key_algorithms :: (Num a) => a -> KeyAlgorithm | ||
51 | key_algorithms 1 = RSA | ||
52 | key_algorithms 2 = RSA | ||
53 | key_algorithms 3 = RSA | ||
54 | key_algorithms 16 = ELGAMAL | ||
55 | key_algorithms 17 = DSA | ||
56 | key_algorithms 18 = ECC | ||
57 | key_algorithms 19 = ECDSA | ||
58 | key_algorithms 21 = DH | ||
28 | 59 | ||
29 | -- A message is encoded as a list that takes the entire file | 60 | -- A message is encoded as a list that takes the entire file |
30 | instance Binary Message where | 61 | instance Binary Message where |
@@ -94,6 +125,22 @@ parse_old_length tag = | |||
94 | return (fromIntegral len) | 125 | return (fromIntegral len) |
95 | 126 | ||
96 | parse_packet :: Word8 -> Get Packet | 127 | parse_packet :: Word8 -> Get Packet |
128 | -- OnePassSignaturePacket, http://tools.ietf.org/html/rfc4880#section-5.4 | ||
129 | parse_packet 4 = do | ||
130 | version <- get | ||
131 | signature_type <- get | ||
132 | hash_algo <- get :: Get Word8 | ||
133 | key_algo <- get :: Get Word8 | ||
134 | key_id <- get :: Get Word64 | ||
135 | nested <- get | ||
136 | return (OnePassSignaturePacket { | ||
137 | version = version, | ||
138 | signature_type = signature_type, | ||
139 | hash_algorithm = (hash_algorithms hash_algo), | ||
140 | key_algorithm = (key_algorithms key_algo), | ||
141 | key_id = (BaseConvert.toString 16 key_id), | ||
142 | nested = nested | ||
143 | }) | ||
97 | -- CompressedDataPacket, http://tools.ietf.org/html/rfc4880#section-5.6 | 144 | -- CompressedDataPacket, http://tools.ietf.org/html/rfc4880#section-5.6 |
98 | parse_packet 8 = do | 145 | parse_packet 8 = do |
99 | algorithm <- get :: Get Word8 | 146 | algorithm <- get :: Get Word8 |