h-gpgme 0.5.0.0 → 0.5.1.0
raw patch · 6 files changed
+48/−1 lines, 6 files
Files
- h-gpgme.cabal +1/−1
- src/Crypto/Gpgme.hs +2/−0
- src/Crypto/Gpgme/Ctx.hs +7/−0
- src/Crypto/Gpgme/Internal.hs +8/−0
- src/Crypto/Gpgme/Types.hs +8/−0
- test/CtxTest.hs +22/−0
h-gpgme.cabal view
@@ -1,5 +1,5 @@ Name: h-gpgme-Version: 0.5.0.0+Version: 0.5.1.0 Description: High Level Binding for GnuPG Made Easy (gpgme): A Haskell API for the gpgme C library. Synopsis: High Level Binding for GnuPG Made Easy (gpgme) License: MIT
src/Crypto/Gpgme.hs view
@@ -38,6 +38,7 @@ , freeCtx , withCtx , setArmor+ , setKeyListingMode -- ** Passphrase callbacks , isPassphraseCbSupported , PassphraseCb@@ -93,6 +94,7 @@ , sourceString -- * Other Types+ , KeyListingMode(..) , SignMode(..) , Fpr
src/Crypto/Gpgme/Ctx.hs view
@@ -87,6 +87,13 @@ ctx <- peek ctxPtr c'gpgme_set_armor ctx (if armored then 1 else 0) +-- | Sets the key listing mode on ctx+setKeyListingMode :: [KeyListingMode] -> Ctx -> IO ()+setKeyListingMode modes (Ctx {_ctx = ctxPtr}) = do+ let m = foldl (\memo -> (memo .|.) . fromKeyListingMode) 0 modes+ ctx <- peek ctxPtr+ checkError "set_keylist_mode" =<< c'gpgme_set_keylist_mode ctx m+ -- | Are passphrase callbacks supported? -- -- This functionality is known to be broken in some gpg versions,
src/Crypto/Gpgme/Internal.hs view
@@ -68,6 +68,14 @@ noError :: Num a => a noError = 0 +fromKeyListingMode :: KeyListingMode -> C'gpgme_keylist_mode_t+fromKeyListingMode KeyListingLocal = c'GPGME_KEYLIST_MODE_LOCAL+fromKeyListingMode KeyListingExtern = c'GPGME_KEYLIST_MODE_EXTERN+fromKeyListingMode KeyListingSigs = c'GPGME_KEYLIST_MODE_SIGS+fromKeyListingMode KeyListingSigNotations = c'GPGME_KEYLIST_MODE_SIG_NOTATIONS+fromKeyListingMode KeyListingValidate = c'GPGME_KEYLIST_MODE_VALIDATE++ fromProtocol :: (Num a) => Protocol -> a fromProtocol CMS = c'GPGME_PROTOCOL_CMS fromProtocol GPGCONF = c'GPGME_PROTOCOL_GPGCONF
src/Crypto/Gpgme/Types.hs view
@@ -26,6 +26,14 @@ , _engineVersion :: String -- ^ engine version } +-- | Modes for key listings+data KeyListingMode+ = KeyListingLocal+ | KeyListingExtern+ | KeyListingSigs+ | KeyListingSigNotations+ | KeyListingValidate+ -- | Modes for signing with GPG data SignMode = Normal | Detach | Clear deriving Show
test/CtxTest.hs view
@@ -4,6 +4,7 @@ import Control.Monad.Trans.Maybe import Control.Monad.Trans.Class (lift) import qualified Data.ByteString as BS+import Data.Maybe (fromMaybe) import Control.Exception (catch, fromException) import System.IO.Error (IOError, isUserError) @@ -18,6 +19,8 @@ tests = [ testCase "run_action_with_ctx" run_action_with_ctx , testCase "set_armor" set_armor , testCase "unset_armor" unset_armor+ , testCase "no_set_listing_mode" no_set_listing_mode+ , testCase "set_listing_mode" set_listing_mode , testCase "exception_safe" exception_safe ] @@ -44,6 +47,25 @@ lift $ setArmor False bCtx lift $ encrypt bCtx [aPubKey] NoFlag "plaintext" (not $ armorPrefix `BS.isPrefixOf` fromJustAndRight enc) @? ("Binary must not start with " ++ show armorPrefix)++no_set_listing_mode :: Assertion+no_set_listing_mode = do+ sigs <- withCtx "test/bob" "C" OpenPGP $ \bCtx -> runMaybeT $ do+ aPubKey <- MaybeT $ getKey bCtx alice_pub_fpr NoSecret+ kuids <- lift $ keyUserIds' aPubKey+ return $ concatMap keyuserSignatures kuids+ let sigs' = fromMaybe [] sigs+ (length sigs' == 0) @? ("There should be no signatures, but there are some")++set_listing_mode :: Assertion+set_listing_mode = do+ sigs <- withCtx "test/bob" "C" OpenPGP $ \bCtx -> runMaybeT $ do+ lift $ setKeyListingMode [KeyListingLocal, KeyListingSigs] bCtx+ aPubKey <- MaybeT $ getKey bCtx alice_pub_fpr NoSecret+ kuids <- lift $ keyUserIds' aPubKey+ return $ concatMap keyuserSignatures kuids+ let sigs' = fromMaybe [] sigs+ (length sigs' > 0) @? ("There should be some signatures, but there are non") -- Ensure that if an exception occurs then the expected exception type is returned so that we know -- the context was freed