summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-10-29 19:07:35 -0400
committerjoe <joe@jerkface.net>2017-10-29 19:07:35 -0400
commit08f03452a94f922c3a9ea44a4a43931a5bb44cb3 (patch)
treedf27963cd5b985f6be3772b26a364e98f5a3d5fa /src/Network
parent4a2bb67f5fbd3d1f8e939cea32384132076f1c7e (diff)
comments.
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/Tox/Crypto/Transport.hs21
1 files changed, 18 insertions, 3 deletions
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)
68encodeNetCrypto (NetCrypto x) saddr = (B.cons 0x1b (runPut $ put x),saddr) 68encodeNetCrypto (NetCrypto x) saddr = (B.cons 0x1b (runPut $ put x),saddr)
69 69
70data Handshake (f :: * -> *) = Handshake 70data Handshake (f :: * -> *) = Handshake
71 { handshakeCookie :: Cookie 71 { -- The cookie is a cookie obtained by
72 -- sending a cookie request packet to the peer and getting a cookie
73 -- response packet with a cookie in it. It may also be obtained in the
74 -- handshake packet by a peer receiving a handshake packet (Other
75 -- Cookie).
76 handshakeCookie :: Cookie
77 -- The nonce is a nonce used to encrypt the encrypted part of the handshake
78 -- packet.
72 , handshakeNonce :: Nonce24 79 , handshakeNonce :: Nonce24
73 , hadshakeData :: f HandshakeData 80 -- The encrypted part of the handshake packet is encrypted with the long
81 -- term user-keys of both peers.
82 , handshakeData :: f HandshakeData
74 } 83 }
75 84
76instance Serialize (Handshake Encrypted) where 85instance Serialize (Handshake Encrypted) where
@@ -91,7 +100,11 @@ instance Sized HandshakeData where
91 <> contramap otherCookie size 100 <> contramap otherCookie size
92 101
93data CryptoPacket (f :: * -> *) = CryptoPacket 102data CryptoPacket (f :: * -> *) = CryptoPacket
94 { pktNonce :: Word16 103 { -- | The last 2 bytes of the nonce used to encrypt 'pktData'
104 pktNonce :: Word16
105 -- The payload is encrypted with the session key and 'baseNonce' set by
106 -- the receiver in their handshake + packet number (starting at 0, big
107 -- endian math).
95 , pktData :: f CryptoData 108 , pktData :: f CryptoData
96 } 109 }
97 110
@@ -148,8 +161,10 @@ erCompat lens = error $ "Use of '" ++ lens ++ "' lens on incompatible CryptoMes
148typingStatus :: Functor f => (UserStatus -> f UserStatus)-> (CryptoMessage -> f CryptoMessage) 161typingStatus :: Functor f => (UserStatus -> f UserStatus)-> (CryptoMessage -> f CryptoMessage)
149typingStatus = lens getter setter 162typingStatus = lens getter setter
150 where 163 where
164 getter :: CryptoMessage -> UserStatus
151 getter (TwoByte TYPING status) = toEnum $ fromIntegral status 165 getter (TwoByte TYPING status) = toEnum $ fromIntegral status
152 getter _ = erCompat "typingStatus" 166 getter _ = erCompat "typingStatus"
167 setter :: CryptoMessage -> UserStatus -> CryptoMessage
153 setter (TwoByte TYPING _) status = TwoByte TYPING (fromIntegral . fromEnum $ status) 168 setter (TwoByte TYPING _) status = TwoByte TYPING (fromIntegral . fromEnum $ status)
154 setter _ _ = erCompat "typingStatus" 169 setter _ _ = erCompat "typingStatus"
155 170