diff options
author | joe <joe@jerkface.net> | 2013-12-13 04:27:54 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2013-12-13 04:27:54 -0500 |
commit | de42e2f46ec64f84317ef3696bd304a3836a38f9 (patch) | |
tree | 71190f85d0b5354fde46f22f5150ab86ac34343d /OpenPGP.hs | |
parent | 89c2b6b175ecf805fdd9e823726b8eec4774c78b (diff) |
Changed pgpSign to return a Maybe in case a signature cannot be made.
Diffstat (limited to 'OpenPGP.hs')
-rw-r--r-- | OpenPGP.hs | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -10,6 +10,7 @@ import Data.OpenPGP.CryptoAPI (verify,fingerprint,sign,decryptSecretKey) | |||
10 | import Data.Time.Clock.POSIX | 10 | import Data.Time.Clock.POSIX |
11 | import Control.Applicative ( (<$>) ) | 11 | import Control.Applicative ( (<$>) ) |
12 | import Crypto.Random (newGenIO,SystemRandom) | 12 | import Crypto.Random (newGenIO,SystemRandom) |
13 | import ControlMaybe | ||
13 | 14 | ||
14 | now = floor <$> Data.Time.Clock.POSIX.getPOSIXTime | 15 | now = floor <$> Data.Time.Clock.POSIX.getPOSIXTime |
15 | 16 | ||
@@ -32,11 +33,12 @@ pgpSign :: | |||
32 | -> OpenPGP.SignatureOver -- ^ Data to sign, and optional signature packet | 33 | -> OpenPGP.SignatureOver -- ^ Data to sign, and optional signature packet |
33 | -> OpenPGP.HashAlgorithm -- ^ HashAlgorithm to use in signature | 34 | -> OpenPGP.HashAlgorithm -- ^ HashAlgorithm to use in signature |
34 | -> String -- ^ KeyID of key to choose | 35 | -> String -- ^ KeyID of key to choose |
35 | -> IO OpenPGP.SignatureOver | 36 | -> IO (Maybe OpenPGP.SignatureOver) |
36 | pgpSign seckeys dta hash_algo keyid = do | 37 | pgpSign seckeys dta hash_algo keyid = |
38 | handleIO_ (return Nothing) $ do | ||
37 | timestamp <- now | 39 | timestamp <- now |
38 | g <- newGenIO :: IO SystemRandom | 40 | g <- newGenIO :: IO SystemRandom |
39 | let sigs = map (stampit timestamp) $ signatures_over dta | 41 | let sigs = map (stampit timestamp) $ signatures_over dta |
40 | dta' = dta { signatures_over = sigs } | 42 | dta' = dta { signatures_over = sigs } |
41 | let (r,g') = sign seckeys dta' hash_algo keyid timestamp g | 43 | let (r,g') = sign seckeys dta' hash_algo keyid timestamp g |
42 | return r | 44 | return (Just r) |