test ciphers in a basic fashion for now.
This commit is contained in:
parent
4b3cd2c2f7
commit
18cf6a5392
2 changed files with 42 additions and 0 deletions
2
Tests.hs
2
Tests.hs
|
@ -2,7 +2,9 @@
|
|||
|
||||
import qualified Tests.Marshal as Marshal
|
||||
import qualified Tests.Connection as Connection
|
||||
import qualified Tests.Ciphers as Ciphers
|
||||
|
||||
main = do
|
||||
Marshal.runTests
|
||||
Ciphers.runTests
|
||||
Connection.runTests
|
||||
|
|
40
Tests/Ciphers.hs
Normal file
40
Tests/Ciphers.hs
Normal file
|
@ -0,0 +1,40 @@
|
|||
module Tests.Ciphers
|
||||
( runTests
|
||||
) where
|
||||
|
||||
import Data.Word
|
||||
import Control.Applicative ((<$>))
|
||||
|
||||
import Tests.Common
|
||||
import Test.QuickCheck
|
||||
|
||||
import qualified Data.ByteString as B
|
||||
import Network.TLS.Cipher
|
||||
|
||||
arbitraryKey :: Cipher -> Gen [Word8]
|
||||
arbitraryKey cipher = vector (fromIntegral $ cipherKeySize cipher)
|
||||
|
||||
arbitraryIV :: Cipher -> Gen [Word8]
|
||||
arbitraryIV cipher = vector (fromIntegral $ cipherIVSize cipher)
|
||||
|
||||
arbitraryText :: Cipher -> Gen [Word8]
|
||||
arbitraryText cipher = vector (fromIntegral $ cipherPaddingSize cipher)
|
||||
|
||||
cipher_test cipher = run_test n t
|
||||
where
|
||||
n = ("cipher: " ++ cipherName cipher ++ ": decrypt . encrypt = id")
|
||||
t = case cipherF cipher of
|
||||
CipherBlockF enc dec -> do
|
||||
key <- B.pack <$> arbitraryKey cipher
|
||||
iv <- B.pack <$> arbitraryIV cipher
|
||||
t <- B.pack <$> arbitraryText cipher
|
||||
return $ block enc dec key iv t
|
||||
CipherStreamF ktoi enc dec -> do
|
||||
key <- B.pack <$> arbitraryKey cipher
|
||||
t <- B.pack <$> arbitraryText cipher
|
||||
return $ stream ktoi enc dec key t
|
||||
block e d key iv t = (d key iv . e key iv) t == t
|
||||
stream ktoi e d key t = (fst . d iv . fst . e iv) t == t
|
||||
where iv = ktoi key
|
||||
|
||||
runTests = mapM_ cipher_test supportedCiphers
|
Loading…
Reference in a new issue