summaryrefslogtreecommitdiff
path: root/src/Network/Tox
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-10 02:20:55 -0400
committerjoe <joe@jerkface.net>2018-06-10 02:20:55 -0400
commit2313073b3e85ed2479ac4246de29e8867f51603b (patch)
tree1a602dd6411d23364832a3e8fe019f1ecfd0ce2e /src/Network/Tox
parentb1a8e947df45ce363da7d2787ec487dedac3c397 (diff)
Improved nid command JID parsing.
Diffstat (limited to 'src/Network/Tox')
-rw-r--r--src/Network/Tox/NodeId.hs15
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
520data NoSpamId = NoSpamId NoSpam PublicKey 521data NoSpamId = NoSpamId NoSpam PublicKey
521 deriving (Eq,Ord) 522 deriving (Eq,Ord)
522 523
524noSpamIdToHex :: NoSpamId -> String
525noSpamIdToHex (NoSpamId nspam pub) = C8.unpack (Base16.encode $ BA.convert pub)
526 ++ nospam16 nspam
527
528nospam16 :: NoSpam -> String
529nospam16 (NoSpam w32 Nothing) = n ++ "????"
530 where n = take 8 $ nospam16 (NoSpam w32 (Just 0))
531nospam16 (NoSpam w32 (Just w16)) = C8.unpack $ Base16.encode $ runPut $ do
532 put w32
533 put w16
523 534
524nospam64 :: NoSpam -> String 535nospam64 :: NoSpam -> String
525nospam64 (NoSpam w32 Nothing) = n ++ "???" 536nospam64 (NoSpam w32 Nothing) = n ++ "???"
@@ -549,7 +560,9 @@ parseNoSpamId spec | Text.length spec == 76
549 560
550parseNoSpamJID :: Text -> Either String NoSpamId 561parseNoSpamJID :: Text -> Either String NoSpamId
551parseNoSpamJID jid = do 562parseNoSpamJID 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."