diff options
author | joe <joe@jerkface.net> | 2017-10-18 20:55:56 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-10-18 20:55:56 -0400 |
commit | 3b8c8d74db95fa8dc345a73101d2c1921655c70d (patch) | |
tree | 3227ac1e43e7222ea2bf5e53c6b502e9a7838b9b /src/Crypto/Tox.hs | |
parent | 35aed24bdd67cecbd77e0c64c6c054e736aac787 (diff) |
WIP: Command to publish a toxid on a given node.
Diffstat (limited to 'src/Crypto/Tox.hs')
-rw-r--r-- | src/Crypto/Tox.hs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Crypto/Tox.hs b/src/Crypto/Tox.hs index d6f63f18..b86a5395 100644 --- a/src/Crypto/Tox.hs +++ b/src/Crypto/Tox.hs | |||
@@ -49,6 +49,7 @@ module Crypto.Tox | |||
49 | ) where | 49 | ) where |
50 | 50 | ||
51 | import Control.Arrow | 51 | import Control.Arrow |
52 | import Control.Monad | ||
52 | import qualified Crypto.Cipher.ChaChaPoly1305 as Symmetric | 53 | import qualified Crypto.Cipher.ChaChaPoly1305 as Symmetric |
53 | import qualified Crypto.Cipher.Salsa as Salsa | 54 | import qualified Crypto.Cipher.Salsa as Salsa |
54 | import qualified Crypto.Cipher.XSalsa as XSalsa | 55 | import qualified Crypto.Cipher.XSalsa as XSalsa |
@@ -260,6 +261,7 @@ bin2hex = C8.unpack . Base16.encode . BA.convert | |||
260 | bin2base64 :: ByteArrayAccess bs => bs -> String | 261 | bin2base64 :: ByteArrayAccess bs => bs -> String |
261 | bin2base64 = C8.unpack . Base64.encode . BA.convert | 262 | bin2base64 = C8.unpack . Base64.encode . BA.convert |
262 | 263 | ||
264 | |||
263 | instance Show Nonce24 where | 265 | instance Show Nonce24 where |
264 | showsPrec d nonce = quoted (mappend $ bin2hex nonce) | 266 | showsPrec d nonce = quoted (mappend $ bin2hex nonce) |
265 | 267 | ||
@@ -298,6 +300,16 @@ newtype Nonce32 = Nonce32 ByteString | |||
298 | instance Show Nonce32 where | 300 | instance Show Nonce32 where |
299 | showsPrec d nonce = mappend $ bin2base64 nonce | 301 | showsPrec d nonce = mappend $ bin2base64 nonce |
300 | 302 | ||
303 | instance Read Nonce32 where | ||
304 | readsPrec _ str = either (const []) id $ do | ||
305 | let (ds,ss) = Prelude.splitAt 43 str | ||
306 | ss' <- case ss of | ||
307 | '=':xs -> Right xs -- optional terminating '=' | ||
308 | _ -> Right ss | ||
309 | bs <- Base64.decode (C8.pack $ ds ++ ['=']) | ||
310 | guard $ B.length bs == 32 | ||
311 | return [ (Nonce32 bs, ss') ] | ||
312 | |||
301 | instance Serialize Nonce32 where | 313 | instance Serialize Nonce32 where |
302 | get = Nonce32 <$> getBytes 32 | 314 | get = Nonce32 <$> getBytes 32 |
303 | put (Nonce32 bs) = putByteString bs | 315 | put (Nonce32 bs) = putByteString bs |
@@ -350,6 +362,8 @@ data TransportCrypto = TransportCrypto | |||
350 | , transportPublic :: PublicKey | 362 | , transportPublic :: PublicKey |
351 | , onionAliasSecret :: SecretKey | 363 | , onionAliasSecret :: SecretKey |
352 | , onionAliasPublic :: PublicKey | 364 | , onionAliasPublic :: PublicKey |
365 | , rendezvousSecret :: SecretKey | ||
366 | , rendezvousPublic :: PublicKey | ||
353 | , transportSymmetric :: STM SymmetricKey | 367 | , transportSymmetric :: STM SymmetricKey |
354 | , transportNewNonce :: STM Nonce24 | 368 | , transportNewNonce :: STM Nonce24 |
355 | } | 369 | } |