summaryrefslogtreecommitdiff
path: root/Data/OpenPGP/Util/Sign.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2013-12-14 23:14:16 -0500
committerjoe <joe@jerkface.net>2013-12-14 23:14:16 -0500
commit6b42fc6904d05979c409c0043d6d7b2eed22b58c (patch)
tree0cccb442aa3ab4f17ee54e63ae80ca240fbb5b8e /Data/OpenPGP/Util/Sign.hs
parentce0d32ef83ccf15198bdd5248faa02abbcf2f769 (diff)
Refactoring.
Diffstat (limited to 'Data/OpenPGP/Util/Sign.hs')
-rw-r--r--Data/OpenPGP/Util/Sign.hs56
1 files changed, 2 insertions, 54 deletions
diff --git a/Data/OpenPGP/Util/Sign.hs b/Data/OpenPGP/Util/Sign.hs
index ef7d16b..e492f95 100644
--- a/Data/OpenPGP/Util/Sign.hs
+++ b/Data/OpenPGP/Util/Sign.hs
@@ -17,28 +17,8 @@ import qualified Crypto.Random as Vincent
17import qualified Crypto.PubKey.DSA as Vincent.DSA 17import qualified Crypto.PubKey.DSA as Vincent.DSA
18import qualified Crypto.PubKey.RSA as Vincent.RSA 18import qualified Crypto.PubKey.RSA as Vincent.RSA
19import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA 19import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA
20import Crypto.PubKey.HashDescr as Vincent 20
21 21import Data.OpenPGP.Util.Base
22import Crypto.Hash.MD5 as MD5
23import Crypto.Hash.SHA1 as SHA1
24import Crypto.Hash.SHA256 as SHA256
25import Crypto.Hash.SHA384 as SHA384
26import Crypto.Hash.SHA512 as SHA512
27import Crypto.Hash.SHA224 as SHA224
28import Crypto.Hash.RIPEMD160 as RIPEMD160
29
30hashAlgoDesc OpenPGP.MD5 = Vincent.hashDescrMD5
31hashAlgoDesc OpenPGP.SHA1 = Vincent.hashDescrSHA1
32hashAlgoDesc OpenPGP.RIPEMD160 = Vincent.hashDescrRIPEMD160
33hashAlgoDesc OpenPGP.SHA256 = Vincent.hashDescrSHA256
34hashAlgoDesc OpenPGP.SHA384 = Vincent.hashDescrSHA384
35hashAlgoDesc OpenPGP.SHA512 = Vincent.hashDescrSHA512
36hashAlgoDesc OpenPGP.SHA224 = Vincent.hashDescrSHA224
37hashAlgoDesc _ =
38 error "Unsupported HashAlgorithm in hashAlgoDesc"
39
40find_key :: OpenPGP.Message -> String -> Maybe OpenPGP.Packet
41find_key = OpenPGP.find_key fingerprint
42 22
43 23
44privateDSAkey :: OpenPGP.Packet -> Vincent.DSA.PrivateKey 24privateDSAkey :: OpenPGP.Packet -> Vincent.DSA.PrivateKey
@@ -58,38 +38,6 @@ privateRSAkey k =
58 q = keyParam 'q' k 38 q = keyParam 'q' k
59 pubkey = rsaKey k 39 pubkey = rsaKey k
60 40
61rsaKey :: OpenPGP.Packet -> Vincent.RSA.PublicKey
62rsaKey k =
63 Vincent.RSA.PublicKey (integerBytesize n) n (keyParam 'e' k)
64 where
65 n = keyParam 'n' k
66
67integerBytesize :: Integer -> Int
68integerBytesize i = fromIntegral $ LZ.length (encode (OpenPGP.MPI i)) - 2
69
70
71toStrictBS :: LZ.ByteString -> BS.ByteString
72toStrictBS = BS.concat . LZ.toChunks
73
74toLazyBS :: BS.ByteString -> LZ.ByteString
75toLazyBS = LZ.fromChunks . (:[])
76
77
78keyParam :: Char -> OpenPGP.Packet -> Integer
79keyParam c k = fromJustMPI $ lookup c (OpenPGP.key k)
80fromJustMPI :: Maybe OpenPGP.MPI -> Integer
81fromJustMPI (Just (OpenPGP.MPI x)) = x
82fromJustMPI _ = error "Not a Just MPI, Data.OpenPGP.CryptoAPI"
83
84hashBySymbol OpenPGP.MD5 = MD5.hashlazy
85hashBySymbol OpenPGP.SHA1 = SHA1.hashlazy
86hashBySymbol OpenPGP.SHA256 = SHA256.hashlazy
87hashBySymbol OpenPGP.SHA384 = SHA384.hashlazy
88hashBySymbol OpenPGP.SHA512 = SHA512.hashlazy
89hashBySymbol OpenPGP.SHA224 = SHA224.hashlazy
90hashBySymbol OpenPGP.RIPEMD160 = RIPEMD160.hashlazy
91
92
93 41
94 42
95-- | Make a signature 43-- | Make a signature