debugged computation bug in ByteString to UInteger conversion

likely caused by an overflow, but don't have time to investigate
This commit is contained in:
Trolli Schmittlauch 2020-03-20 01:21:00 +01:00
parent 2d05d0644d
commit b41acaf52a

View file

@ -3,7 +3,6 @@ module Foo where
import Crypto.Hash import Crypto.Hash
import Data.Word import Data.Word
import Data.Bits (shift)
import Network.Socket (HostAddress6) import Network.Socket (HostAddress6)
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
import qualified Data.ByteString.Builder as BB import qualified Data.ByteString.Builder as BB
@ -46,7 +45,7 @@ byteStringToUInteger bs = sum $ parsedBytes 0 bs
parseWithOffset :: Integer -> Word8 -> Integer parseWithOffset :: Integer -> Word8 -> Integer
parseWithOffset 0 word = toInteger word -- a shift of 0 is always 0 parseWithOffset 0 word = toInteger word -- a shift of 0 is always 0
parseWithOffset offset word = shift (toInteger word) 8*offset parseWithOffset offset word = toInteger word * 2^(8 * offset)
-- |Utility function creating a strict ByteString from [Word32], -- |Utility function creating a strict ByteString from [Word32],
-- needed for encoding @HostAddress6@ as a ByteString -- needed for encoding @HostAddress6@ as a ByteString