summaryrefslogtreecommitdiff
path: root/Data/OpenPGP.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Data/OpenPGP.hs')
-rw-r--r--Data/OpenPGP.hs13
1 files changed, 2 insertions, 11 deletions
diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs
index 6667f1a..8fef50a 100644
--- a/Data/OpenPGP.hs
+++ b/Data/OpenPGP.hs
@@ -1005,19 +1005,10 @@ instance BINARY_CLASS MPI where
1005 put (MPI i) 1005 put (MPI i)
1006 | i >= 0 = do 1006 | i >= 0 = do
1007 put (bitl :: Word16) 1007 put (bitl :: Word16)
1008 putSomeByteString bytes 1008 putSomeByteString $ B.fromStrict bytes
1009 | otherwise = fail $ "MPI is less than 0: " ++ show i 1009 | otherwise = fail $ "MPI is less than 0: " ++ show i
1010 where 1010 where
1011 (bytes, bitl) 1011 (bitl, bytes) = putBigNum i
1012 | B.null bytes' = (B.singleton 0, 1)
1013 | otherwise =
1014 (bytes', (fromIntegral (B.length bytes') - 1) * 8 + sigBit)
1015
1016 sigBit = fromIntegral $ 8 - countLeadingZeros (B.index bytes 0)
1017 bytes' = B.reverse $ B.unfoldr (\x ->
1018 if x == 0 then Nothing else
1019 Just (fromIntegral x, x `shiftR` 8)
1020 ) i
1021 get = do 1012 get = do
1022 length <- fmap fromIntegral (get :: Get Word16) 1013 length <- fmap fromIntegral (get :: Get Word16)
1023 bytes <- getSomeByteString =<< assertProp (>0) ((length + 7) `div` 8) 1014 bytes <- getSomeByteString =<< assertProp (>0) ((length + 7) `div` 8)