From 08f03452a94f922c3a9ea44a4a43931a5bb44cb3 Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 29 Oct 2017 19:07:35 -0400 Subject: comments. --- src/Network/Tox/Crypto/Transport.hs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Network/Tox/Crypto/Transport.hs b/src/Network/Tox/Crypto/Transport.hs index 1583ef6f..f7fd0f7e 100644 --- a/src/Network/Tox/Crypto/Transport.hs +++ b/src/Network/Tox/Crypto/Transport.hs @@ -68,9 +68,18 @@ encodeNetCrypto (NetHandshake x) saddr = (B.cons 0x1a (runPut $ put x),saddr) encodeNetCrypto (NetCrypto x) saddr = (B.cons 0x1b (runPut $ put x),saddr) data Handshake (f :: * -> *) = Handshake - { handshakeCookie :: Cookie + { -- The cookie is a cookie obtained by + -- sending a cookie request packet to the peer and getting a cookie + -- response packet with a cookie in it. It may also be obtained in the + -- handshake packet by a peer receiving a handshake packet (Other + -- Cookie). + handshakeCookie :: Cookie + -- The nonce is a nonce used to encrypt the encrypted part of the handshake + -- packet. , handshakeNonce :: Nonce24 - , hadshakeData :: f HandshakeData + -- The encrypted part of the handshake packet is encrypted with the long + -- term user-keys of both peers. + , handshakeData :: f HandshakeData } instance Serialize (Handshake Encrypted) where @@ -91,7 +100,11 @@ instance Sized HandshakeData where <> contramap otherCookie size data CryptoPacket (f :: * -> *) = CryptoPacket - { pktNonce :: Word16 + { -- | The last 2 bytes of the nonce used to encrypt 'pktData' + pktNonce :: Word16 + -- The payload is encrypted with the session key and 'baseNonce' set by + -- the receiver in their handshake + packet number (starting at 0, big + -- endian math). , pktData :: f CryptoData } @@ -148,8 +161,10 @@ erCompat lens = error $ "Use of '" ++ lens ++ "' lens on incompatible CryptoMes typingStatus :: Functor f => (UserStatus -> f UserStatus)-> (CryptoMessage -> f CryptoMessage) typingStatus = lens getter setter where + getter :: CryptoMessage -> UserStatus getter (TwoByte TYPING status) = toEnum $ fromIntegral status getter _ = erCompat "typingStatus" + setter :: CryptoMessage -> UserStatus -> CryptoMessage setter (TwoByte TYPING _) status = TwoByte TYPING (fromIntegral . fromEnum $ status) setter _ _ = erCompat "typingStatus" -- cgit v1.2.3