Wrote decrypt tests
This commit is contained in:
parent
c8997b998a
commit
373cd7b621
|
@ -1,6 +1,7 @@
|
|||
package doubleratchet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
@ -105,7 +106,7 @@ func TestState_RatchetEncryptDecrypt_Basic(t *testing.T) {
|
|||
require.NotEmpty(t, m.Ciphertext)
|
||||
}
|
||||
|
||||
func TestState_RatchetDecrypt_BasicCommunication(t *testing.T) {
|
||||
func TestState_RatchetDecrypt_BasicCommunicationAliceSends(t *testing.T) {
|
||||
// Arrange.
|
||||
var (
|
||||
bobI, _ = New(sk)
|
||||
|
@ -113,18 +114,46 @@ func TestState_RatchetDecrypt_BasicCommunication(t *testing.T) {
|
|||
|
||||
aliceI, _ = New(sk, WithRemoteKey(bob.DHs.PublicKey()))
|
||||
alice = aliceI.(*state)
|
||||
|
||||
pt = []byte("1337")
|
||||
)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
pt := fmt.Sprintf("msg%d", i)
|
||||
t.Run(pt, func(t *testing.T) {
|
||||
// Act.
|
||||
var (
|
||||
m = alice.RatchetEncrypt(pt, nil)
|
||||
m = alice.RatchetEncrypt([]byte(pt), nil)
|
||||
decrypted, err = bob.RatchetDecrypt(m, nil)
|
||||
)
|
||||
|
||||
// Assert.
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, pt, decrypted)
|
||||
require.Equal(t, []byte(pt), decrypted)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestState_RatchetDecrypt_BasicCommunicationBobSends(t *testing.T) {
|
||||
// Arrange.
|
||||
var (
|
||||
bobI, _ = New(sk)
|
||||
bob = bobI.(*state)
|
||||
|
||||
aliceI, _ = New(sk, WithRemoteKey(bob.DHs.PublicKey()))
|
||||
alice = aliceI.(*state)
|
||||
)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
pt := fmt.Sprintf("msg%d", i)
|
||||
t.Run(pt, func(t *testing.T) {
|
||||
// Act.
|
||||
var (
|
||||
m = bob.RatchetEncrypt([]byte(pt), nil)
|
||||
decrypted, err = alice.RatchetDecrypt(m, nil)
|
||||
)
|
||||
|
||||
// Assert.
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, []byte(pt), decrypted)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue