summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Crypto
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-10-30 23:53:11 -0400
committerjoe <joe@jerkface.net>2017-10-30 23:53:11 -0400
commit13d617b0b8389d702cb0a615fc359f4be27402f7 (patch)
tree1d406eade86e2cd46d3e66a85ed2e723fdf5e782 /src/Network/Tox/Crypto
parent23767c2ebc53a2853c0065e727c3bbbf40cd5a83 (diff)
Serialize instance for HandshakeData.
Diffstat (limited to 'src/Network/Tox/Crypto')
-rw-r--r--src/Network/Tox/Crypto/Transport.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Network/Tox/Crypto/Transport.hs b/src/Network/Tox/Crypto/Transport.hs
index 5b9a0661..d89ac80d 100644
--- a/src/Network/Tox/Crypto/Transport.hs
+++ b/src/Network/Tox/Crypto/Transport.hs
@@ -50,7 +50,10 @@ import Network.Tox.DHT.Transport (Cookie)
50import Network.Tox.NodeId 50import Network.Tox.NodeId
51 51
52import Network.Socket 52import Network.Socket
53import Data.ByteArray
54
53import Data.ByteString as B 55import Data.ByteString as B
56import Data.Maybe
54import Data.Monoid 57import Data.Monoid
55import Data.Word 58import Data.Word
56import Crypto.Hash 59import Crypto.Hash
@@ -106,6 +109,17 @@ instance Sized HandshakeData where
106 <> ConstSize 64 -- contramap cookieHash size -- missing instance Sized (Digest SHA512) 109 <> ConstSize 64 -- contramap cookieHash size -- missing instance Sized (Digest SHA512)
107 <> contramap otherCookie size 110 <> contramap otherCookie size
108 111
112instance Serialize HandshakeData where
113 get = HandshakeData <$> get
114 <*> (id2key <$> get)
115 <*> (fromJust . digestFromByteString <$> getBytes 64)
116 <*> get
117 put (HandshakeData n k h c) = do
118 put n
119 put $ key2id k
120 putByteString (convert h)
121 put c
122
109data CryptoPacket (f :: * -> *) = CryptoPacket 123data CryptoPacket (f :: * -> *) = CryptoPacket
110 { -- | The last 2 bytes of the nonce used to encrypt 'pktData' 124 { -- | The last 2 bytes of the nonce used to encrypt 'pktData'
111 pktNonce :: Word16 125 pktNonce :: Word16