diff options
author | Stephen Paul Weber <singpolyma@singpolyma.net> | 2011-08-07 16:43:42 -0500 |
---|---|---|
committer | Stephen Paul Weber <singpolyma@singpolyma.net> | 2011-08-07 16:43:42 -0500 |
commit | f7929f2ebe0b79ec3d913bccb2f623502e687934 (patch) | |
tree | f17c1b31f40aa46bd3c616da8324164932725f48 | |
parent | 1aead960f5a536884342a5ae49851ec997eb453f (diff) |
Code to generate trailer for SignaturePacket
-rw-r--r-- | lib/OpenPGP.hs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/OpenPGP.hs b/lib/OpenPGP.hs index aeadc47..7a1508e 100644 --- a/lib/OpenPGP.hs +++ b/lib/OpenPGP.hs | |||
@@ -127,6 +127,35 @@ secret_key_fields RSA_S = secret_key_fields RSA | |||
127 | secret_key_fields ELGAMAL = ['x'] | 127 | secret_key_fields ELGAMAL = ['x'] |
128 | secret_key_fields DSA = ['x'] | 128 | secret_key_fields DSA = ['x'] |
129 | 129 | ||
130 | -- Need this seperate for trailer calculation | ||
131 | signature_packet_start :: Packet -> LZ.ByteString | ||
132 | signature_packet_start (SignaturePacket { | ||
133 | version = 4, | ||
134 | signature_type = signature_type, | ||
135 | key_algorithm = key_algorithm, | ||
136 | hash_algorithm = hash_algorithm, | ||
137 | hashed_subpackets = hashed_subpackets | ||
138 | }) = | ||
139 | LZ.concat $ [ | ||
140 | encode (0x04 :: Word8), | ||
141 | encode signature_type, | ||
142 | encode key_algorithm, | ||
143 | encode hash_algorithm, | ||
144 | encode ((fromIntegral $ LZ.length hashed_subs) :: Word16), | ||
145 | hashed_subs | ||
146 | ] | ||
147 | where hashed_subs = LZ.concat $ map encode hashed_subpackets | ||
148 | |||
149 | -- The trailer is just the top of the body plus some crap | ||
150 | calculate_signature_trailer :: Packet -> LZ.ByteString | ||
151 | calculate_signature_trailer p = | ||
152 | LZ.concat [ | ||
153 | signature_packet_start p, | ||
154 | encode (0x04 :: Word8), | ||
155 | encode (0xff :: Word8), | ||
156 | encode ((fromIntegral (LZ.length $ signature_packet_start p)) :: Word32) | ||
157 | ] | ||
158 | |||
130 | parse_packet :: Word8 -> Get Packet | 159 | parse_packet :: Word8 -> Get Packet |
131 | -- SignaturePacket, http://tools.ietf.org/html/rfc4880#section-5.2 | 160 | -- SignaturePacket, http://tools.ietf.org/html/rfc4880#section-5.2 |
132 | parse_packet 2 = do | 161 | parse_packet 2 = do |