summaryrefslogtreecommitdiff
path: root/Data/OpenPGP
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2016-04-14 12:50:25 -0400
committerjoe <joe@jerkface.net>2016-04-14 12:51:36 -0400
commit47fbb4b70ee6c74937ed4b55540b612aacc3de80 (patch)
tree3d3577a0e3706512cd2c49938e91acf72e203249 /Data/OpenPGP
parent880f16b4e52bbf96dd531c1c4b864423b057b770 (diff)
parent37d5a99e9f2303780a7cdbf4730ace6eff58a466 (diff)
Merged openpgp package into openpgp-util
Diffstat (limited to 'Data/OpenPGP')
-rw-r--r--Data/OpenPGP/Internal.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/Data/OpenPGP/Internal.hs b/Data/OpenPGP/Internal.hs
new file mode 100644
index 0000000..b2bd506
--- /dev/null
+++ b/Data/OpenPGP/Internal.hs
@@ -0,0 +1,20 @@
1module Data.OpenPGP.Internal where
2
3import Data.Word
4import Data.Bits
5
6decode_s2k_count :: Word8 -> Word32
7decode_s2k_count c = (16 + (fromIntegral c .&. 15)) `shiftL`
8 ((fromIntegral c `shiftR` 4) + 6)
9
10encode_s2k_count :: Word32 -> Word8
11encode_s2k_count iterations
12 | iterations >= 65011712 = 255
13 | decode_s2k_count result < iterations = result+1
14 | otherwise = result
15 where
16 result = fromIntegral $ (fromIntegral c `shiftL` 4) .|. (count - 16)
17 (count, c) = encode_s2k_count' (iterations `shiftR` 6) (0::Word8)
18 encode_s2k_count' count c
19 | count < 32 = (count, c)
20 | otherwise = encode_s2k_count' (count `shiftR` 1) (c+1)