summaryrefslogtreecommitdiff
path: root/src/Crypto/Tox.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Crypto/Tox.hs')
-rw-r--r--src/Crypto/Tox.hs14
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
51import Control.Arrow 51import Control.Arrow
52import Control.Monad
52import qualified Crypto.Cipher.ChaChaPoly1305 as Symmetric 53import qualified Crypto.Cipher.ChaChaPoly1305 as Symmetric
53import qualified Crypto.Cipher.Salsa as Salsa 54import qualified Crypto.Cipher.Salsa as Salsa
54import qualified Crypto.Cipher.XSalsa as XSalsa 55import qualified Crypto.Cipher.XSalsa as XSalsa
@@ -260,6 +261,7 @@ bin2hex = C8.unpack . Base16.encode . BA.convert
260bin2base64 :: ByteArrayAccess bs => bs -> String 261bin2base64 :: ByteArrayAccess bs => bs -> String
261bin2base64 = C8.unpack . Base64.encode . BA.convert 262bin2base64 = C8.unpack . Base64.encode . BA.convert
262 263
264
263instance Show Nonce24 where 265instance 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
298instance Show Nonce32 where 300instance Show Nonce32 where
299 showsPrec d nonce = mappend $ bin2base64 nonce 301 showsPrec d nonce = mappend $ bin2base64 nonce
300 302
303instance 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
301instance Serialize Nonce32 where 313instance 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 }