summaryrefslogtreecommitdiff
path: root/Data/OpenPGP.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-07-03 03:47:22 -0400
committerJoe Crayne <joe@jerkface.net>2019-07-03 03:47:22 -0400
commita35b7f7517b6d4c351d95acba3b87aa786c90f05 (patch)
tree8428daf69832da7457e9e05b9beefcacee9f1adb /Data/OpenPGP.hs
parent660d5f111fee62ded78ffb622b063e4818c32928 (diff)
More big-num changes.
Diffstat (limited to 'Data/OpenPGP.hs')
-rw-r--r--Data/OpenPGP.hs11
1 files changed, 4 insertions, 7 deletions
diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs
index 74223b2..6667f1a 100644
--- a/Data/OpenPGP.hs
+++ b/Data/OpenPGP.hs
@@ -1005,9 +1005,7 @@ 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 flip fix (B.length bytes - 1) $ \loop j -> do 1008 putSomeByteString bytes
1009 put (B.index bytes j)
1010 when (j /= 0) $ loop (j - 1)
1011 | otherwise = fail $ "MPI is less than 0: " ++ show i 1009 | otherwise = fail $ "MPI is less than 0: " ++ show i
1012 where 1010 where
1013 (bytes, bitl) 1011 (bytes, bitl)
@@ -1015,16 +1013,15 @@ instance BINARY_CLASS MPI where
1015 | otherwise = 1013 | otherwise =
1016 (bytes', (fromIntegral (B.length bytes') - 1) * 8 + sigBit) 1014 (bytes', (fromIntegral (B.length bytes') - 1) * 8 + sigBit)
1017 1015
1018 sigBit = fst $ until ((==0) . snd) 1016 sigBit = fromIntegral $ 8 - countLeadingZeros (B.index bytes 0)
1019 (first (+1) . second (`shiftR` 1)) (0,B.last bytes) 1017 bytes' = B.reverse $ B.unfoldr (\x ->
1020 bytes' = B.unfoldr (\x ->
1021 if x == 0 then Nothing else 1018 if x == 0 then Nothing else
1022 Just (fromIntegral x, x `shiftR` 8) 1019 Just (fromIntegral x, x `shiftR` 8)
1023 ) i 1020 ) i
1024 get = do 1021 get = do
1025 length <- fmap fromIntegral (get :: Get Word16) 1022 length <- fmap fromIntegral (get :: Get Word16)
1026 bytes <- getSomeByteString =<< assertProp (>0) ((length + 7) `div` 8) 1023 bytes <- getSomeByteString =<< assertProp (>0) ((length + 7) `div` 8)
1027 return $ MPI $ B.foldl (\a b -> (a `shiftL` 8) + fromIntegral b) 0 bytes 1024 return $ MPI $ getBigNum (B.toStrict bytes)
1028 1025
1029listUntilEnd :: (BINARY_CLASS a) => Get [a] 1026listUntilEnd :: (BINARY_CLASS a) => Get [a]
1030listUntilEnd = do 1027listUntilEnd = do