diff options
author | Stephen Paul Weber <singpolyma@singpolyma.net> | 2011-08-08 20:29:31 -0500 |
---|---|---|
committer | Stephen Paul Weber <singpolyma@singpolyma.net> | 2011-08-08 20:29:31 -0500 |
commit | b33e4888364a0819b7e6d7f39c892f8af229b859 (patch) | |
tree | 26a323cf8ef0169a75ef80d5ecf448a9d10eebd7 | |
parent | 01cd974321f171148e923517121c14154b8d8469 (diff) |
put for SignaturePacket, OnePassSignaturePacket, CompressedDataPacket
-rw-r--r-- | lib/OpenPGP.hs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/OpenPGP.hs b/lib/OpenPGP.hs index 99e536e..1c8d2d7 100644 --- a/lib/OpenPGP.hs +++ b/lib/OpenPGP.hs | |||
@@ -172,6 +172,41 @@ calculate_signature_trailer p = | |||
172 | ] | 172 | ] |
173 | 173 | ||
174 | put_packet :: (Num a) => Packet -> (LZ.ByteString, a) | 174 | put_packet :: (Num a) => Packet -> (LZ.ByteString, a) |
175 | put_packet (SignaturePacket { version = 4, | ||
176 | signature_type = signature_type, | ||
177 | key_algorithm = key_algorithm, | ||
178 | hash_algorithm = hash_algorithm, | ||
179 | hashed_subpackets = hashed_subpackets, | ||
180 | unhashed_subpackets = unhashed_subpackets, | ||
181 | hash_head = hash_head, | ||
182 | signature = signature }) = | ||
183 | (LZ.concat [ LZ.singleton 4, encode signature_type, | ||
184 | encode key_algorithm, encode hash_algorithm, | ||
185 | encode (fromIntegral $ LZ.length hashed :: Word16), | ||
186 | hashed, | ||
187 | encode (fromIntegral $ LZ.length unhashed :: Word16), | ||
188 | unhashed, | ||
189 | encode hash_head, encode signature ], 2) | ||
190 | where hashed = LZ.concat $ map encode hashed_subpackets | ||
191 | unhashed = LZ.concat $ map encode unhashed_subpackets | ||
192 | put_packet (OnePassSignaturePacket { version = version, | ||
193 | signature_type = signature_type, | ||
194 | hash_algorithm = hash_algorithm, | ||
195 | key_algorithm = key_algorithm, | ||
196 | key_id = key_id, | ||
197 | nested = nested }) = | ||
198 | (LZ.concat [ encode version, encode signature_type, | ||
199 | encode hash_algorithm, encode key_algorithm, | ||
200 | encode (BaseConvert.toNum 16 key_id :: Word64), | ||
201 | encode nested ], 4) | ||
202 | put_packet (CompressedDataPacket { compression_algorithm = algorithm, | ||
203 | message = message }) = | ||
204 | (LZ.append (encode algorithm) $ compress $ encode message, 8) | ||
205 | where compress = case algorithm of | ||
206 | Uncompressed -> id | ||
207 | ZIP -> Zip.compress | ||
208 | ZLIB -> Zlib.compress | ||
209 | BZip2 -> BZip2.compress | ||
175 | put_packet (LiteralDataPacket { format = format, filename = filename, | 210 | put_packet (LiteralDataPacket { format = format, filename = filename, |
176 | timestamp = timestamp, content = content | 211 | timestamp = timestamp, content = content |
177 | }) = | 212 | }) = |