diff options
author | Joe Crayne <joe@jerkface.net> | 2018-11-27 22:32:32 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-11-27 22:47:28 -0500 |
commit | c2807c309c32e86ff199d06ea411d6619c92e597 (patch) | |
tree | 6e87daa698104bea86aa0b499d9e4d16cdefa49b /src/Network/Tox/NodeId.hs | |
parent | b6f84bd5bca03a5493c038c3e9bb26892224a41a (diff) |
TCP relay packet serialization.
Diffstat (limited to 'src/Network/Tox/NodeId.hs')
-rw-r--r-- | src/Network/Tox/NodeId.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Network/Tox/NodeId.hs b/src/Network/Tox/NodeId.hs index dc600db7..97faa942 100644 --- a/src/Network/Tox/NodeId.hs +++ b/src/Network/Tox/NodeId.hs | |||
@@ -13,6 +13,7 @@ | |||
13 | {-# LANGUAGE LambdaCase #-} | 13 | {-# LANGUAGE LambdaCase #-} |
14 | {-# LANGUAGE PatternSynonyms #-} | 14 | {-# LANGUAGE PatternSynonyms #-} |
15 | {-# LANGUAGE ScopedTypeVariables #-} | 15 | {-# LANGUAGE ScopedTypeVariables #-} |
16 | {-# LANGUAGE StandaloneDeriving #-} | ||
16 | {-# LANGUAGE TupleSections #-} | 17 | {-# LANGUAGE TupleSections #-} |
17 | {- LANGUAGE TypeApplications -} | 18 | {- LANGUAGE TypeApplications -} |
18 | module Network.Tox.NodeId | 19 | module Network.Tox.NodeId |
@@ -118,6 +119,19 @@ packPublicKey ws = BA.allocAndFreeze (8 * length ws) $ | |||
118 | -- convenient for short-circuiting xor/distance comparisons. The PublicKey | 119 | -- convenient for short-circuiting xor/distance comparisons. The PublicKey |
119 | -- format is convenient for encryption. | 120 | -- format is convenient for encryption. |
120 | data NodeId = NodeId [Word64] !(Maybe PublicKey) | 121 | data NodeId = NodeId [Word64] !(Maybe PublicKey) |
122 | deriving Data | ||
123 | |||
124 | instance Data PublicKey where | ||
125 | -- Data a => (forall d b . Data d => c (d -> b) -> d -> c b) -> (forall g . g -> c g) -> a -> c a | ||
126 | gfoldl f z txt = z (throwCryptoError . publicKey) `f` (BA.convert txt :: ByteString) | ||
127 | toConstr _ = error "Crypto.PubKey.Curve25519.toConstr" | ||
128 | gunfold _ _ = error "Crypto.PubKey.Curve25519.gunfold" | ||
129 | #if MIN_VERSION_base(4,2,0) | ||
130 | dataTypeOf _ = mkNoRepType "Crypto.PubKey.Curve25519.PublicKey" | ||
131 | #else | ||
132 | dataTypeOf _ = mkNorepType "Crypto.PubKey.Curve25519.PublicKey" | ||
133 | #endif | ||
134 | |||
121 | 135 | ||
122 | instance Eq NodeId where | 136 | instance Eq NodeId where |
123 | (NodeId ws _) == (NodeId xs _) | 137 | (NodeId ws _) == (NodeId xs _) |
@@ -586,6 +600,7 @@ parseNoSpamJID jid = do | |||
586 | '$' : b64digits -> solveBase64NoSpamID b64digits pub | 600 | '$' : b64digits -> solveBase64NoSpamID b64digits pub |
587 | '0' : 'x' : hexdigits -> do nospam <- readEither ('0':'x':hexdigits) | 601 | '0' : 'x' : hexdigits -> do nospam <- readEither ('0':'x':hexdigits) |
588 | return $ NoSpamId nospam pub | 602 | return $ NoSpamId nospam pub |
603 | _ -> Left "Missing nospam." | ||
589 | 604 | ||
590 | solveBase64NoSpamID :: String -> PublicKey -> Either String NoSpamId | 605 | solveBase64NoSpamID :: String -> PublicKey -> Either String NoSpamId |
591 | solveBase64NoSpamID b64digits pub = do | 606 | solveBase64NoSpamID b64digits pub = do |