diff options
author | joe <joe@jerkface.net> | 2018-06-08 18:09:26 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-06-08 18:09:26 -0400 |
commit | e6e9799e4bed42daac27739d2cf2ae77414fb3b5 (patch) | |
tree | 69647feb57c42a81cdea41b4c557faefd6b183bc | |
parent | 7db65f496b512f5a2adc7fe7d4124a777f9daa88 (diff) |
Accept hexadecimal nospam in jabber-id format.
-rw-r--r-- | src/Network/Tox/NodeId.hs | 11 |
1 files changed, 8 insertions, 3 deletions
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 | |||
555 | _ -> Left "Hostname should be 43 base64 digits followed by .tox." | 555 | _ -> Left "Hostname should be 43 base64 digits followed by .tox." |
556 | pub <- id2key <$> readEither base64 | 556 | pub <- id2key <$> readEither base64 |
557 | let ustr = Text.unpack u | 557 | let ustr = Text.unpack u |
558 | '$' : b64digits <- Right ustr -- TODO: support 0x prefix also. | 558 | case ustr of |
559 | NoSpam nospam (Just x) <- readEither $ map (\case; '?' -> '0'; c -> c) ustr | 559 | '$' : b64digits -> solveBase64NoSpamID b64digits pub |
560 | '0' : 'x' : hexdigits -> do nospam <- readEither ('0':'x':hexdigits) | ||
561 | return $ NoSpamId nospam pub | ||
562 | |||
563 | solveBase64NoSpamID :: String -> PublicKey -> Either String NoSpamId | ||
564 | solveBase64NoSpamID b64digits pub = do | ||
565 | NoSpam nospam (Just x) <- readEither $ '$' : map (\case; '?' -> '0'; c -> c) b64digits | ||
560 | let nlo = fromIntegral (0x0FFFF .&. nospam) :: Word16 | 566 | let nlo = fromIntegral (0x0FFFF .&. nospam) :: Word16 |
561 | nhi = fromIntegral (0x0FFFF .&. (nospam `shiftR` 16)) :: Word16 | 567 | nhi = fromIntegral (0x0FFFF .&. (nospam `shiftR` 16)) :: Word16 |
562 | sum = x `xor` nlo `xor` nhi `xor` xorsum pub | 568 | sum = x `xor` nlo `xor` nhi `xor` xorsum pub |
@@ -583,7 +589,6 @@ parseNoSpamJID jid = do | |||
583 | let bitpos = q * 6 + p * 2 | 589 | let bitpos = q * 6 + p * 2 |
584 | ac' = ac `xor` shiftR (fromIntegral b `shiftL` 48) bitpos | 590 | ac' = ac `xor` shiftR (fromIntegral b `shiftL` 48) bitpos |
585 | solve ns ac' | 591 | solve ns ac' |
586 | |||
587 | n64' <- solve ns n64 | 592 | n64' <- solve ns n64 |
588 | let nospam' = fromIntegral (n64' `shiftR` 32) | 593 | let nospam' = fromIntegral (n64' `shiftR` 32) |
589 | cksum' = fromIntegral (n64' `shiftR` 16) | 594 | cksum' = fromIntegral (n64' `shiftR` 16) |