diff options
author | Joe Crayne <joe@jerkface.net> | 2018-09-04 23:36:23 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-09-07 13:18:56 -0400 |
commit | f5d20a324b5aef4e14281d969de8677352956b6b (patch) | |
tree | 4df63cc7cbb6b70d07122e8e2720e25ee0ed2818 /src | |
parent | 18eb72eca608b5858be66a4d48c6818556b8e124 (diff) |
Tox cookie: Generic & Hashable instances.
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/Tox/DHT/Transport.hs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/Network/Tox/DHT/Transport.hs b/src/Network/Tox/DHT/Transport.hs index 0c69ea8b..e784ec90 100644 --- a/src/Network/Tox/DHT/Transport.hs +++ b/src/Network/Tox/DHT/Transport.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE DeriveGeneric #-} | ||
1 | {-# LANGUAGE FlexibleContexts #-} | 2 | {-# LANGUAGE FlexibleContexts #-} |
2 | {-# LANGUAGE FlexibleInstances #-} | 3 | {-# LANGUAGE FlexibleInstances #-} |
3 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} | 4 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} |
@@ -47,11 +48,13 @@ import Data.Bool | |||
47 | import qualified Data.ByteString as B | 48 | import qualified Data.ByteString as B |
48 | ;import Data.ByteString (ByteString) | 49 | ;import Data.ByteString (ByteString) |
49 | import Data.Functor.Contravariant | 50 | import Data.Functor.Contravariant |
51 | import Data.Hashable | ||
50 | import Data.Maybe | 52 | import Data.Maybe |
51 | import Data.Monoid | 53 | import Data.Monoid |
52 | import Data.Serialize as S | 54 | import Data.Serialize as S |
53 | import Data.Tuple | 55 | import Data.Tuple |
54 | import Data.Word | 56 | import Data.Word |
57 | import GHC.Generics | ||
55 | import Network.Socket | 58 | import Network.Socket |
56 | 59 | ||
57 | type DHTTransport = Transport String NodeInfo (DHTMessage Encrypted8) | 60 | type DHTTransport = Transport String NodeInfo (DHTMessage Encrypted8) |
@@ -358,6 +361,9 @@ data Cookie (f :: * -> *) = Cookie Nonce24 (f CookieData) | |||
358 | deriving instance Eq (f CookieData) => Eq (Cookie f) | 361 | deriving instance Eq (f CookieData) => Eq (Cookie f) |
359 | deriving instance Ord (f CookieData) => Ord (Cookie f) | 362 | deriving instance Ord (f CookieData) => Ord (Cookie f) |
360 | deriving instance Show (f CookieData) => Show (Cookie f) | 363 | deriving instance Show (f CookieData) => Show (Cookie f) |
364 | deriving instance Generic (f CookieData) => Generic (Cookie f) | ||
365 | |||
366 | instance Hashable (Cookie Encrypted) | ||
361 | 367 | ||
362 | instance Sized (Cookie Encrypted) where size = ConstSize 112 -- 24 byte nonce + 88 byte cookie data | 368 | instance Sized (Cookie Encrypted) where size = ConstSize 112 -- 24 byte nonce + 88 byte cookie data |
363 | 369 | ||
@@ -370,7 +376,7 @@ data CookieData = CookieData -- 16 (mac) | |||
370 | , longTermKey :: PublicKey -- 32 | 376 | , longTermKey :: PublicKey -- 32 |
371 | , dhtKey :: PublicKey -- + 32 | 377 | , dhtKey :: PublicKey -- + 32 |
372 | } -- = 88 bytes when encrypted. | 378 | } -- = 88 bytes when encrypted. |
373 | deriving Show | 379 | deriving (Show, Generic) |
374 | 380 | ||
375 | instance Sized CookieData where | 381 | instance Sized CookieData where |
376 | size = ConstSize 72 | 382 | size = ConstSize 72 |