diff options
author | Joe Crayne <joe@jerkface.net> | 2019-07-01 23:16:32 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-07-01 23:16:32 -0400 |
commit | 5d5ce0e97107619b8e33c76585d7629f106ad3c8 (patch) | |
tree | 3492c9de1a740154654a6ba1cced90e879f47219 /lib | |
parent | ae8792ee7c51da15e52f30475c17ce589f940509 (diff) |
New debugging option: --trace-verify
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Data/OpenPGP/Util.hs | 37 | ||||
-rw-r--r-- | lib/Kiki.hs | 5 |
2 files changed, 41 insertions, 1 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 #-} | ||
3 | module Data.OpenPGP.Util | ||
4 | ( module P | ||
5 | , verify | ||
6 | , setVerifyFlag | ||
7 | ) where | ||
8 | |||
9 | import Data.Bool | ||
10 | import Data.IORef | ||
11 | import Debug.Trace | ||
12 | import GHC.Stack | ||
13 | import System.IO.Unsafe | ||
14 | |||
15 | import qualified "openpgp-util" Data.OpenPGP.Util as P | ||
16 | import "openpgp-util" Data.OpenPGP.Util hiding (verify) | ||
17 | import Data.OpenPGP | ||
18 | |||
19 | traceVerifyFlag :: IORef Bool | ||
20 | traceVerifyFlag = unsafePerformIO $ newIORef False | ||
21 | {-# NOINLINE traceVerifyFlag #-} | ||
22 | |||
23 | getVerifyFlag :: Bool | ||
24 | getVerifyFlag = unsafePerformIO $ readIORef traceVerifyFlag | ||
25 | {-# NOINLINE getVerifyFlag #-} | ||
26 | |||
27 | setVerifyFlag :: Bool -> IO () | ||
28 | setVerifyFlag x = writeIORef traceVerifyFlag x | ||
29 | |||
30 | shortCallStack :: [([Char], SrcLoc)] -> String | ||
31 | shortCallStack [] = "" | ||
32 | shortCallStack ((_,loc):_) = (srcLocFile loc) ++ ":" ++ show (srcLocStartLine loc) | ||
33 | |||
34 | verify :: HasCallStack => Message -> SignatureOver -> SignatureOver | ||
35 | verify msg sig = | ||
36 | bool id (trace $ "verify " ++ shortCallStack (getCallStack callStack)) getVerifyFlag | ||
37 | $ P.verify msg sig | ||
diff --git a/lib/Kiki.hs b/lib/Kiki.hs index 64e2d7d..6481b58 100644 --- a/lib/Kiki.hs +++ b/lib/Kiki.hs | |||
@@ -1,6 +1,9 @@ | |||
1 | {-# LANGUAGE CPP #-} | 1 | {-# LANGUAGE CPP #-} |
2 | {-# LANGUAGE OverloadedStrings #-} | 2 | {-# LANGUAGE OverloadedStrings #-} |
3 | module Kiki where | 3 | module Kiki |
4 | ( module Kiki | ||
5 | , setVerifyFlag | ||
6 | ) where | ||
4 | 7 | ||
5 | import Control.Applicative | 8 | import Control.Applicative |
6 | import Control.Arrow | 9 | import Control.Arrow |