summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Paul Weber <singpolyma@singpolyma.net>2011-07-30 14:33:10 -0500
committerStephen Paul Weber <singpolyma@singpolyma.net>2011-07-30 14:33:10 -0500
commitdef7972c0e6e2d894380953c2a5114bdbca8febc (patch)
treebd434ff58b0560d6b5376b9d5eeee034a88d11db
parent97c347067be0211a0e02be0c7b2c59921f90a8ee (diff)
get/put for Message
-rw-r--r--lib/openpgp.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/openpgp.hs b/lib/openpgp.hs
index a52d255..2848538 100644
--- a/lib/openpgp.hs
+++ b/lib/openpgp.hs
@@ -6,6 +6,21 @@ import Data.Word
6newtype Message = Message [Packet] deriving Show 6newtype Message = Message [Packet] deriving Show
7data Packet = EmptyPacket | Len Word8 Word32 deriving Show 7data Packet = EmptyPacket | Len Word8 Word32 deriving Show
8 8
9-- A message is encoded as a list that takes the entire file
10instance Binary Message where
11 put (Message []) = return ()
12 put (Message (x:xs)) = do
13 put x
14 put (Message xs)
15 get = do
16 done <- isEmpty
17 if done then do
18 return (Message [])
19 else do
20 next_packet <- get :: Get Packet
21 (Message tail) <- get :: Get Message
22 return (Message (next_packet:tail))
23
9instance Binary Packet where 24instance Binary Packet where
10 get = do 25 get = do
11 tag <- get :: Get Word8 26 tag <- get :: Get Word8