From bf36db548891057ccdcfb5b4c9366296fc26d7dd Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sun, 1 May 2011 15:56:53 +0200 Subject: Code cleaning. --- Hsbot/Utils.hs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'Hsbot/Utils.hs') diff --git a/Hsbot/Utils.hs b/Hsbot/Utils.hs index 0b32fa6..b41fa52 100644 --- a/Hsbot/Utils.hs +++ b/Hsbot/Utils.hs @@ -19,6 +19,7 @@ import qualified Data.Certificate.KeyRSA as KeyRSA import Data.Certificate.PEM import Data.Certificate.X509 import Data.List +import Data.Maybe import Network.TLS import System.IO @@ -33,7 +34,7 @@ addThreadIdToQuitMVar thrId = do delThreadIdFromQuitMVar :: ThreadId -> Env IO () delThreadIdFromQuitMVar thrId = do threadIdsMv <- asks envThreadIdsMv - liftIO $ modifyMVar_ threadIdsMv (\l -> return $ delete thrId l) + liftIO $ modifyMVar_ threadIdsMv (return . delete thrId) setGlobalQuitMVar :: BotStatus -> Env IO () setGlobalQuitMVar status = do @@ -49,7 +50,7 @@ sendStr _ (Just ctx) msg = sendData ctx $ L.fromChunks [C.pack msg] sendStr handle Nothing msg = hPutStrLn handle msg -- TLS utils -initTLSEnv :: TLSConfig -> IO (TLSParams) +initTLSEnv :: TLSConfig -> IO TLSParams initTLSEnv ssl = do let certFile = sslCert ssl keyFile = sslKey ssl @@ -68,10 +69,8 @@ initTLSEnv ssl = do readCertificate :: FilePath -> IO X509 readCertificate filepath = do content <- B.readFile filepath - let certdata = case parsePEMCert content of - Nothing -> error ("no valid certificate section") - Just x -> x - let cert = case decodeCertificate $ L.fromChunks [certdata] of + let certdata = fromMaybe (error "no valid certificate section") $ parsePEMCert content + cert = case decodeCertificate $ L.fromChunks [certdata] of Left err -> error ("cannot decode certificate: " ++ err) Right x -> x return cert @@ -80,11 +79,11 @@ readPrivateKey :: FilePath -> IO PrivateKey readPrivateKey filepath = do content <- B.readFile filepath let pkdata = case parsePEMKeyRSA content of - Nothing -> error ("no valid RSA key section") + Nothing -> error "no valid RSA key section" Just x -> L.fromChunks [x] let pk = case KeyRSA.decodePrivate pkdata of Left err -> error ("cannot decode key: " ++ err) - Right x -> PrivRSA $ RSA.PrivateKey + Right x -> PrivRSA RSA.PrivateKey { RSA.private_sz = fromIntegral $ KeyRSA.lenmodulus x , RSA.private_n = KeyRSA.modulus x , RSA.private_d = KeyRSA.private_exponant x -- cgit v1.2.3