diff --git a/ambiata-tinfoil.cabal b/ambiata-tinfoil.cabal index 4df766f..432f4ac 100644 --- a/ambiata-tinfoil.cabal +++ b/ambiata-tinfoil.cabal @@ -50,6 +50,7 @@ library Tinfoil.Data.Verify Tinfoil.Encode Tinfoil.Hash + Tinfoil.Internal.Sodium Tinfoil.Internal.Sodium.Data Tinfoil.Internal.Sodium.Foreign Tinfoil.KDF diff --git a/src/Tinfoil/Internal/Sodium.hs b/src/Tinfoil/Internal/Sodium.hs new file mode 100644 index 0000000..3bbf51c --- /dev/null +++ b/src/Tinfoil/Internal/Sodium.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} + +module Tinfoil.Internal.Sodium ( + Sodium(..) + , runSodium + ) where + +import P + +import System.IO (IO) + +import Tinfoil.Internal.Sodium.Data +import Tinfoil.Internal.Sodium.Foreign + +newtype Sodium a = + Sodium (IO a) + deriving (Monad, Functor, Applicative) + +runSodium :: Sodium a -> IO (Maybe' a) +runSodium (Sodium s) = + sodiumInit >>= \x -> case x of + SodiumInitialised -> + Just' <$> s + SodiumNotInitialised -> + pure Nothing'