summaryrefslogtreecommitdiff
path: root/DHTTransport.hs
diff options
context:
space:
mode:
Diffstat (limited to 'DHTTransport.hs')
-rw-r--r--DHTTransport.hs13
1 files changed, 8 insertions, 5 deletions
diff --git a/DHTTransport.hs b/DHTTransport.hs
index 013fa322..ac263cdc 100644
--- a/DHTTransport.hs
+++ b/DHTTransport.hs
@@ -307,15 +307,18 @@ forwardDHTRequests crypto closeLookup dht = dht { awaitMessage = await' }
307 m -> pass m 307 m -> pass m
308 308
309encrypt :: TransportCrypto -> DHTMessage ((,) Nonce8) -> NodeInfo -> (DHTMessage Encrypted8, NodeInfo) 309encrypt :: TransportCrypto -> DHTMessage ((,) Nonce8) -> NodeInfo -> (DHTMessage Encrypted8, NodeInfo)
310encrypt crypto msg ni = (transcode (encryptMessage crypto) msg, ni) 310encrypt crypto msg ni = ( transcode (encryptMessage crypto (id2key $ nodeId ni)) msg
311 , ni )
311 312
312encryptMessage :: Serialize a => 313encryptMessage :: Serialize a =>
313 TransportCrypto -> Nonce24 -> Either (Nonce8,a) (Assym (Nonce8,a)) -> Encrypted8 a 314 TransportCrypto ->
314encryptMessage crypto n (Right assym) = E8 $ ToxCrypto.encrypt secret plain 315 PublicKey ->
316 Nonce24 -> Either (Nonce8,a) (Assym (Nonce8,a)) -> Encrypted8 a
317encryptMessage crypto destKey n (Right assym) = E8 $ ToxCrypto.encrypt secret plain
315 where 318 where
316 secret = computeSharedSecret (transportSecret crypto) (senderKey assym) n 319 secret = computeSharedSecret (transportSecret crypto) destKey n
317 plain = encodePlain $ swap $ assymData assym 320 plain = encodePlain $ swap $ assymData assym
318encryptMessage crypto n (Left plain) = _todo -- need cached public key. 321encryptMessage crypto destKey n (Left plain) = _todo -- need cached public key.
319 322
320decrypt :: TransportCrypto -> DHTMessage Encrypted8 -> NodeInfo -> Either String (DHTMessage ((,) Nonce8), NodeInfo) 323decrypt :: TransportCrypto -> DHTMessage Encrypted8 -> NodeInfo -> Either String (DHTMessage ((,) Nonce8), NodeInfo)
321decrypt crypto msg ni = (, ni) <$> (sequenceMessage $ transcode (decryptMessage crypto) msg) 324decrypt crypto msg ni = (, ni) <$> (sequenceMessage $ transcode (decryptMessage crypto) msg)