This commit is contained in:
Vincent Hanquez 2016-08-12 07:08:35 +01:00
commit 21c6a8d0a4
3 changed files with 38 additions and 3 deletions

View File

@ -52,10 +52,8 @@ instance E.Exception CryptoError
data CryptoFailable a =
CryptoPassed a
| CryptoFailed CryptoError
deriving (Show)
instance Show a => Show (CryptoFailable a) where
show (CryptoPassed a) = "CryptoPassed " ++ show a
show (CryptoFailed err) = "CryptoFailed " ++ show err
instance Eq a => Eq (CryptoFailable a) where
(==) (CryptoPassed a) (CryptoPassed b) = a == b
(==) (CryptoFailed e1) (CryptoFailed e2) = e1 == e2

34
Crypto/Tutorial.hs Normal file
View File

@ -0,0 +1,34 @@
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# LANGUAGE OverloadedStrings #-}
{-| How to use @cryptonite@
> -- | Beware MUST BE 256bits as we use AES256
> import Data.ByteString (ByteString)
> import Crypto.Cipher.AES (AES256)
> import Crypto.Cipher.Types (BlockCipher(..), Cipher(..),nullIV)
> import Crypto.Error (CryptoFailable(..))
>
> secretKey :: ByteString
> secretKey = "012-456-89A-CDE-012-456-89A-CDE-"
>
> encrypt :: ByteString -> ByteString -> ByteString
> encrypt secret = ctrCombine ctx nullIV
> where
> ctx = cipherInitNoErr (cipherMakeKey (undefined :: AES256) secret)
> cipherInitNoErr :: BlockCipher c => Key c -> c
> cipherInitNoErr (Key k) = case cipherInit k of
> CryptoPassed a -> a
> CryptoFailed e -> error (show e)
> cipherMakeKey :: Cipher cipher => cipher -> ByteString -> Key cipher
> cipherMakeKey _ = Key -- Yeah Lazyness!!!!!!
>
>
> decrypt :: ByteString -> ByteString -> ByteString
> decrypt = encrypt
|-}
module Crypto.Tutorial () where
import Crypto.Cipher.Types

View File

@ -23,6 +23,8 @@ Description:
cryptographic kitchen sink that provides cryptography for everyone.
.
Evaluate the security related to your requirements before using.
.
Read "Crypto.Tutorial" for a quick start guide.
License: BSD3
License-file: LICENSE
Copyright: Vincent Hanquez <vincent@snarc.org>
@ -139,6 +141,7 @@ Library
Crypto.Random.Entropy
Crypto.Random.EntropyPool
Crypto.Random.Entropy.Unsafe
Crypto.Tutorial
Other-modules: Crypto.Cipher.AES.Primitive
Crypto.Cipher.Blowfish.Box
Crypto.Cipher.Blowfish.Primitive