Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. {-# LANGUAGE KindSignatures #-}
  2. {-# LANGUAGE DataKinds #-}
  3. {-# LANGUAGE ScopedTypeVariables #-}
  4.  
  5. module Key (Key, makeKey) where
  6.  
  7. import Data.ByteString (ByteString)
  8. import qualified Data.ByteString as B
  9. import Data.Proxy
  10. import GHC.TypeLits
  11.  
  12. newtype Key (size :: Nat) = Key ByteString
  13. deriving (Show)
  14.  
  15. makeKey :: forall size. KnownNat size => ByteString -> Maybe (Key size)
  16. makeKey s | B.length s == (keyLength `div` 8) = Just (Key s)
  17. | otherwise = Nothing
  18. where
  19. keyLength = fromInteger $ natVal (Proxy :: Proxy size)
  20.  
  21. --encrypt :: Key 96 -> Key 256 -> String -> String
  22. --encrypt (Key nonce) (Key cipherKey) plaintext = undefined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement