diff options
author | Stephen Paul Weber <singpolyma@singpolyma.net> | 2011-08-03 21:41:31 -0500 |
---|---|---|
committer | Stephen Paul Weber <singpolyma@singpolyma.net> | 2011-08-03 21:41:31 -0500 |
commit | a1f9066810c6624d0b9f1814e2a9131f3c73a071 (patch) | |
tree | 731ff714b568f897958e4921b0247ac7d96a0af7 | |
parent | 8b0320121725ed77956163a08aea39475279de50 (diff) |
signature convenience methods
-rw-r--r-- | lib/OpenPGP.hs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/OpenPGP.hs b/lib/OpenPGP.hs index d45597a..25a93d2 100644 --- a/lib/OpenPGP.hs +++ b/lib/OpenPGP.hs | |||
@@ -1,4 +1,4 @@ | |||
1 | module OpenPGP (Message(..), Packet(..), SignatureSubpacket(..), HashAlgorithm, KeyAlgorithm, CompressionAlgorithm, fingerprint) where | 1 | module OpenPGP (Message(..), Packet(..), SignatureSubpacket(..), HashAlgorithm, KeyAlgorithm, CompressionAlgorithm, MPI, fingerprint, signatures_and_data, signature_issuer) where |
2 | 2 | ||
3 | import Control.Monad | 3 | import Control.Monad |
4 | import Data.Binary | 4 | import Data.Binary |
@@ -352,6 +352,16 @@ instance Binary Message where | |||
352 | (Message tail) <- get :: Get Message | 352 | (Message tail) <- get :: Get Message |
353 | return (Message (next_packet:tail)) | 353 | return (Message (next_packet:tail)) |
354 | 354 | ||
355 | signatures_and_data :: Message -> ([Packet], [Packet]) | ||
356 | signatures_and_data (Message ((CompressedDataPacket {message = m}):_)) = | ||
357 | signatures_and_data m | ||
358 | signatures_and_data (Message lst) = | ||
359 | (filter isSig lst, filter isDta lst) | ||
360 | where isSig (SignaturePacket {}) = True | ||
361 | isSig _ = False | ||
362 | isDta (LiteralDataPacket {}) = True | ||
363 | isDta _ = False | ||
364 | |||
355 | newtype MPI = MPI Integer deriving (Show, Read, Eq, Ord) | 365 | newtype MPI = MPI Integer deriving (Show, Read, Eq, Ord) |
356 | instance Binary MPI where | 366 | instance Binary MPI where |
357 | put (MPI i) = do | 367 | put (MPI i) = do |
@@ -388,6 +398,15 @@ instance Binary SignatureSubpacket where | |||
388 | packet <- getLazyByteString len | 398 | packet <- getLazyByteString len |
389 | return $ runGet (parse_signature_subpacket tag) packet | 399 | return $ runGet (parse_signature_subpacket tag) packet |
390 | 400 | ||
401 | signature_issuer :: OpenPGP.Packet -> Maybe String | ||
402 | signature_issuer (SignaturePacket {hashed_subpackets = hashed, | ||
403 | unhashed_subpackets = unhashed}) = | ||
404 | if (length issuers) > 0 then Just issuer else Nothing | ||
405 | where IssuerPacket issuer = issuers !! 0 | ||
406 | issuers = (filter isIssuer hashed) ++ (filter isIssuer unhashed) | ||
407 | isIssuer (IssuerPacket {}) = True | ||
408 | isIssuer _ = False | ||
409 | |||
391 | get_signature_subpackets :: Get [SignatureSubpacket] | 410 | get_signature_subpackets :: Get [SignatureSubpacket] |
392 | get_signature_subpackets = do | 411 | get_signature_subpackets = do |
393 | done <- isEmpty | 412 | done <- isEmpty |