summaryrefslogtreecommitdiff
path: root/lib/Data/OpenPGP/Util.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/OpenPGP/Util.hs')
-rw-r--r--lib/Data/OpenPGP/Util.hs37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/Data/OpenPGP/Util.hs b/lib/Data/OpenPGP/Util.hs
new file mode 100644
index 0000000..a51ce64
--- /dev/null
+++ b/lib/Data/OpenPGP/Util.hs
@@ -0,0 +1,37 @@
1{-# OPTIONS_GHC -Wno-duplicate-exports #-}
2{-# LANGUAGE PackageImports #-}
3module Data.OpenPGP.Util
4 ( module P
5 , verify
6 , setVerifyFlag
7 ) where
8
9import Data.Bool
10import Data.IORef
11import Debug.Trace
12import GHC.Stack
13import System.IO.Unsafe
14
15import qualified "openpgp-util" Data.OpenPGP.Util as P
16import "openpgp-util" Data.OpenPGP.Util hiding (verify)
17import Data.OpenPGP
18
19traceVerifyFlag :: IORef Bool
20traceVerifyFlag = unsafePerformIO $ newIORef False
21{-# NOINLINE traceVerifyFlag #-}
22
23getVerifyFlag :: Bool
24getVerifyFlag = unsafePerformIO $ readIORef traceVerifyFlag
25{-# NOINLINE getVerifyFlag #-}
26
27setVerifyFlag :: Bool -> IO ()
28setVerifyFlag x = writeIORef traceVerifyFlag x
29
30shortCallStack :: [([Char], SrcLoc)] -> String
31shortCallStack [] = ""
32shortCallStack ((_,loc):_) = (srcLocFile loc) ++ ":" ++ show (srcLocStartLine loc)
33
34verify :: HasCallStack => Message -> SignatureOver -> SignatureOver
35verify msg sig =
36 bool id (trace $ "verify " ++ shortCallStack (getCallStack callStack)) getVerifyFlag
37 $ P.verify msg sig