Skip to content

Instantly share code, notes, and snippets.



Created Feb 10, 2016
What would you like to do?
Getting values out of types at runtime
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Key (Key, makeKey) where
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import Data.Proxy
import GHC.TypeLits
newtype Key (size :: Nat) = Key ByteString
deriving (Show)
makeKey :: forall size. KnownNat size => ByteString -> Maybe (Key size)
makeKey s | B.length s == (keyLength `div` 8) = Just (Key s)
| otherwise = Nothing
keyLength = fromInteger $ natVal (Proxy :: Proxy size)
--encrypt :: Key 96 -> Key 256 -> String -> String
--encrypt (Key nonce) (Key cipherKey) plaintext = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.