summaryrefslogtreecommitdiff
path: root/OpenPGP.hs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenPGP.hs')
-rw-r--r--OpenPGP.hs42
1 files changed, 42 insertions, 0 deletions
diff --git a/OpenPGP.hs b/OpenPGP.hs
new file mode 100644
index 0000000..7fef0b5
--- /dev/null
+++ b/OpenPGP.hs
@@ -0,0 +1,42 @@
1module OpenPGP
2 ( verify
3 , fingerprint
4 , pgpSign
5 , decryptSecretKey
6 ) where
7
8import Data.OpenPGP as OpenPGP
9import Data.OpenPGP.CryptoAPI (verify,fingerprint,sign,decryptSecretKey)
10import Data.Time.Clock.POSIX
11import Control.Applicative ( (<$>) )
12import Crypto.Random (newGenIO,SystemRandom)
13
14now = floor <$> Data.Time.Clock.POSIX.getPOSIXTime
15
16stampit timestamp sig = sig { hashed_subpackets = hashed' }
17 where
18 hashed_stamps = filter isStamp (hashed_subpackets sig)
19 unhashed_stamps = filter isStamp (unhashed_subpackets sig)
20 hashed' = case hashed_stamps ++ unhashed_stamps of
21 [] -> SignatureCreationTimePacket (fromIntegral timestamp)
22 : hashed_subpackets sig
23 _ -> hashed_subpackets sig
24 isStamp (SignatureCreationTimePacket {}) = True
25 isStamp _ = False
26
27-- | Make a signature
28--
29-- In order to set more options on a signature, pass in a signature packet.
30pgpSign ::
31 OpenPGP.Message -- ^ SecretKeys, one of which will be used
32 -> OpenPGP.SignatureOver -- ^ Data to sign, and optional signature packet
33 -> OpenPGP.HashAlgorithm -- ^ HashAlgorithm to use in signature
34 -> String -- ^ KeyID of key to choose
35 -> IO OpenPGP.SignatureOver
36pgpSign seckeys dta hash_algo keyid = do
37 timestamp <- now
38 g <- newGenIO :: IO SystemRandom
39 let sigs = map (stampit timestamp) $ signatures_over dta
40 dta' = dta { signatures_over = sigs }
41 let (r,g') = sign seckeys dta' hash_algo keyid timestamp g
42 return r