Skip to content

Commit

Permalink
Add Sodium monad
Browse files Browse the repository at this point in the history
  • Loading branch information
olorin committed Jan 3, 2017
1 parent 9e1ce69 commit e73e5b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions ambiata-tinfoil.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/Tinfoil/Internal/Sodium.hs
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit e73e5b2

Please sign in to comment.