summaryrefslogtreecommitdiff
path: root/ToxCrypto.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-08-30 06:17:23 -0400
committerjoe <joe@jerkface.net>2017-08-30 06:17:23 -0400
commit2d0d30e70bea230ede343bd1cc2700b11becb494 (patch)
tree1650c5339a90c29a33624a5caf0f8841d6741023 /ToxCrypto.hs
parent9d16ca2529a184309cbd50bd3b6bc228b31c5e91 (diff)
More progress on ToxTransport and related modules.
Diffstat (limited to 'ToxCrypto.hs')
-rw-r--r--ToxCrypto.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/ToxCrypto.hs b/ToxCrypto.hs
index 98e02e91..cae7e251 100644
--- a/ToxCrypto.hs
+++ b/ToxCrypto.hs
@@ -17,6 +17,8 @@ module ToxCrypto
17 , getRemainingEncrypted 17 , getRemainingEncrypted
18 , putEncrypted 18 , putEncrypted
19 , Auth 19 , Auth
20 , Sized(..)
21 , Size(..)
20 ) where 22 ) where
21 23
22import qualified Crypto.Cipher.Salsa as Salsa 24import qualified Crypto.Cipher.Salsa as Salsa
@@ -81,6 +83,13 @@ instance Sized a => Serialize (Encrypted a) where
81 ConstSize n -> Encrypted <$> getBytes (16 + n) -- 16 extra for Poly1305 mac 83 ConstSize n -> Encrypted <$> getBytes (16 + n) -- 16 extra for Poly1305 mac
82 put = putEncrypted 84 put = putEncrypted
83 85
86instance (Sized a, Sized b) => Sized (a,b) where
87 size = case (size :: Size a, size :: Size b) of
88 (ConstSize a , ConstSize b) -> ConstSize $ a + b
89 (VarSize f , ConstSize b) -> VarSize $ \(a, _) -> f a + b
90 (ConstSize a , VarSize g) -> VarSize $ \(_, b) -> a + g b
91 (VarSize f , VarSize g) -> VarSize $ \(a, b) -> f a + g b
92
84getRemainingEncrypted :: Get (Encrypted a) 93getRemainingEncrypted :: Get (Encrypted a)
85getRemainingEncrypted = Encrypted <$> (remaining >>= getBytes) 94getRemainingEncrypted = Encrypted <$> (remaining >>= getBytes)
86 95