summaryrefslogtreecommitdiff
path: root/src/Network/Tox/NodeId.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox/NodeId.hs')
-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."