module Tahin ( TahinPassword
, TahinMasterPassword
, TahinIdentifier
, TahinTransformer
, tahin ) where
import qualified Data.ByteString.Base64 as B64
import qualified Data.ByteString.Char8 as BS8
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import Data.Text (Text)
type TahinMasterPassword = Text
type TahinPassword = Text
type TahinIdentifier = Text
type TahinTransformer = TahinMasterPassword -> TahinIdentifier -> TahinPassword
tahin :: (BS8.ByteString -> BS8.ByteString) -> Int -> TahinTransformer
tahin hash len =
curry (T.take len . TE.decodeUtf8 . B64.encode . hash . TE.encodeUtf8 . intercal)
where intercal (pw, identifier) = T.intercalate " " [pw, identifier]