summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-10-29 17:20:07 -0400
committerjoe <joe@jerkface.net>2017-10-29 17:20:07 -0400
commit85b6fc2a851d1321ca8d21d50ab88bd2c95cec6a (patch)
treedce85082a5ea8af59b5678cce63bddf533eeb1c2 /src
parenta0ddb901b9b67bf7722ccf57806962456b261292 (diff)
Serialize instance for Handshake.
Diffstat (limited to 'src')
-rw-r--r--src/Network/Tox/Crypto/Transport.hs11
-rw-r--r--src/Network/Tox/NodeId.hs1
2 files changed, 12 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
40import Crypto.Tox 40import Crypto.Tox
41import Network.Tox.DHT.Transport (Cookie) 41import Network.Tox.DHT.Transport (Cookie)
42import Network.Tox.NodeId
42 43
43import Network.Socket 44import Network.Socket
44import Data.ByteString as B 45import Data.ByteString as B
@@ -67,6 +68,10 @@ data Handshake (f :: * -> *) = Handshake
67 , hadshakeData :: f HandshakeData 68 , hadshakeData :: f HandshakeData
68 } 69 }
69 70
71instance Serialize (Handshake Encrypted) where
72 get = Handshake <$> get <*> get <*> get
73 put (Handshake cookie n24 dta) = put cookie >> put n24 >> put dta
74
70data HandshakeData = HandshakeData 75data 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
82instance 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
77data CryptoPacket (f :: * -> *) = CryptoPacket 88data CryptoPacket (f :: * -> *) = CryptoPacket
78 { pktNonce :: Word16 89 { pktNonce :: Word16
79 , pktData :: f CryptoData 90 , pktData :: f CryptoData
diff --git a/src/Network/Tox/NodeId.hs b/src/Network/Tox/NodeId.hs
index 20dc1854..00b572f2 100644
--- a/src/Network/Tox/NodeId.hs
+++ b/src/Network/Tox/NodeId.hs
@@ -90,6 +90,7 @@ packPublicKey ws = BA.allocAndFreeze (8 * length ws) $
90newtype NodeId = NodeId [Word64] 90newtype NodeId = NodeId [Word64]
91 deriving (Eq,Ord) -- ByteArrayAccess) -- (Eq,Ord,ByteArrayAccess, Bits, Hashable) 91 deriving (Eq,Ord) -- ByteArrayAccess) -- (Eq,Ord,ByteArrayAccess, Bits, Hashable)
92 92
93instance Sized NodeId where size = ConstSize 32
93 94
94key2id :: PublicKey -> NodeId 95key2id :: PublicKey -> NodeId
95key2id = NodeId . unpackPublicKey 96key2id = NodeId . unpackPublicKey