refactor: use guards

This commit is contained in:
Evgeny Poberezkin
2020-10-14 21:30:21 +01:00
parent b1f41d10da
commit a58ce378db
2 changed files with 15 additions and 20 deletions
+3 -4
View File
@@ -69,10 +69,9 @@ verifyTransmission signature connId cmd = do
conn <- getConn store party connId
either (return . smpErr) f conn
verifySend :: Maybe PublicKey -> m Cmd
verifySend =
if null signature
then return . maybe cmd (const authErr)
else maybe (return authErr) verifySignature
verifySend
| null signature = return . maybe cmd (const authErr)
| otherwise = maybe (return authErr) verifySignature
-- TODO stub
verifySignature :: PublicKey -> m Cmd
verifySignature key = return $ if signature == key then cmd else authErr
+12 -16
View File
@@ -92,25 +92,21 @@ tGet fromParty h = do
-- ERROR response does not always have connection ID
Cmd SBroker (ERROR _) -> Right cmd
-- other responses must have connection ID
Cmd SBroker _ ->
if null connId
then Left $ SYNTAX errNoConnectionId
else Right cmd
Cmd SBroker _
| null connId -> Left $ SYNTAX errNoConnectionId
| otherwise -> Right cmd
-- CREATE must NOT have signature or connection ID
Cmd SRecipient (CREATE _) ->
if null signature && null connId
then Right cmd
else Left $ SYNTAX errHasCredentials
Cmd SRecipient (CREATE _)
| null signature && null connId -> Right cmd
| otherwise -> Left $ SYNTAX errHasCredentials
-- SEND must have connection ID, signature is not always required
Cmd SSender (SEND _) ->
if null connId
then Left $ SYNTAX errNoConnectionId
else Right cmd
Cmd SSender (SEND _)
| null connId -> Left $ SYNTAX errNoConnectionId
| otherwise -> Right cmd
-- other client commands must have both signature and connection ID
_ ->
if null signature || null connId
then Left $ SYNTAX errNoCredentials
else Right cmd
_
| null signature || null connId -> Left $ SYNTAX errNoCredentials
| otherwise -> Right cmd
cmdWithMsgBody :: Cmd -> m (Either ErrorType Cmd)
cmdWithMsgBody = \case