File: Tests.hs

package info (click to toggle)
haskell-secret-sharing 1.0.1.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 100 kB
  • sloc: haskell: 139; makefile: 5
file content (39 lines) | stat: -rw-r--r-- 1,038 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Main
where
import Data.Monoid
import Test.Framework
import Test.Framework.Providers.QuickCheck2
import Test.QuickCheck
import Data.Maybe
import qualified Data.List as L
import Control.Monad

import Data.ByteString.Lazy( ByteString )
import qualified Data.ByteString.Lazy as B

import Crypto.SecretSharing.Internal

instance Arbitrary ByteString where
    arbitrary   = fmap B.pack arbitrary

main :: IO ()
main = defaultMainWithOpts
       [ testProperty "encodingDecoding" propEncodingDecoding
       ] mempty

data ShareIdxs = ShareIdxs { shareIdxs :: [Int] }
  deriving (Show,Eq,Ord)
 
instance Arbitrary ShareIdxs where
  arbitrary = 
    liftM (ShareIdxs . L.nub) $ sequence [ choose (1,prime-1) 
                                         | i <- [1..(prime-1) `div` 2]]

propEncodingDecoding bstr idxs = ioProperty $ do
  shares <- encode 20 (prime-1) bstr 
  if null shares && B.null bstr
    then return True
    else do
      let chosen = [ shares !! (i-1) | i <- shareIdxs idxs ]  
      return (bstr == (decode chosen))