blob: b2bd506675c9a236885a5b33ee329f4e0aa556b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
module Data.OpenPGP.Internal where
import Data.Word
import Data.Bits
decode_s2k_count :: Word8 -> Word32
decode_s2k_count c = (16 + (fromIntegral c .&. 15)) `shiftL`
((fromIntegral c `shiftR` 4) + 6)
encode_s2k_count :: Word32 -> Word8
encode_s2k_count iterations
| iterations >= 65011712 = 255
| decode_s2k_count result < iterations = result+1
| otherwise = result
where
result = fromIntegral $ (fromIntegral c `shiftL` 4) .|. (count - 16)
(count, c) = encode_s2k_count' (iterations `shiftR` 6) (0::Word8)
encode_s2k_count' count c
| count < 32 = (count, c)
| otherwise = encode_s2k_count' (count `shiftR` 1) (c+1)
|