mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
0ebf1da05d
* core: WebRTC frames encryption * test
19 lines
679 B
Haskell
19 lines
679 B
Haskell
module WebRTCTests where
|
|
|
|
import Crypto.Random (getRandomBytes)
|
|
import qualified Data.ByteString.Base64.URL as U
|
|
import qualified Data.ByteString.Char8 as B
|
|
import Simplex.Chat.Mobile.WebRTC
|
|
import Test.Hspec
|
|
|
|
webRTCTests :: Spec
|
|
webRTCTests = describe "WebRTC crypto" $ do
|
|
it "encrypts and decrypts media" $ do
|
|
key <- U.encode <$> getRandomBytes 32
|
|
frame <- getRandomBytes 1000
|
|
let reservedSize = authTagSize + ivSize
|
|
frame' <- chatEncryptMedia key $ frame <> B.replicate reservedSize '\NUL'
|
|
B.length frame' `shouldBe` B.length frame + reservedSize
|
|
frame'' <- chatDecryptMedia key frame'
|
|
frame'' `shouldBe` frame <> B.replicate reservedSize '\NUL'
|