diff options
Diffstat (limited to 'ToxCrypto.hs')
-rw-r--r-- | ToxCrypto.hs | 9 |
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 | ||
22 | import qualified Crypto.Cipher.Salsa as Salsa | 24 | import 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 | ||
86 | instance (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 | |||
84 | getRemainingEncrypted :: Get (Encrypted a) | 93 | getRemainingEncrypted :: Get (Encrypted a) |
85 | getRemainingEncrypted = Encrypted <$> (remaining >>= getBytes) | 94 | getRemainingEncrypted = Encrypted <$> (remaining >>= getBytes) |
86 | 95 | ||