diff options
author | joe <joe@jerkface.net> | 2017-10-29 17:20:07 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-10-29 17:20:07 -0400 |
commit | 85b6fc2a851d1321ca8d21d50ab88bd2c95cec6a (patch) | |
tree | dce85082a5ea8af59b5678cce63bddf533eeb1c2 /src/Network/Tox/Crypto | |
parent | a0ddb901b9b67bf7722ccf57806962456b261292 (diff) |
Serialize instance for Handshake.
Diffstat (limited to 'src/Network/Tox/Crypto')
-rw-r--r-- | src/Network/Tox/Crypto/Transport.hs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/Network/Tox/Crypto/Transport.hs b/src/Network/Tox/Crypto/Transport.hs index 0011fac0..4cf6c7a5 100644 --- a/src/Network/Tox/Crypto/Transport.hs +++ b/src/Network/Tox/Crypto/Transport.hs | |||
@@ -39,6 +39,7 @@ module Network.Tox.Crypto.Transport | |||
39 | 39 | ||
40 | import Crypto.Tox | 40 | import Crypto.Tox |
41 | import Network.Tox.DHT.Transport (Cookie) | 41 | import Network.Tox.DHT.Transport (Cookie) |
42 | import Network.Tox.NodeId | ||
42 | 43 | ||
43 | import Network.Socket | 44 | import Network.Socket |
44 | import Data.ByteString as B | 45 | import Data.ByteString as B |
@@ -67,6 +68,10 @@ data Handshake (f :: * -> *) = Handshake | |||
67 | , hadshakeData :: f HandshakeData | 68 | , hadshakeData :: f HandshakeData |
68 | } | 69 | } |
69 | 70 | ||
71 | instance Serialize (Handshake Encrypted) where | ||
72 | get = Handshake <$> get <*> get <*> get | ||
73 | put (Handshake cookie n24 dta) = put cookie >> put n24 >> put dta | ||
74 | |||
70 | data HandshakeData = HandshakeData | 75 | data HandshakeData = HandshakeData |
71 | { baseNonce :: Nonce24 | 76 | { baseNonce :: Nonce24 |
72 | , sessionKey :: PublicKey | 77 | , sessionKey :: PublicKey |
@@ -74,6 +79,12 @@ data HandshakeData = HandshakeData | |||
74 | , otherCookie :: Cookie | 79 | , otherCookie :: Cookie |
75 | } | 80 | } |
76 | 81 | ||
82 | instance Sized HandshakeData where | ||
83 | size = contramap baseNonce size | ||
84 | <> contramap (key2id . sessionKey) size | ||
85 | <> ConstSize 64 -- contramap cookieHash size -- missing instance Sized (Digest SHA512) | ||
86 | <> contramap otherCookie size | ||
87 | |||
77 | data CryptoPacket (f :: * -> *) = CryptoPacket | 88 | data CryptoPacket (f :: * -> *) = CryptoPacket |
78 | { pktNonce :: Word16 | 89 | { pktNonce :: Word16 |
79 | , pktData :: f CryptoData | 90 | , pktData :: f CryptoData |