From e6e9799e4bed42daac27739d2cf2ae77414fb3b5 Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 8 Jun 2018 18:09:26 -0400 Subject: Accept hexadecimal nospam in jabber-id format. --- src/Network/Tox/NodeId.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Network/Tox/NodeId.hs b/src/Network/Tox/NodeId.hs index 74239710..dab1b14a 100644 --- a/src/Network/Tox/NodeId.hs +++ b/src/Network/Tox/NodeId.hs @@ -555,8 +555,14 @@ parseNoSpamJID jid = do _ -> Left "Hostname should be 43 base64 digits followed by .tox." pub <- id2key <$> readEither base64 let ustr = Text.unpack u - '$' : b64digits <- Right ustr -- TODO: support 0x prefix also. - NoSpam nospam (Just x) <- readEither $ map (\case; '?' -> '0'; c -> c) ustr + case ustr of + '$' : b64digits -> solveBase64NoSpamID b64digits pub + '0' : 'x' : hexdigits -> do nospam <- readEither ('0':'x':hexdigits) + return $ NoSpamId nospam pub + +solveBase64NoSpamID :: String -> PublicKey -> Either String NoSpamId +solveBase64NoSpamID b64digits pub = do + NoSpam nospam (Just x) <- readEither $ '$' : map (\case; '?' -> '0'; c -> c) b64digits let nlo = fromIntegral (0x0FFFF .&. nospam) :: Word16 nhi = fromIntegral (0x0FFFF .&. (nospam `shiftR` 16)) :: Word16 sum = x `xor` nlo `xor` nhi `xor` xorsum pub @@ -583,7 +589,6 @@ parseNoSpamJID jid = do let bitpos = q * 6 + p * 2 ac' = ac `xor` shiftR (fromIntegral b `shiftL` 48) bitpos solve ns ac' - n64' <- solve ns n64 let nospam' = fromIntegral (n64' `shiftR` 32) cksum' = fromIntegral (n64' `shiftR` 16) -- cgit v1.2.3