packages feed

RFC1751 0.3.0.1 → 0.3.1.0

raw patch · 3 files changed

+20/−21 lines, 3 filesdep +vectornew-uploaderPVP ok

version bump matches the API change (PVP)

Dependencies added: vector

API changes (from Hackage documentation)

Files

Data/RFC1751.hs view
@@ -13,7 +13,8 @@ import qualified Data.ByteString.Lazy as BL import Data.Bits import Data.Char-import Data.List+import Data.Vector (Vector, (!), fromList)+import qualified Data.Vector as V  encodeWord64 :: Word64 -> ByteString encodeWord64 = BS.concat . BL.toChunks . encode@@ -25,7 +26,7 @@ mnemonicToKey :: String -> Maybe ByteString mnemonicToKey s = do     guard $ length ws == 12-    BS.concat <$> mapM ((encodeWord64 <$>) . wordsToKey) [ws1, ws2]+    BS.concat <$> mapM ((encodeWord64 <$>) . wordsToKey) [fromList ws1, fromList ws2]   where     ws = words $ map toUpper s     (ws1, ws2) = splitAt 6 ws@@ -40,21 +41,21 @@  keyToWords :: Word64 -> [String] keyToWords key =-    map ((dict !!) . fromIntegral) indices+    map ((dict !) . fromIntegral) indices   where     keyCheckSum = checkSum key     tempIndices = map (\start -> extract key start 11) [0,11..55]     indices = init tempIndices ++ [last tempIndices .|. keyCheckSum] -wordsToKey :: [String] -> Maybe Word64+wordsToKey :: Vector String -> Maybe Word64 wordsToKey ws = do-    let findWord w   = fromIntegral <$> elemIndex w dict-        maybeIndices = sequence $ map findWord ws+    let findWord w   = fromIntegral <$> V.elemIndex w dict+        maybeIndices = V.sequence $ V.map findWord ws     indices <- maybeIndices     let buildKey acc (bits, index) = (index `shift` bits) .|. acc-        key = foldl buildKey 0 $ zip [53,42..(-2)] indices+        key = V.foldl buildKey 0 $ V.zip (fromList [53,42..(-2)]) indices         computedSum = checkSum key-        providedSum = last indices .&. 0x03+        providedSum = V.last indices .&. 0x03     guard $ providedSum == computedSum     return key @@ -62,7 +63,7 @@ checkSum key =     pairSum .&. 0x03   where-    pairSum = sum $ map (flip (extract key) $ 2) [0,2..62]+    pairSum = sum $ map (flip (extract key) 2) [0,2..62]  extract :: Word64 -> Int -> Int -> Word64 extract key start len =@@ -72,8 +73,8 @@     mask = complement $ 0xffffffffffffffff `shiftL` count     temp = key `shiftR` (64 - start - count) .&. mask -dict :: [String]-dict =+dict :: Vector String+dict = fromList   [ "A", "ABE", "ACE", "ACT", "AD", "ADA", "ADD", "AGO", "AID"   , "AIM", "AIR", "ALL", "ALP", "AM", "AMY", "AN", "ANA", "AND"   , "ANN", "ANT", "ANY", "APE", "APS", "APT", "ARC", "ARE", "ARK"
RFC1751.cabal view
@@ -1,8 +1,5 @@--- Initial RFC1751.cabal generated by cabal init.  For further --- documentation, see http://haskell.org/cabal/users-guide/- name:                RFC1751-version:             0.3.0.1+version:             0.3.1.0 synopsis:            RFC-1751 library for Haskell description:         Convert 128-bit ByteString to/from 12 English words. homepage:            https://github.com/xenog/RFC1751@@ -10,22 +7,22 @@ license-file:        UNLICENSE author:              Jean-Pierre Rupp maintainer:          root@haskoin.com--- copyright:            category:            Data build-type:          Simple cabal-version:       >=1.8  source-repository head     type:     git-    location: https://github.com/xenog/RFC1751.git+    location: https://github.com/xenog/rfc-1751.git  library   exposed-modules:   Data.RFC1751   build-depends:     base ==4.*,                      binary,-                     bytestring+                     bytestring,+                     vector -test-suite test-haskoin-crypto+test-suite test-rfc1751     type:              exitcode-stdio-1.0     main-is:           Main.hs     other-modules:     Tests,@@ -33,6 +30,7 @@     build-depends:     base,                        binary,                        bytestring,+                       vector,                        RFC1751,                        QuickCheck,                        test-framework,
tests/Units.hs view
@@ -86,7 +86,7 @@     | otherwise = error "integerToBS not defined for negative values"   where      f 0 = Nothing-    f x = Just $ (fromInteger x :: Word8, x `shiftR` 8)+    f x = Just (fromInteger x :: Word8, x `shiftR` 8)  hexToBS :: String -> ByteString hexToBS str@@ -97,7 +97,7 @@     z2    = BS.replicate (fromIntegral $ length z `div` 2) 0     r1    = readHex r     r2 | null r    = BS.empty-       | null r1   = error $ "cannot read hex"+       | null r1   = error "cannot read hex"        | otherwise = integerToBS $ fst $ head r1  vectors :: [TestVector]