diff options
author | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-04-27 13:07:54 -0500 |
---|---|---|
committer | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-04-27 13:07:54 -0500 |
commit | 16f0cd61f101ad1de2da3b3445b7f31b124de317 (patch) | |
tree | 8a452edade6b91951bc8c189b185e57b7853beb9 /Data | |
parent | 2ed08625f7f56ab5c086498d47242299cff10e98 (diff) |
MPI encode/decode QuickCheck
Diffstat (limited to 'Data')
-rw-r--r-- | Data/OpenPGP.hs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs index bf7cdf5..63d4dc1 100644 --- a/Data/OpenPGP.hs +++ b/Data/OpenPGP.hs | |||
@@ -56,6 +56,7 @@ module Data.OpenPGP ( | |||
56 | 56 | ||
57 | import Numeric | 57 | import Numeric |
58 | import Control.Monad | 58 | import Control.Monad |
59 | import Control.Exception (assert) | ||
59 | import Data.Bits | 60 | import Data.Bits |
60 | import Data.Word | 61 | import Data.Word |
61 | import Data.Char | 62 | import Data.Char |
@@ -632,10 +633,11 @@ instance BINARY_CLASS MPI where | |||
632 | + 1 :: Word16) | 633 | + 1 :: Word16) |
633 | putSomeByteString bytes | 634 | putSomeByteString bytes |
634 | where | 635 | where |
635 | bytes = B.reverse $ B.unfoldr (\x -> | 636 | bytes = if B.null bytes' then B.singleton 0 else bytes' |
637 | bytes' = B.reverse $ B.unfoldr (\x -> | ||
636 | if x == 0 then Nothing else | 638 | if x == 0 then Nothing else |
637 | Just (fromIntegral x, x `shiftR` 8) | 639 | Just (fromIntegral x, x `shiftR` 8) |
638 | ) i | 640 | ) (assert (i>=0) i) |
639 | get = do | 641 | get = do |
640 | length <- fmap fromIntegral (get :: Get Word16) | 642 | length <- fmap fromIntegral (get :: Get Word16) |
641 | bytes <- getSomeByteString ((length + 7) `div` 8) | 643 | bytes <- getSomeByteString ((length + 7) `div` 8) |