Code cleaning.
This commit is contained in:
parent
c497b24700
commit
bf36db5488
6 changed files with 29 additions and 30 deletions
|
@ -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
|
||||
|
|
Reference in a new issue