
module Zero.Sjcl.Hkdf
  (
    hkdf
  , hkdfText
  ) where

import qualified Data.JSString as JSS
import           Data.JSString (JSString)
import qualified Data.Text as T
import           Data.Text (Text)
import           Zero.Sjcl.BitArray (BitArray)

------------------------------------------------------------------------------

hkdf :: BitArray -> Int -> BitArray -> Text -> IO BitArray
hkdf ikm niter salt info  = do
  js_hkdf ikm niter salt (JSS.pack $ T.unpack info)

hkdfText :: Text -> Int -> BitArray -> Text -> IO BitArray
hkdfText ikm niter salt info  = do
  js_hkdf_string (JSS.pack $ T.unpack ikm) niter salt (JSS.pack $ T.unpack info)

------------------------------------------------------------------------------
-- FFI
------------------------------------------------------------------------------

foreign import javascript unsafe "$r = sjcl.misc.hkdf($1,$2,$3,$4);"
  js_hkdf :: BitArray -> Int -> BitArray -> JSString -> IO BitArray

foreign import javascript unsafe "$r = sjcl.misc.hkdf($1,$2,$3,$4);"
  js_hkdf_string :: JSString -> Int -> BitArray -> JSString -> IO BitArray
