module Botan.PubKey.Verify
(
pkVerify
, PKVerify(..)
, destroyPKVerify
, newPKVerify
, pkVerifyUpdate
, pkVerifyFinish
) where
import qualified Data.ByteString as ByteString
import qualified Botan.Low.PubKey.Verify as Low
import Botan.Error
import Botan.Prelude
import Botan.PubKey
import Botan.PubKey.Sign
pkVerify :: PubKey -> PKSignAlgo -> PKSignatureFormat -> ByteString -> PKSignature -> Bool
pkVerify :: PubKey
-> PKSignAlgo
-> PKSignatureFormat
-> ByteString
-> ByteString
-> Bool
pkVerify PubKey
pk PKSignAlgo
algo PKSignatureFormat
fmt ByteString
msg ByteString
sig = IO Bool -> Bool
forall a. IO a -> a
unsafePerformIO (IO Bool -> Bool) -> IO Bool -> Bool
forall a b. (a -> b) -> a -> b
$ do
PKVerify
verifier <- PubKey -> PKSignAlgo -> PKSignatureFormat -> IO PKVerify
forall (m :: * -> *).
MonadIO m =>
PubKey -> PKSignAlgo -> PKSignatureFormat -> m PKVerify
newPKVerify PubKey
pk PKSignAlgo
algo PKSignatureFormat
fmt
PKVerify -> ByteString -> IO ()
forall (m :: * -> *). MonadIO m => PKVerify -> ByteString -> m ()
pkVerifyUpdate PKVerify
verifier ByteString
msg
PKVerify -> ByteString -> IO Bool
forall (m :: * -> *). MonadIO m => PKVerify -> ByteString -> m Bool
pkVerifyFinish PKVerify
verifier ByteString
sig
{-# NOINLINE pkVerify #-}
type PKVerify = Low.Verify
destroyPKVerify :: (MonadIO m) => PKVerify -> m ()
destroyPKVerify :: forall (m :: * -> *). MonadIO m => PKVerify -> m ()
destroyPKVerify = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (PKVerify -> IO ()) -> PKVerify -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PKVerify -> IO ()
Low.verifyDestroy
newPKVerify :: (MonadIO m) => PubKey -> PKSignAlgo -> PKSignatureFormat -> m PKVerify
newPKVerify :: forall (m :: * -> *).
MonadIO m =>
PubKey -> PKSignAlgo -> PKSignatureFormat -> m PKVerify
newPKVerify PubKey
pk PKSignAlgo
algo PKSignatureFormat
fmt = IO PKVerify -> m PKVerify
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO PKVerify -> m PKVerify) -> IO PKVerify -> m PKVerify
forall a b. (a -> b) -> a -> b
$ PubKey -> ByteString -> PKSignatureFormat -> IO PKVerify
Low.verifyCreate PubKey
pk (PKSignAlgo -> ByteString
signAlgoName PKSignAlgo
algo) PKSignatureFormat
fmt
pkVerifyUpdate :: (MonadIO m) => PKVerify -> ByteString -> m ()
pkVerifyUpdate :: forall (m :: * -> *). MonadIO m => PKVerify -> ByteString -> m ()
pkVerifyUpdate PKVerify
verifier ByteString
msg = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ PKVerify -> ByteString -> IO ()
Low.verifyUpdate PKVerify
verifier ByteString
msg
pkVerifyFinish :: (MonadIO m) => PKVerify -> PKSignature -> m Bool
pkVerifyFinish :: forall (m :: * -> *). MonadIO m => PKVerify -> ByteString -> m Bool
pkVerifyFinish PKVerify
verifier ByteString
sig = IO Bool -> m Bool
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ PKVerify -> ByteString -> IO Bool
Low.verifyFinish PKVerify
verifier ByteString
sig