Test LE serialization
This commit is contained in:
parent
6e1b6fdb90
commit
393aeac8cd
@ -7,10 +7,10 @@ compiler: ghc-8.6 lts-13.3
|
|||||||
# options
|
# options
|
||||||
# option: alias x=y z=v
|
# option: alias x=y z=v
|
||||||
option: gaugedeps extradep=gauge-0.2.1
|
option: gaugedeps extradep=gauge-0.2.1
|
||||||
option: basementmin extradep=basement-0.0.6 extradep=foundation-0.0.19 extradep=memory-0.14.14
|
option: basementmin extradep=basement-0.0.8 extradep=memory-0.14.18
|
||||||
|
|
||||||
# builds
|
# builds
|
||||||
build: ghc-8.2
|
build: ghc-8.2 basementmin
|
||||||
build: ghc-8.0 basementmin gaugedeps
|
build: ghc-8.0 basementmin gaugedeps
|
||||||
build: ghc-8.0 basementmin gaugedeps os=osx
|
build: ghc-8.0 basementmin gaugedeps os=osx
|
||||||
build: ghc-8.4
|
build: ghc-8.4
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# ~*~ auto-generated by haskell-ci with config : 8f74deffc95fd794fa2996c167c6543bbfab1ae432f0a83e0898f0b5871a92eb ~*~
|
# ~*~ auto-generated by haskell-ci with config : 68149dea5ea6ea0dcbeebc12e2f77fd3f4f0166e8666f9dccd49bae65e2df32c ~*~
|
||||||
|
|
||||||
# Use new container infrastructure to enable caching
|
# Use new container infrastructure to enable caching
|
||||||
sudo: false
|
sudo: false
|
||||||
@ -49,15 +49,15 @@ script:
|
|||||||
# create the build stack.yaml
|
# create the build stack.yaml
|
||||||
case "$RESOLVER" in
|
case "$RESOLVER" in
|
||||||
ghc-8.2)
|
ghc-8.2)
|
||||||
echo "{ resolver: lts-11.22, packages: [ '.' ], extra-deps: [], flags: {} }" > stack.yaml
|
echo "{ resolver: lts-11.22, packages: [ '.' ], extra-deps: [ basement-0.0.8, memory-0.14.18 ], flags: {} }" > stack.yaml
|
||||||
stack --no-terminal build --install-ghc --coverage --test --bench --no-run-benchmarks --haddock --no-haddock-deps
|
stack --no-terminal build --install-ghc --coverage --test --bench --no-run-benchmarks --haddock --no-haddock-deps
|
||||||
;;
|
;;
|
||||||
ghc-8.0)
|
ghc-8.0)
|
||||||
echo "{ resolver: lts-9.21, packages: [ '.' ], extra-deps: [ basement-0.0.6, foundation-0.0.19, memory-0.14.14, gauge-0.2.1 ], flags: {} }" > stack.yaml
|
echo "{ resolver: lts-9.21, packages: [ '.' ], extra-deps: [ basement-0.0.8, memory-0.14.18, gauge-0.2.1 ], flags: {} }" > stack.yaml
|
||||||
stack --no-terminal build --install-ghc --coverage --test --bench --no-run-benchmarks --haddock --no-haddock-deps
|
stack --no-terminal build --install-ghc --coverage --test --bench --no-run-benchmarks --haddock --no-haddock-deps
|
||||||
;;
|
;;
|
||||||
ghc-8.0)
|
ghc-8.0)
|
||||||
echo "{ resolver: lts-9.21, packages: [ '.' ], extra-deps: [ basement-0.0.6, foundation-0.0.19, memory-0.14.14, gauge-0.2.1 ], flags: {} }" > stack.yaml
|
echo "{ resolver: lts-9.21, packages: [ '.' ], extra-deps: [ basement-0.0.8, memory-0.14.18, gauge-0.2.1 ], flags: {} }" > stack.yaml
|
||||||
stack --no-terminal build --install-ghc --coverage --test --bench --no-run-benchmarks --haddock --no-haddock-deps
|
stack --no-terminal build --install-ghc --coverage --test --bench --no-run-benchmarks --haddock --no-haddock-deps
|
||||||
;;
|
;;
|
||||||
ghc-8.4)
|
ghc-8.4)
|
||||||
|
|||||||
@ -239,7 +239,7 @@ Library
|
|||||||
Build-depends: base
|
Build-depends: base
|
||||||
|
|
||||||
Build-depends: bytestring
|
Build-depends: bytestring
|
||||||
, memory >= 0.14.14
|
, memory >= 0.14.18
|
||||||
, basement >= 0.0.6
|
, basement >= 0.0.6
|
||||||
, ghc-prim
|
, ghc-prim
|
||||||
ghc-options: -Wall -fwarn-tabs -optc-O3
|
ghc-options: -Wall -fwarn-tabs -optc-O3
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
# ~*~ auto-generated by haskell-ci with config : 8f74deffc95fd794fa2996c167c6543bbfab1ae432f0a83e0898f0b5871a92eb ~*~
|
# ~*~ auto-generated by haskell-ci with config : 68149dea5ea6ea0dcbeebc12e2f77fd3f4f0166e8666f9dccd49bae65e2df32c ~*~
|
||||||
{ resolver: lts-13.2, packages: [ '.' ], extra-deps: [], flags: {} }
|
{ resolver: lts-13.3, packages: [ '.' ], extra-deps: [], flags: {} }
|
||||||
|
|
||||||
|
|||||||
@ -4,9 +4,11 @@ module Number (tests) where
|
|||||||
import Imports
|
import Imports
|
||||||
|
|
||||||
import Data.ByteArray (Bytes)
|
import Data.ByteArray (Bytes)
|
||||||
|
import qualified Data.ByteArray as B
|
||||||
import Crypto.Number.Basic
|
import Crypto.Number.Basic
|
||||||
import Crypto.Number.Generate
|
import Crypto.Number.Generate
|
||||||
import Crypto.Number.Serialize
|
import qualified Crypto.Number.Serialize as BE
|
||||||
|
import qualified Crypto.Number.Serialize.LE as LE
|
||||||
import Crypto.Number.Prime
|
import Crypto.Number.Prime
|
||||||
import Data.Bits
|
import Data.Bits
|
||||||
|
|
||||||
@ -50,14 +52,24 @@ tests = testGroup "number"
|
|||||||
bits = 6 + baseBits
|
bits = 6 + baseBits
|
||||||
prime = withTestDRG testDRG $ generateSafePrime bits
|
prime = withTestDRG testDRG $ generateSafePrime bits
|
||||||
in bits == numBits prime
|
in bits == numBits prime
|
||||||
, testProperty "marshalling" $ \qaInt ->
|
|
||||||
getQAInteger qaInt == os2ip (i2osp (getQAInteger qaInt) :: Bytes)
|
|
||||||
, testProperty "as-power-of-2-and-odd" $ \n ->
|
, testProperty "as-power-of-2-and-odd" $ \n ->
|
||||||
let (e, a1) = asPowerOf2AndOdd n
|
let (e, a1) = asPowerOf2AndOdd n
|
||||||
in n == (2^e)*a1
|
in n == (2^e)*a1
|
||||||
|
, testProperty "marshalling-be" $ \qaInt ->
|
||||||
|
getQAInteger qaInt == BE.os2ip (BE.i2osp (getQAInteger qaInt) :: Bytes)
|
||||||
|
, testProperty "marshalling-le" $ \qaInt ->
|
||||||
|
getQAInteger qaInt == LE.os2ip (LE.i2osp (getQAInteger qaInt) :: Bytes)
|
||||||
|
, testProperty "be-rev-le" $ \qaInt ->
|
||||||
|
getQAInteger qaInt == LE.os2ip (B.reverse (BE.i2osp (getQAInteger qaInt) :: Bytes))
|
||||||
|
, testProperty "be-rev-le-40" $ \qaInt ->
|
||||||
|
getQAInteger qaInt == LE.os2ip (B.reverse (BE.i2ospOf_ 40 (getQAInteger qaInt) :: Bytes))
|
||||||
|
, testProperty "le-rev-be" $ \qaInt ->
|
||||||
|
getQAInteger qaInt == BE.os2ip (B.reverse (LE.i2osp (getQAInteger qaInt) :: Bytes))
|
||||||
|
, testProperty "le-rev-be-40" $ \qaInt ->
|
||||||
|
getQAInteger qaInt == BE.os2ip (B.reverse (LE.i2ospOf_ 40 (getQAInteger qaInt) :: Bytes))
|
||||||
, testGroup "marshalling-kat-to-bytearray" $ map toSerializationKat $ zip [katZero..] serializationVectors
|
, testGroup "marshalling-kat-to-bytearray" $ map toSerializationKat $ zip [katZero..] serializationVectors
|
||||||
, testGroup "marshalling-kat-to-integer" $ map toSerializationKatInteger $ zip [katZero..] serializationVectors
|
, testGroup "marshalling-kat-to-integer" $ map toSerializationKatInteger $ zip [katZero..] serializationVectors
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
toSerializationKat (i, (sz, n, ba)) = testCase (show i) (ba @=? i2ospOf_ sz n)
|
toSerializationKat (i, (sz, n, ba)) = testCase (show i) (ba @=? BE.i2ospOf_ sz n)
|
||||||
toSerializationKatInteger (i, (_, n, ba)) = testCase (show i) (n @=? os2ip ba)
|
toSerializationKatInteger (i, (_, n, ba)) = testCase (show i) (n @=? BE.os2ip ba)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user