memory 0.14.13 → 0.14.14
raw patch · 6 files changed
+51/−11 lines, 6 files
Files
- CHANGELOG.md +5/−0
- Data/Memory/Encoding/Base32.hs +2/−2
- Data/Memory/Encoding/Base64.hs +1/−1
- README.md +7/−5
- memory.cabal +2/−1
- tests/Tests.hs +34/−2
CHANGELOG.md view
@@ -1,3 +1,8 @@+## 0.14.14++* Fix bounds issues with empty strings in base64 and base32+* Improve tests compatibility w.r.t old basement version+ ## 0.14.13 * Handle compat SPECIALIZE for older GHC
Data/Memory/Encoding/Base32.hs view
@@ -58,7 +58,7 @@ -> Int -- index output -> IO () loop i di- | i > len = return ()+ | i >= len = return () | otherwise = do i1 <- peekByteOff src i i2 <- peekOrZero (i + 1)@@ -111,6 +111,7 @@ -- if the length is not a multiple of 8, Nothing is returned unBase32Length :: Ptr Word8 -> Int -> IO (Maybe Int) unBase32Length src len+ | len < 1 = return $ Just 0 | (len `mod` 8) /= 0 = return Nothing | otherwise = do last1Byte <- peekByteOff src (len - 1)@@ -250,4 +251,3 @@ \\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\ \\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\ \\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"#-
Data/Memory/Encoding/Base64.hs view
@@ -104,7 +104,7 @@ -- if the length is not a multiple of 4, Nothing is returned unBase64Length :: Ptr Word8 -> Int -> IO (Maybe Int) unBase64Length src len- | len < 1 = return Nothing+ | len < 1 = return $ Just 0 | (len `mod` 4) /= 0 = return Nothing | otherwise = do last1Byte <- peekByteOff src (len - 1)
README.md view
@@ -50,9 +50,11 @@ On the following haskell versions: -* GHC 7.0.x-* GHC 7.4.x-* GHC 7.6.x-* GHC 7.8.x-* GHC 7.10.x+* GHC 7.10+* GHC 8.0+* GHC 8.2++Some older versions or different systems are possibly working too++
memory.cabal view
@@ -1,5 +1,5 @@ Name: memory-version: 0.14.13+version: 0.14.14 Synopsis: memory and related abstraction stuff Description: Chunk of memory, polymorphic byte array management and manipulation@@ -110,6 +110,7 @@ SipHash Utils Build-Depends: base >= 3 && < 5+ , bytestring , tasty , tasty-quickcheck , tasty-hunit
tests/Tests.hs view
@@ -7,6 +7,7 @@ import Utils import Data.Char (chr) import Data.Word+import qualified Data.ByteString as BS import Data.ByteArray (Bytes, ScrubbedBytes, ByteArray) import qualified Data.ByteArray as B import qualified Data.ByteArray.Encoding as B@@ -16,14 +17,19 @@ #ifdef WITH_FOUNDATION_SUPPORT import qualified Foundation as F+#if MIN_VERSION_basement(0,0,5) import Basement.Block (Block)+#endif import Basement.UArray (UArray) #endif data Backend = BackendByte | BackendScrubbedBytes #ifdef WITH_FOUNDATION_SUPPORT- | BackendBlock | BackendUArray+#if MIN_VERSION_basement(0,0,5)+ | BackendBlock #endif+ | BackendUArray+#endif deriving (Show,Eq,Bounded,Enum) allBackends :: [Backend]@@ -38,7 +44,9 @@ BackendByte -> ArbitraryBS `fmap` ((B.pack `fmap` replicateM n arbitrary) :: Gen Bytes) BackendScrubbedBytes -> ArbitraryBS `fmap` ((B.pack `fmap` replicateM n arbitrary) :: Gen ScrubbedBytes) #ifdef WITH_FOUNDATION_SUPPORT+#if MIN_VERSION_basement(0,0,5) BackendBlock -> ArbitraryBS `fmap` ((B.pack `fmap` replicateM n arbitrary) :: Gen (Block Word8))+#endif BackendUArray -> ArbitraryBS `fmap` ((B.pack `fmap` replicateM n arbitrary) :: Gen (UArray Word8)) #endif @@ -69,7 +77,7 @@ #if MIN_VERSION_basement(0,0,5) , testGroup "Block" (l withBlockWitness) #endif- , testGroup "UArray" (l withBlockWitness)+ , testGroup "UArray" (l withUArrayWitness) #endif ] @@ -92,6 +100,7 @@ , ("easure.", "ZWFzdXJlLg==") , ("asure.", "YXN1cmUu") , ("sure.", "c3VyZS4=")+ , ("", "") ] base64URLKats =@@ -161,6 +170,28 @@ outbs = B.convertFromBase base $ witnessID $ B.pack $ unS out in Right inpbs @=? outbs +-- check not to touch internal null pointer of the empty ByteString+bsNullEncodingTest =+ testGroup "BS-null"+ [ testGroup "BASE64"+ [ testCase "encode-KAT" $ toTest B.Base64+ , testCase "decode-KAT" $ toBackTest B.Base64+ ]+ , testGroup "BASE32"+ [ testCase "encode-KAT" $ toTest B.Base32+ , testCase "decode-KAT" $ toBackTest B.Base32+ ]+ , testGroup "BASE16"+ [ testCase "encode-KAT" $ toTest B.Base16+ , testCase "decode-KAT" $ toBackTest B.Base16+ ]+ ]+ where+ toTest base =+ B.convertToBase base BS.empty @=? BS.empty+ toBackTest base =+ B.convertFromBase base BS.empty @=? Right BS.empty+ parsingTests witnessID = [ testCase "parse" $ let input = witnessID $ B.pack $ unS "xx abctest"@@ -174,6 +205,7 @@ main = defaultMain $ testGroup "memory" [ localOption (QuickCheckTests 5000) $ testGroupBackends "basic" basicProperties+ , bsNullEncodingTest , testGroupBackends "encoding" encodingTests , testGroupBackends "parsing" parsingTests , testGroupBackends "hashing" $ \witnessID ->