{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE TypeFamilies             #-}

module Crypto.Saltine (
  sodiumInit
  ) where

import Foreign.C

-- | Runs Sodiums's initialization routine. This must be called before
-- using any other function. It is thread-safe since libsodium 1.0.11.
sodiumInit :: IO ()
sodiumInit :: IO ()
sodiumInit = do
  CInt
err <- IO CInt
c_sodiumInit
  case CInt
err of
    CInt
0 -> -- everything went well
      () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    CInt
1 -> -- already initialized, we're good
      () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    CInt
_ -> -- some kind of failure
      [Char] -> IO ()
forall a. HasCallStack => [Char] -> a
error [Char]
"Crypto.Saltine.sodiumInit"

foreign import ccall "sodium_init" c_sodiumInit :: IO CInt