<commit_before>{-# LANGUAGE FlexibleContexts #-}
module Modules.Stream (tests) where

import           Control.Applicative                  ((<$>))
import           Data.ByteString                      (ByteString)
import qualified Data.ByteString                      as BS
import           Test.Framework                       (Test)
import           Test.Framework.Providers.QuickCheck2 (testProperty)
import           Test.QuickCheck
import           Test.QuickCheck.Monadic              (run, assert, monadicIO)

import           Raaz.Primitives
import           Raaz.Primitives.Cipher
import qualified Raaz.Util.ByteString                 as BU
import           Raaz.Memory
import           Raaz.Types

import           Raaz.Cipher.AES.Type
import           Raaz.Cipher.AES.CTR

import           Raaz.Random

-- | Type to capture only integers from 1 to 10
newtype Sized = Sized (BYTES Int) deriving Show

instance Arbitrary Sized where
  arbitrary = Sized . BYTES <$> choose (0,100000)

data TestIV g = TestIV ByteString deriving Show

instance Initializable p => Arbitrary (TestIV p) where
  arbitrary = gen undefined
    where
      gen :: Initializable p => p -> Gen (TestIV p)
      gen p = TestIV . BS.pack <$> vectorOf (fromIntegral $ cxtSize p) arbitrary

prop_length :: (StreamGadget g, Initializable (PrimitiveOf g))
            => g
            -> TestIV (PrimitiveOf g)
            -> Sized    -- ^ Number of bytes to generate
            -> Property
prop_length g' (TestIV bsiv) (Sized sz) = monadicIO $ do
  bs <- run $ generateBytes
  assert (BU.length bs == sz)
  where
    generateBytes = do
      g <- createGadget g'
      initialize g (getCxt bsiv)
      genBytes g sz
    createGadget :: StreamGadget g => g -> IO (RandomSource g)
    createGadget _ = newGadget

tests :: [Test]
tests = [ testProperty "AES CTR 128"
          $ prop_length (undefined :: (CPortable128 CTR Encryption)) ]<commit_msg>fixed the raaz-random test<commit_after>{-# LANGUAGE FlexibleContexts #-}
module Modules.Stream (tests) where

import           Control.Applicative                  ((<$>))
import           Data.ByteString                      (ByteString)
import qualified Data.ByteString                      as BS
import           Test.Framework                       (Test)
import           Test.Framework.Providers.QuickCheck2 (testProperty)
import           Test.QuickCheck
import           Test.QuickCheck.Monadic              (run, assert, monadicIO)

import           Raaz.Primitives
import           Raaz.Primitives.Cipher
import qualified Raaz.Util.ByteString                 as BU
import           Raaz.Memory
import           Raaz.Types

import           Raaz.Cipher.AES.Type
import           Raaz.Cipher.AES.CTR

import           Raaz.Random

-- | Type to capture only integers from 1 to 10
newtype Sized = Sized (BYTES Int) deriving Show

instance Arbitrary Sized where
  arbitrary = Sized . BYTES <$> choose (0,100000)

data TestIV g = TestIV ByteString deriving Show

instance Initializable p => Arbitrary (TestIV p) where
  arbitrary = gen undefined
    where
      gen :: Initializable p => p -> Gen (TestIV p)
      gen p = TestIV . BS.pack <$> vectorOf (fromIntegral $ cxtSize p) arbitrary

prop_length :: (StreamGadget g, Initializable (PrimitiveOf g))
            => g
            -> TestIV (PrimitiveOf g)
            -> Sized    -- ^ Number of bytes to generate
            -> Property
prop_length g' (TestIV bsiv) (Sized sz) = monadicIO $ do
  bs <- run $ generateBytes
  assert (BU.length bs == sz)
  where
    generateBytes = do
      g <- createGadget g'
      initialize g (getCxt bsiv)
      genBytes g sz
    createGadget :: StreamGadget g => g -> IO (RandomSource g)
    createGadget _ = newGadget

tests :: [Test]
tests = [ testProperty "AES CTR 128"
          $ prop_length (undefined :: (CGadget (Cipher AES KEY128 CTR Encryption))) ]
{'fraction_non_alphanumeric': 0.0812274368231047, 'fraction_numerical': 0.008767405879319236, 'mean_word_length': 2.083465818759936, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3380572', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1091, 'n_words': 354}