diff options
author | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-12-29 15:39:48 -0500 |
---|---|---|
committer | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-12-29 15:39:48 -0500 |
commit | 55330cc47562d6b5010fcc4ec25175191788a9e4 (patch) | |
tree | 62592f39c231e58de7bdb33a5bea302df42afd7f /Data | |
parent | 28c581683cb3a04b87b4eee1b46e40e96098b770 (diff) |
More documentation
Diffstat (limited to 'Data')
-rw-r--r-- | Data/OpenPGP.hs | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs index a3b7b62..4d049dd 100644 --- a/Data/OpenPGP.hs +++ b/Data/OpenPGP.hs | |||
@@ -175,6 +175,7 @@ data Packet = | |||
175 | key_algorithm::KeyAlgorithm, | 175 | key_algorithm::KeyAlgorithm, |
176 | encrypted_data::B.ByteString | 176 | encrypted_data::B.ByteString |
177 | } | | 177 | } | |
178 | -- ^ <http://tools.ietf.org/html/rfc4880#section-5.1> | ||
178 | SignaturePacket { | 179 | SignaturePacket { |
179 | version::Word8, | 180 | version::Word8, |
180 | signature_type::Word8, | 181 | signature_type::Word8, |
@@ -186,6 +187,7 @@ data Packet = | |||
186 | signature::[MPI], | 187 | signature::[MPI], |
187 | trailer::B.ByteString | 188 | trailer::B.ByteString |
188 | } | | 189 | } | |
190 | -- ^ <http://tools.ietf.org/html/rfc4880#section-5.2> | ||
189 | OnePassSignaturePacket { | 191 | OnePassSignaturePacket { |
190 | version::Word8, | 192 | version::Word8, |
191 | signature_type::Word8, | 193 | signature_type::Word8, |
@@ -194,6 +196,7 @@ data Packet = | |||
194 | key_id::String, | 196 | key_id::String, |
195 | nested::Word8 | 197 | nested::Word8 |
196 | } | | 198 | } | |
199 | -- ^ <http://tools.ietf.org/html/rfc4880#section-5.4> | ||
197 | PublicKeyPacket { | 200 | PublicKeyPacket { |
198 | version::Word8, | 201 | version::Word8, |
199 | timestamp::Word32, | 202 | timestamp::Word32, |
@@ -202,39 +205,45 @@ data Packet = | |||
202 | is_subkey::Bool, | 205 | is_subkey::Bool, |
203 | v3_days_of_validity::Maybe Word16 | 206 | v3_days_of_validity::Maybe Word16 |
204 | } | | 207 | } | |
208 | -- ^ <http://tools.ietf.org/html/rfc4880#section-5.5.1.1> (also subkey) | ||
205 | SecretKeyPacket { | 209 | SecretKeyPacket { |
206 | version::Word8, | 210 | version::Word8, |
207 | timestamp::Word32, | 211 | timestamp::Word32, |
208 | key_algorithm::KeyAlgorithm, | 212 | key_algorithm::KeyAlgorithm, |
209 | key::[(Char,MPI)], | 213 | key::[(Char,MPI)], |
210 | s2k_useage::Word8, -- determines if the Maybes are Just or Nothing | 214 | s2k_useage::Word8, -- ^ determines if the 'Maybe's are 'Just' or 'Nothing' |
211 | symmetric_type::Maybe Word8, | 215 | symmetric_type::Maybe Word8, |
212 | s2k_type::Maybe Word8, | 216 | s2k_type::Maybe Word8, |
213 | s2k_hash_algorithm::Maybe HashAlgorithm, | 217 | s2k_hash_algorithm::Maybe HashAlgorithm, |
214 | s2k_salt::Maybe Word64, | 218 | s2k_salt::Maybe Word64, |
215 | s2k_count::Maybe Word32, | 219 | s2k_count::Maybe Word32, |
216 | encrypted_data::B.ByteString, | 220 | encrypted_data::B.ByteString, |
217 | private_hash::Maybe B.ByteString, -- the hash may be in the encrypted data | 221 | private_hash::Maybe B.ByteString, -- ^ the hash may be in the encrypted data |
218 | is_subkey::Bool | 222 | is_subkey::Bool |
219 | } | | 223 | } | |
224 | -- ^ <http://tools.ietf.org/html/rfc4880#section-5.5.1.3> (also subkey) | ||
220 | CompressedDataPacket { | 225 | CompressedDataPacket { |
221 | compression_algorithm::CompressionAlgorithm, | 226 | compression_algorithm::CompressionAlgorithm, |
222 | message::Message | 227 | message::Message |
223 | } | | 228 | } | |
224 | MarkerPacket | | 229 | -- ^ <http://tools.ietf.org/html/rfc4880#section-5.6> |
230 | MarkerPacket | -- ^ <http://tools.ietf.org/html/rfc4880#section-5.8> | ||
225 | LiteralDataPacket { | 231 | LiteralDataPacket { |
226 | format::Char, | 232 | format::Char, |
227 | filename::String, | 233 | filename::String, |
228 | timestamp::Word32, | 234 | timestamp::Word32, |
229 | content::B.ByteString | 235 | content::B.ByteString |
230 | } | | 236 | } | |
231 | TrustPacket B.ByteString | | 237 | -- ^ <http://tools.ietf.org/html/rfc4880#section-5.9> |
232 | UserIDPacket String | | 238 | TrustPacket B.ByteString | -- ^ <http://tools.ietf.org/html/rfc4880#section-5.10> |
239 | UserIDPacket String | -- ^ <http://tools.ietf.org/html/rfc4880#section-5.11> | ||
233 | EncryptedDataPacket { | 240 | EncryptedDataPacket { |
234 | version::Word8, -- 0 for old-skool no-MDC (tag 9) | 241 | version::Word8, |
235 | encrypted_data::B.ByteString | 242 | encrypted_data::B.ByteString |
236 | } | | 243 | } | |
237 | ModificationDetectionCodePacket B.ByteString | | 244 | -- ^ <http://tools.ietf.org/html/rfc4880#section-5.13> |
245 | -- or <http://tools.ietf.org/html/rfc4880#section-5.7> when version is 0 | ||
246 | ModificationDetectionCodePacket B.ByteString | -- ^ <http://tools.ietf.org/html/rfc4880#section-5.14> | ||
238 | UnsupportedPacket Word8 B.ByteString | 247 | UnsupportedPacket Word8 B.ByteString |
239 | deriving (Show, Read, Eq) | 248 | deriving (Show, Read, Eq) |
240 | 249 | ||
@@ -830,7 +839,7 @@ instance BINARY_CLASS RevocationCode where | |||
830 | put = put . enum_to_word8 | 839 | put = put . enum_to_word8 |
831 | get = fmap enum_from_word8 get | 840 | get = fmap enum_from_word8 get |
832 | 841 | ||
833 | -- A message is encoded as a list that takes the entire file | 842 | -- | A message is encoded as a list that takes the entire file |
834 | newtype Message = Message [Packet] deriving (Show, Read, Eq) | 843 | newtype Message = Message [Packet] deriving (Show, Read, Eq) |
835 | instance BINARY_CLASS Message where | 844 | instance BINARY_CLASS Message where |
836 | put (Message xs) = mapM_ put xs | 845 | put (Message xs) = mapM_ put xs |
@@ -846,6 +855,7 @@ signatures_and_data (Message lst) = | |||
846 | isDta (LiteralDataPacket {}) = True | 855 | isDta (LiteralDataPacket {}) = True |
847 | isDta _ = False | 856 | isDta _ = False |
848 | 857 | ||
858 | -- | <http://tools.ietf.org/html/rfc4880#section-3.2> | ||
849 | newtype MPI = MPI Integer deriving (Show, Read, Eq, Ord) | 859 | newtype MPI = MPI Integer deriving (Show, Read, Eq, Ord) |
850 | instance BINARY_CLASS MPI where | 860 | instance BINARY_CLASS MPI where |
851 | put (MPI i) | 861 | put (MPI i) |
@@ -879,15 +889,15 @@ listUntilEnd = do | |||
879 | rest <- listUntilEnd | 889 | rest <- listUntilEnd |
880 | return (next:rest) | 890 | return (next:rest) |
881 | 891 | ||
882 | -- http://tools.ietf.org/html/rfc4880#section-5.2.3.1 | 892 | -- | <http://tools.ietf.org/html/rfc4880#section-5.2.3.1> |
883 | data SignatureSubpacket = | 893 | data SignatureSubpacket = |
884 | SignatureCreationTimePacket Word32 | | 894 | SignatureCreationTimePacket Word32 | |
885 | SignatureExpirationTimePacket Word32 | -- seconds after CreationTime | 895 | SignatureExpirationTimePacket Word32 | -- ^ seconds after CreationTime |
886 | ExportableCertificationPacket Bool | | 896 | ExportableCertificationPacket Bool | |
887 | TrustSignaturePacket {depth::Word8, trust::Word8} | | 897 | TrustSignaturePacket {depth::Word8, trust::Word8} | |
888 | RegularExpressionPacket String | | 898 | RegularExpressionPacket String | |
889 | RevocablePacket Bool | | 899 | RevocablePacket Bool | |
890 | KeyExpirationTimePacket Word32 | -- seconds after key CreationTime | 900 | KeyExpirationTimePacket Word32 | -- ^ seconds after key CreationTime |
891 | PreferredSymmetricAlgorithmsPacket [SymmetricAlgorithm] | | 901 | PreferredSymmetricAlgorithmsPacket [SymmetricAlgorithm] | |
892 | RevocationKeyPacket { | 902 | RevocationKeyPacket { |
893 | sensitive::Bool, | 903 | sensitive::Bool, |
@@ -1160,7 +1170,12 @@ signature_issuer (SignaturePacket {hashed_subpackets = hashed, | |||
1160 | isIssuer _ = False | 1170 | isIssuer _ = False |
1161 | signature_issuer _ = Nothing | 1171 | signature_issuer _ = Nothing |
1162 | 1172 | ||
1163 | find_key :: (Packet -> String) -> Message -> String -> Maybe Packet | 1173 | -- | Find a key with the given Fingerprint/KeyID |
1174 | find_key :: | ||
1175 | (Packet -> String) -- ^ Extract Fingerprint/KeyID from packet | ||
1176 | -> Message -- ^ List of packets (some of which are keys) | ||
1177 | -> String -- ^ Fingerprint/KeyID to search for | ||
1178 | -> Maybe Packet | ||
1164 | find_key fpr (Message (x@(PublicKeyPacket {}):xs)) keyid = | 1179 | find_key fpr (Message (x@(PublicKeyPacket {}):xs)) keyid = |
1165 | find_key' fpr x xs keyid | 1180 | find_key' fpr x xs keyid |
1166 | find_key fpr (Message (x@(SecretKeyPacket {}):xs)) keyid = | 1181 | find_key fpr (Message (x@(SecretKeyPacket {}):xs)) keyid = |
@@ -1177,7 +1192,18 @@ find_key' fpr x xs keyid | |||
1177 | thisid = reverse $ take (length keyid) (reverse (fpr x)) | 1192 | thisid = reverse $ take (length keyid) (reverse (fpr x)) |
1178 | 1193 | ||
1179 | -- | SignaturePacket smart constructor | 1194 | -- | SignaturePacket smart constructor |
1180 | signaturePacket :: Word8 -> Word8 -> KeyAlgorithm -> HashAlgorithm -> [SignatureSubpacket] -> [SignatureSubpacket] -> Word16 -> [MPI] -> Packet | 1195 | -- |
1196 | -- <http://tools.ietf.org/html/rfc4880#section-5.2> | ||
1197 | signaturePacket :: | ||
1198 | Word8 -- ^ Signature version (probably 4) | ||
1199 | -> Word8 -- ^ Signature type <http://tools.ietf.org/html/rfc4880#section-5.2.1> | ||
1200 | -> KeyAlgorithm | ||
1201 | -> HashAlgorithm | ||
1202 | -> [SignatureSubpacket] -- ^ Hashed subpackets (these get signed) | ||
1203 | -> [SignatureSubpacket] -- ^ Unhashed subpackets (these do not get signed) | ||
1204 | -> Word16 -- ^ Left 16 bits of the signed hash value | ||
1205 | -> [MPI] -- ^ The raw MPIs of the signature | ||
1206 | -> Packet | ||
1181 | signaturePacket version signature_type key_algorithm hash_algorithm hashed_subpackets unhashed_subpackets hash_head signature = | 1207 | signaturePacket version signature_type key_algorithm hash_algorithm hashed_subpackets unhashed_subpackets hash_head signature = |
1182 | let p = SignaturePacket { | 1208 | let p = SignaturePacket { |
1183 | version = version, | 1209 | version = version, |