{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.GLib.Structs.Hmac
(
Hmac(..) ,
#if defined(ENABLE_OVERLOADING)
ResolveHmacMethod ,
#endif
#if defined(ENABLE_OVERLOADING)
HmacGetDigestMethodInfo ,
#endif
hmacGetDigest ,
#if defined(ENABLE_OVERLOADING)
HmacGetStringMethodInfo ,
#endif
hmacGetString ,
#if defined(ENABLE_OVERLOADING)
HmacUnrefMethodInfo ,
#endif
hmacUnref ,
#if defined(ENABLE_OVERLOADING)
HmacUpdateMethodInfo ,
#endif
hmacUpdate ,
) where
import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P
import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GArray as B.GArray
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GHashTable as B.GHT
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Coerce as Coerce
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL
import qualified GHC.Records as R
newtype Hmac = Hmac (SP.ManagedPtr Hmac)
deriving (Hmac -> Hmac -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Hmac -> Hmac -> Bool
$c/= :: Hmac -> Hmac -> Bool
== :: Hmac -> Hmac -> Bool
$c== :: Hmac -> Hmac -> Bool
Eq)
instance SP.ManagedPtrNewtype Hmac where
toManagedPtr :: Hmac -> ManagedPtr Hmac
toManagedPtr (Hmac ManagedPtr Hmac
p) = ManagedPtr Hmac
p
instance BoxedPtr Hmac where
boxedPtrCopy :: Hmac -> IO Hmac
boxedPtrCopy = forall (m :: * -> *) a. Monad m => a -> m a
return
boxedPtrFree :: Hmac -> IO ()
boxedPtrFree = \Hmac
_x -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Hmac
type instance O.AttributeList Hmac = HmacAttributeList
type HmacAttributeList = ('[ ] :: [(Symbol, *)])
#endif
foreign import ccall "g_hmac_get_digest" g_hmac_get_digest ::
Ptr Hmac ->
Ptr Word8 ->
Ptr Word32 ->
IO ()
hmacGetDigest ::
(B.CallStack.HasCallStack, MonadIO m) =>
Hmac
-> ByteString
-> m ()
hmacGetDigest :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Hmac -> ByteString -> m ()
hmacGetDigest Hmac
hmac ByteString
buffer = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
let digestLen :: Word32
digestLen = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ ByteString -> Int
B.length ByteString
buffer
Ptr Hmac
hmac' <- forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Hmac
hmac
Ptr Word8
buffer' <- ByteString -> IO (Ptr Word8)
packByteString ByteString
buffer
Ptr Word32
digestLen' <- forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Word32)
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr Word32
digestLen' Word32
digestLen
Ptr Hmac -> Ptr Word8 -> Ptr Word32 -> IO ()
g_hmac_get_digest Ptr Hmac
hmac' Ptr Word8
buffer' Ptr Word32
digestLen'
Word32
digestLen'' <- forall a. Storable a => Ptr a -> IO a
peek Ptr Word32
digestLen'
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Hmac
hmac
forall a. Ptr a -> IO ()
freeMem Ptr Word8
buffer'
forall a. Ptr a -> IO ()
freeMem Ptr Word32
digestLen'
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data HmacGetDigestMethodInfo
instance (signature ~ (ByteString -> m ()), MonadIO m) => O.OverloadedMethod HmacGetDigestMethodInfo Hmac signature where
overloadedMethod = hmacGetDigest
instance O.OverloadedMethodInfo HmacGetDigestMethodInfo Hmac where
overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
O.resolvedSymbolName = "GI.GLib.Structs.Hmac.hmacGetDigest",
O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.27/docs/GI-GLib-Structs-Hmac.html#v:hmacGetDigest"
})
#endif
foreign import ccall "g_hmac_get_string" g_hmac_get_string ::
Ptr Hmac ->
IO CString
hmacGetString ::
(B.CallStack.HasCallStack, MonadIO m) =>
Hmac
-> m T.Text
hmacGetString :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Hmac -> m Text
hmacGetString Hmac
hmac = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
Ptr Hmac
hmac' <- forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Hmac
hmac
CString
result <- Ptr Hmac -> IO CString
g_hmac_get_string Ptr Hmac
hmac'
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"hmacGetString" CString
result
Text
result' <- HasCallStack => CString -> IO Text
cstringToText CString
result
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Hmac
hmac
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'
#if defined(ENABLE_OVERLOADING)
data HmacGetStringMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.OverloadedMethod HmacGetStringMethodInfo Hmac signature where
overloadedMethod = hmacGetString
instance O.OverloadedMethodInfo HmacGetStringMethodInfo Hmac where
overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
O.resolvedSymbolName = "GI.GLib.Structs.Hmac.hmacGetString",
O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.27/docs/GI-GLib-Structs-Hmac.html#v:hmacGetString"
})
#endif
foreign import ccall "g_hmac_unref" g_hmac_unref ::
Ptr Hmac ->
IO ()
hmacUnref ::
(B.CallStack.HasCallStack, MonadIO m) =>
Hmac
-> m ()
hmacUnref :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Hmac -> m ()
hmacUnref Hmac
hmac = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
Ptr Hmac
hmac' <- forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Hmac
hmac
Ptr Hmac -> IO ()
g_hmac_unref Ptr Hmac
hmac'
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Hmac
hmac
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data HmacUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.OverloadedMethod HmacUnrefMethodInfo Hmac signature where
overloadedMethod = hmacUnref
instance O.OverloadedMethodInfo HmacUnrefMethodInfo Hmac where
overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
O.resolvedSymbolName = "GI.GLib.Structs.Hmac.hmacUnref",
O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.27/docs/GI-GLib-Structs-Hmac.html#v:hmacUnref"
})
#endif
foreign import ccall "g_hmac_update" g_hmac_update ::
Ptr Hmac ->
Ptr Word8 ->
Int32 ->
IO ()
hmacUpdate ::
(B.CallStack.HasCallStack, MonadIO m) =>
Hmac
-> ByteString
-> m ()
hmacUpdate :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Hmac -> ByteString -> m ()
hmacUpdate Hmac
hmac ByteString
data_ = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
let length_ :: Int32
length_ = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ ByteString -> Int
B.length ByteString
data_
Ptr Hmac
hmac' <- forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Hmac
hmac
Ptr Word8
data_' <- ByteString -> IO (Ptr Word8)
packByteString ByteString
data_
Ptr Hmac -> Ptr Word8 -> Int32 -> IO ()
g_hmac_update Ptr Hmac
hmac' Ptr Word8
data_' Int32
length_
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Hmac
hmac
forall a. Ptr a -> IO ()
freeMem Ptr Word8
data_'
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data HmacUpdateMethodInfo
instance (signature ~ (ByteString -> m ()), MonadIO m) => O.OverloadedMethod HmacUpdateMethodInfo Hmac signature where
overloadedMethod = hmacUpdate
instance O.OverloadedMethodInfo HmacUpdateMethodInfo Hmac where
overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
O.resolvedSymbolName = "GI.GLib.Structs.Hmac.hmacUpdate",
O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.27/docs/GI-GLib-Structs-Hmac.html#v:hmacUpdate"
})
#endif
#if defined(ENABLE_OVERLOADING)
type family ResolveHmacMethod (t :: Symbol) (o :: *) :: * where
ResolveHmacMethod "unref" o = HmacUnrefMethodInfo
ResolveHmacMethod "update" o = HmacUpdateMethodInfo
ResolveHmacMethod "getDigest" o = HmacGetDigestMethodInfo
ResolveHmacMethod "getString" o = HmacGetStringMethodInfo
ResolveHmacMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveHmacMethod t Hmac, O.OverloadedMethod info Hmac p) => OL.IsLabel t (Hmac -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod @info
#else
fromLabel _ = O.overloadedMethod @info
#endif
#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveHmacMethod t Hmac, O.OverloadedMethod info Hmac p, R.HasField t Hmac p) => R.HasField t Hmac p where
getField = O.overloadedMethod @info
#endif
instance (info ~ ResolveHmacMethod t Hmac, O.OverloadedMethodInfo info Hmac) => OL.IsLabel t (O.MethodProxy info Hmac) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.MethodProxy
#else
fromLabel _ = O.MethodProxy
#endif
#endif