diff options
Diffstat (limited to 'Data/OpenPGP')
-rw-r--r-- | Data/OpenPGP/Internal.hs | 20 |
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 @@ | |||
1 | module Data.OpenPGP.Internal where | ||
2 | |||
3 | import Data.Word | ||
4 | import Data.Bits | ||
5 | |||
6 | decode_s2k_count :: Word8 -> Word32 | ||
7 | decode_s2k_count c = (16 + (fromIntegral c .&. 15)) `shiftL` | ||
8 | ((fromIntegral c `shiftR` 4) + 6) | ||
9 | |||
10 | encode_s2k_count :: Word32 -> Word8 | ||
11 | encode_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) | ||