summaryrefslogtreecommitdiff
path: root/lib/Data/OpenPGP/Util.hs
blob: a51ce64b4f3bed40b167f204ba449982ae2e0205 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{-# OPTIONS_GHC -Wno-duplicate-exports #-}
{-# LANGUAGE PackageImports #-}
module Data.OpenPGP.Util
    ( module P
    , verify
    , setVerifyFlag
    ) where

import Data.Bool
import Data.IORef
import Debug.Trace
import GHC.Stack
import System.IO.Unsafe

import qualified "openpgp-util" Data.OpenPGP.Util as P
import "openpgp-util" Data.OpenPGP.Util hiding (verify)
import Data.OpenPGP

traceVerifyFlag :: IORef Bool
traceVerifyFlag = unsafePerformIO $ newIORef False
{-# NOINLINE traceVerifyFlag #-}

getVerifyFlag :: Bool
getVerifyFlag = unsafePerformIO $ readIORef traceVerifyFlag
{-# NOINLINE getVerifyFlag #-}

setVerifyFlag :: Bool -> IO ()
setVerifyFlag x = writeIORef traceVerifyFlag x

shortCallStack :: [([Char], SrcLoc)] -> String
shortCallStack []          = ""
shortCallStack ((_,loc):_) = (srcLocFile loc) ++ ":" ++ show (srcLocStartLine loc)

verify :: HasCallStack => Message -> SignatureOver -> SignatureOver
verify msg sig =
    bool id (trace $ "verify " ++ shortCallStack (getCallStack callStack)) getVerifyFlag
        $ P.verify msg sig