From e73e5b26aa50d41c2f6e226982446c0e883deef3 Mon Sep 17 00:00:00 2001 From: Sharif Olorin Date: Wed, 28 Dec 2016 01:17:41 +0000 Subject: [PATCH] Add Sodium monad --- ambiata-tinfoil.cabal | 1 + src/Tinfoil/Internal/Sodium.hs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/Tinfoil/Internal/Sodium.hs 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'