summaryrefslogtreecommitdiff
path: root/Data
diff options
context:
space:
mode:
authorStephen Paul Weber <singpolyma@singpolyma.net>2012-04-27 10:54:16 -0500
committerStephen Paul Weber <singpolyma@singpolyma.net>2012-04-27 10:54:16 -0500
commit5b1532529dd4850e5b94730c628f8285c30d1771 (patch)
tree5a2a5db5630ae1512966047ea18b0f1d3d579a9e /Data
parent016decabcc3644dfbe16eaba35ec69d6c2b8bad2 (diff)
Hide internal stuff that is used by tests
Diffstat (limited to 'Data')
-rw-r--r--Data/OpenPGP.hs20
-rw-r--r--Data/OpenPGP/Internal.hs20
2 files changed, 22 insertions, 18 deletions
diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs
index 7c3e8ba..e48dcf6 100644
--- a/Data/OpenPGP.hs
+++ b/Data/OpenPGP.hs
@@ -51,8 +51,7 @@ module Data.OpenPGP (
51 find_key, 51 find_key,
52 fingerprint_material, 52 fingerprint_material,
53 signatures_and_data, 53 signatures_and_data,
54 signature_issuer, 54 signature_issuer
55 decode_s2k_count, encode_s2k_count
56) where 55) where
57 56
58import Numeric 57import Numeric
@@ -61,6 +60,7 @@ import Data.Bits
61import Data.Word 60import Data.Word
62import Data.Char 61import Data.Char
63import Data.Maybe 62import Data.Maybe
63import Data.OpenPGP.Internal
64import qualified Data.ByteString.Lazy as LZ 64import qualified Data.ByteString.Lazy as LZ
65 65
66#ifdef CEREAL 66#ifdef CEREAL
@@ -710,22 +710,6 @@ parse_signature_subpacket 16 = do
710parse_signature_subpacket tag = 710parse_signature_subpacket tag =
711 fmap (UnsupportedSignatureSubpacket tag) getRemainingByteString 711 fmap (UnsupportedSignatureSubpacket tag) getRemainingByteString
712 712
713decode_s2k_count :: Word8 -> Word32
714decode_s2k_count c = (16 + (fromIntegral c .&. 15)) `shiftL`
715 ((fromIntegral c `shiftR` 4) + 6)
716
717encode_s2k_count :: Word32 -> Word8
718encode_s2k_count iterations
719 | iterations >= 65011712 = 255
720 | decode_s2k_count result < iterations = result+1
721 | otherwise = result
722 where
723 result = fromIntegral $ (fromIntegral c `shiftL` 4) .|. (count - 16)
724 (count, c) = encode_s2k_count' (iterations `shiftR` 6) (0::Word8)
725 encode_s2k_count' count c
726 | count < 32 = (count, c)
727 | otherwise = encode_s2k_count' (count `shiftR` 1) (c+1)
728
729find_key :: (Packet -> String) -> Message -> String -> Maybe Packet 713find_key :: (Packet -> String) -> Message -> String -> Maybe Packet
730find_key fpr (Message (x@(PublicKeyPacket {}):xs)) keyid = 714find_key fpr (Message (x@(PublicKeyPacket {}):xs)) keyid =
731 find_key' fpr x xs keyid 715 find_key' fpr x xs keyid
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)