diff options
author | joe <joe@jerkface.net> | 2018-06-10 02:20:55 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-06-10 02:20:55 -0400 |
commit | 2313073b3e85ed2479ac4246de29e8867f51603b (patch) | |
tree | 1a602dd6411d23364832a3e8fe019f1ecfd0ce2e /src/Network/Tox | |
parent | b1a8e947df45ce363da7d2787ec487dedac3c397 (diff) |
Improved nid command JID parsing.
Diffstat (limited to 'src/Network/Tox')
-rw-r--r-- | src/Network/Tox/NodeId.hs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/Network/Tox/NodeId.hs b/src/Network/Tox/NodeId.hs index dab1b14a..f3013142 100644 --- a/src/Network/Tox/NodeId.hs +++ b/src/Network/Tox/NodeId.hs | |||
@@ -29,6 +29,7 @@ module Network.Tox.NodeId | |||
29 | , sampleNodeId | 29 | , sampleNodeId |
30 | , NoSpam(..) | 30 | , NoSpam(..) |
31 | , NoSpamId(..) | 31 | , NoSpamId(..) |
32 | , noSpamIdToHex | ||
32 | , parseNoSpamId | 33 | , parseNoSpamId |
33 | , nospam64 | 34 | , nospam64 |
34 | , verifyChecksum) where | 35 | , verifyChecksum) where |
@@ -520,6 +521,16 @@ verifyChecksum _ _ = return () -- TODO | |||
520 | data NoSpamId = NoSpamId NoSpam PublicKey | 521 | data NoSpamId = NoSpamId NoSpam PublicKey |
521 | deriving (Eq,Ord) | 522 | deriving (Eq,Ord) |
522 | 523 | ||
524 | noSpamIdToHex :: NoSpamId -> String | ||
525 | noSpamIdToHex (NoSpamId nspam pub) = C8.unpack (Base16.encode $ BA.convert pub) | ||
526 | ++ nospam16 nspam | ||
527 | |||
528 | nospam16 :: NoSpam -> String | ||
529 | nospam16 (NoSpam w32 Nothing) = n ++ "????" | ||
530 | where n = take 8 $ nospam16 (NoSpam w32 (Just 0)) | ||
531 | nospam16 (NoSpam w32 (Just w16)) = C8.unpack $ Base16.encode $ runPut $ do | ||
532 | put w32 | ||
533 | put w16 | ||
523 | 534 | ||
524 | nospam64 :: NoSpam -> String | 535 | nospam64 :: NoSpam -> String |
525 | nospam64 (NoSpam w32 Nothing) = n ++ "???" | 536 | nospam64 (NoSpam w32 Nothing) = n ++ "???" |
@@ -549,7 +560,9 @@ parseNoSpamId spec | Text.length spec == 76 | |||
549 | 560 | ||
550 | parseNoSpamJID :: Text -> Either String NoSpamId | 561 | parseNoSpamJID :: Text -> Either String NoSpamId |
551 | parseNoSpamJID jid = do | 562 | parseNoSpamJID jid = do |
552 | (Just u,h,_) <- Right $ splitJID jid | 563 | (u,h) <- maybe (Left "Invalid JID.") Right |
564 | $ let (mu,h,_) = splitJID jid | ||
565 | in fmap (, h) mu | ||
553 | base64 <- case splitAt 43 $ Text.unpack h of | 566 | base64 <- case splitAt 43 $ Text.unpack h of |
554 | (base64,".tox") -> Right base64 | 567 | (base64,".tox") -> Right base64 |
555 | _ -> Left "Hostname should be 43 base64 digits followed by .tox." | 568 | _ -> Left "Hostname should be 43 base64 digits followed by .tox." |