mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-08-28 00:44:38 +00:00
refactor: use guards
This commit is contained in:
+3
-4
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user