diff options
author | joe <joe@jerkface.net> | 2013-12-14 23:14:16 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2013-12-14 23:14:16 -0500 |
commit | 6b42fc6904d05979c409c0043d6d7b2eed22b58c (patch) | |
tree | 0cccb442aa3ab4f17ee54e63ae80ca240fbb5b8e /Data/OpenPGP/Util/Sign.hs | |
parent | ce0d32ef83ccf15198bdd5248faa02abbcf2f769 (diff) |
Refactoring.
Diffstat (limited to 'Data/OpenPGP/Util/Sign.hs')
-rw-r--r-- | Data/OpenPGP/Util/Sign.hs | 56 |
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 | |||
17 | import qualified Crypto.PubKey.DSA as Vincent.DSA | 17 | import qualified Crypto.PubKey.DSA as Vincent.DSA |
18 | import qualified Crypto.PubKey.RSA as Vincent.RSA | 18 | import qualified Crypto.PubKey.RSA as Vincent.RSA |
19 | import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA | 19 | import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA |
20 | import Crypto.PubKey.HashDescr as Vincent | 20 | |
21 | 21 | import Data.OpenPGP.Util.Base | |
22 | import Crypto.Hash.MD5 as MD5 | ||
23 | import Crypto.Hash.SHA1 as SHA1 | ||
24 | import Crypto.Hash.SHA256 as SHA256 | ||
25 | import Crypto.Hash.SHA384 as SHA384 | ||
26 | import Crypto.Hash.SHA512 as SHA512 | ||
27 | import Crypto.Hash.SHA224 as SHA224 | ||
28 | import Crypto.Hash.RIPEMD160 as RIPEMD160 | ||
29 | |||
30 | hashAlgoDesc OpenPGP.MD5 = Vincent.hashDescrMD5 | ||
31 | hashAlgoDesc OpenPGP.SHA1 = Vincent.hashDescrSHA1 | ||
32 | hashAlgoDesc OpenPGP.RIPEMD160 = Vincent.hashDescrRIPEMD160 | ||
33 | hashAlgoDesc OpenPGP.SHA256 = Vincent.hashDescrSHA256 | ||
34 | hashAlgoDesc OpenPGP.SHA384 = Vincent.hashDescrSHA384 | ||
35 | hashAlgoDesc OpenPGP.SHA512 = Vincent.hashDescrSHA512 | ||
36 | hashAlgoDesc OpenPGP.SHA224 = Vincent.hashDescrSHA224 | ||
37 | hashAlgoDesc _ = | ||
38 | error "Unsupported HashAlgorithm in hashAlgoDesc" | ||
39 | |||
40 | find_key :: OpenPGP.Message -> String -> Maybe OpenPGP.Packet | ||
41 | find_key = OpenPGP.find_key fingerprint | ||
42 | 22 | ||
43 | 23 | ||
44 | privateDSAkey :: OpenPGP.Packet -> Vincent.DSA.PrivateKey | 24 | privateDSAkey :: 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 | ||
61 | rsaKey :: OpenPGP.Packet -> Vincent.RSA.PublicKey | ||
62 | rsaKey k = | ||
63 | Vincent.RSA.PublicKey (integerBytesize n) n (keyParam 'e' k) | ||
64 | where | ||
65 | n = keyParam 'n' k | ||
66 | |||
67 | integerBytesize :: Integer -> Int | ||
68 | integerBytesize i = fromIntegral $ LZ.length (encode (OpenPGP.MPI i)) - 2 | ||
69 | |||
70 | |||
71 | toStrictBS :: LZ.ByteString -> BS.ByteString | ||
72 | toStrictBS = BS.concat . LZ.toChunks | ||
73 | |||
74 | toLazyBS :: BS.ByteString -> LZ.ByteString | ||
75 | toLazyBS = LZ.fromChunks . (:[]) | ||
76 | |||
77 | |||
78 | keyParam :: Char -> OpenPGP.Packet -> Integer | ||
79 | keyParam c k = fromJustMPI $ lookup c (OpenPGP.key k) | ||
80 | fromJustMPI :: Maybe OpenPGP.MPI -> Integer | ||
81 | fromJustMPI (Just (OpenPGP.MPI x)) = x | ||
82 | fromJustMPI _ = error "Not a Just MPI, Data.OpenPGP.CryptoAPI" | ||
83 | |||
84 | hashBySymbol OpenPGP.MD5 = MD5.hashlazy | ||
85 | hashBySymbol OpenPGP.SHA1 = SHA1.hashlazy | ||
86 | hashBySymbol OpenPGP.SHA256 = SHA256.hashlazy | ||
87 | hashBySymbol OpenPGP.SHA384 = SHA384.hashlazy | ||
88 | hashBySymbol OpenPGP.SHA512 = SHA512.hashlazy | ||
89 | hashBySymbol OpenPGP.SHA224 = SHA224.hashlazy | ||
90 | hashBySymbol OpenPGP.RIPEMD160 = RIPEMD160.hashlazy | ||
91 | |||
92 | |||
93 | 41 | ||
94 | 42 | ||
95 | -- | Make a signature | 43 | -- | Make a signature |