RFC1751 0.3.0.0 → 0.3.0.1
raw patch · 3 files changed
+17/−13 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- RFC1751.cabal +1/−1
- tests/Tests.hs +7/−3
- tests/Units.hs +9/−9
RFC1751.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: RFC1751-version: 0.3.0.0+version: 0.3.0.1 synopsis: RFC-1751 library for Haskell description: Convert 128-bit ByteString to/from 12 English words. homepage: https://github.com/xenog/RFC1751
tests/Tests.hs view
@@ -3,6 +3,7 @@ import Control.Applicative import Data.Char import Data.Binary+import qualified Data.ByteString.Char8 as B8 import qualified Data.ByteString.Lazy.Char8 as L8 import Data.Maybe import Data.RFC1751@@ -18,21 +19,24 @@ ] ] +toStrict :: L8.ByteString -> B8.ByteString+toStrict = B8.concat . L8.toChunks+ decodeEncode :: (Word64, Word64) -> Bool decodeEncode (w1, w2) = fromMaybe False $ (== bs) <$> (mnemonicToKey =<< keyToMnemonic bs) where- bs = encode w1 `L8.append` encode w2+ bs = toStrict $ encode w1 `L8.append` encode w2 decodeEncodeLC :: (Word64, Word64) -> Bool decodeEncodeLC (w1, w2) = fromMaybe False $ (== bs) <$> (mnemonicToKey =<< map toLower <$> keyToMnemonic bs) where- bs = encode w1 `L8.append` encode w2+ bs = toStrict $ encode w1 `L8.append` encode w2 doubleWord64 :: Word64 -> Bool doubleWord64 w = fromMaybe False $ do (\(x, y) -> x == y) . splitAt 6 . words <$> keyToMnemonic bs where- bs = encode w `L8.append` encode w+ bs = toStrict $ encode w `L8.append` encode w
tests/Units.hs view
@@ -2,8 +2,8 @@ import Control.Applicative -import Data.ByteString.Lazy (ByteString)-import qualified Data.ByteString.Lazy as BL+import Data.ByteString (ByteString)+import qualified Data.ByteString as BS import Data.Binary import Data.Bits import Data.Char@@ -80,9 +80,9 @@ (assertBool "wrong word" . isNothing $ mnemonicToKey s) integerToBS :: Integer -> ByteString-integerToBS 0 = BL.pack [0]+integerToBS 0 = BS.pack [0] integerToBS i - | i > 0 = BL.pack $ reverse $ unfoldr f i+ | i > 0 = BS.pack $ reverse $ unfoldr f i | otherwise = error "integerToBS not defined for negative values" where f 0 = Nothing@@ -90,13 +90,13 @@ hexToBS :: String -> ByteString hexToBS str- | null str = BL.empty- | otherwise = BL.append z2 r2+ | null str = BS.empty+ | otherwise = BS.append z2 r2 where (z,r) = span (== '0') $ filter (/= ' ') str- z2 = BL.replicate (fromIntegral $ length z `div` 2) 0+ z2 = BS.replicate (fromIntegral $ length z `div` 2) 0 r1 = readHex r- r2 | null r = BL.empty+ r2 | null r = BS.empty | null r1 = error $ "cannot read hex" | otherwise = integerToBS $ fst $ head r1 @@ -122,7 +122,7 @@ encodeTest :: (Int, TestVector) -> Test encodeTest (i, (bs, m)) = testCase ("Encode #" ++ show i)- (bs @=? fromMaybe BL.empty (mnemonicToKey m))+ (bs @=? fromMaybe BS.empty (mnemonicToKey m)) decodeTest :: (Int, TestVector) -> Test decodeTest (i, (bs, hk)) = testCase ("Decode #" ++ show i)