cardano-crypto-class-2.1.1.0: Type classes abstracting over cryptography primitives for Cardano
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cardano.Crypto.MonadSodium.Alloc

Description

The Libsodium API generalized to fit arbitrary-ish Monads.

The purpose of this module is to provide a drop-in replacement for the plain Libsodium module, but such that the Monad in which some essential actions run can be mocked, rather than forcing it to be IO.

It may also be used to provide Libsodium functionality in monad stacks that have IO at the bottom, but decorate certain Libsodium operations with additional effects, e.g. logging mlocked memory access.

Synopsis

Documentation

class Monad m => MonadSodium m where #

Primitive operations on unmanaged mlocked memory. These are all implemented in IO underneath, but should morally be in ST. There are two use cases for this: - Running mlocked-memory operations in a mocking context (e.g. IOSim) for testing purposes. - Running mlocked-memory operations directly on some monad stack with IO at the bottom.

Methods

withMLockedForeignPtr :: forall a b. MLockedForeignPtr a -> (Ptr a -> m b) -> m b #

finalizeMLockedForeignPtr :: forall a. MLockedForeignPtr a -> m () #

traceMLockedForeignPtr :: (Storable a, Show a) => MLockedForeignPtr a -> m () #

Deprecated: Do not use traceMLockedForeignPtr in production

mlockedMalloc :: CSize -> m (MLockedForeignPtr a) #

zeroMem :: Ptr a -> CSize -> m () #

copyMem :: Ptr a -> Ptr a -> CSize -> m () #

Instances

Instances details
MonadSodium IO # 
Instance details

Defined in Cardano.Crypto.MonadSodium.Class

mlockedAlloca :: forall a b m. (MonadSodium m, MonadThrow m) => CSize -> (Ptr a -> m b) -> m b #

mlockedAllocaSized :: forall m n b. (MonadSodium m, MonadThrow m, KnownNat n) => (SizedPtr n -> m b) -> m b #

Re-exports from plain Libsodium module

data MLockedForeignPtr a #

Foreign pointer to securely allocated memory.