summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Paul Weber <singpolyma@singpolyma.net>2011-07-30 16:23:03 -0500
committerStephen Paul Weber <singpolyma@singpolyma.net>2011-07-30 16:23:03 -0500
commit47b73e202e8cbfa5632fbe7c4c5b99e9ad85ccad (patch)
treea0b97f5fe6a7e025b6420621e6c119c4c47790e2
parentfff6631bbe878540c19110bbc9b00e89f0cf3588 (diff)
OnePassSignaturePacket parsing
-rw-r--r--lib/openpgp.hs53
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
8import qualified Codec.Compression.Zlib as Zlib 8import qualified Codec.Compression.Zlib as Zlib
9import qualified Codec.Compression.BZip as BZip2 9import qualified Codec.Compression.BZip as BZip2
10 10
11newtype Message = Message [Packet] deriving Show 11import qualified BaseConvert as BaseConvert
12
13newtype Message = Message [Packet] deriving (Show, Read, Eq)
12 14
13data Packet = 15data 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
37data HashAlgorithm = MD5 | SHA1 | RIPEMD160 | SHA256 | SHA384 | SHA512 | SHA224 deriving (Show, Read, Eq)
38data KeyAlgorithm = RSA | ELGAMAL | DSA | ECC | ECDSA | DH deriving (Show, Read, Eq)
39data CompressionAlgorithm = Uncompressed | ZIP | ZLIB | BZip2 deriving (Show, Read, Eq)
26 40
27data CompressionAlgorithm = Uncompressed | ZIP | ZLIB | BZip2 deriving Show 41hash_algorithms :: (Num a) => a -> HashAlgorithm
42hash_algorithms 1 = MD5
43hash_algorithms 2 = SHA1
44hash_algorithms 3 = RIPEMD160
45hash_algorithms 8 = SHA256
46hash_algorithms 9 = SHA384
47hash_algorithms 10 = SHA512
48hash_algorithms 11 = SHA224
49
50key_algorithms :: (Num a) => a -> KeyAlgorithm
51key_algorithms 1 = RSA
52key_algorithms 2 = RSA
53key_algorithms 3 = RSA
54key_algorithms 16 = ELGAMAL
55key_algorithms 17 = DSA
56key_algorithms 18 = ECC
57key_algorithms 19 = ECDSA
58key_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
30instance Binary Message where 61instance Binary Message where
@@ -94,6 +125,22 @@ parse_old_length tag =
94 return (fromIntegral len) 125 return (fromIntegral len)
95 126
96parse_packet :: Word8 -> Get Packet 127parse_packet :: Word8 -> Get Packet
128-- OnePassSignaturePacket, http://tools.ietf.org/html/rfc4880#section-5.4
129parse_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
98parse_packet 8 = do 145parse_packet 8 = do
99 algorithm <- get :: Get Word8 146 algorithm <- get :: Get Word8