Created
February 10, 2016 21:07
-
-
Save mcschroeder/b59c7859db87f27b812f to your computer and use it in GitHub Desktop.
Getting values out of types at runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 | |
where | |
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