2017-06-19 14:21:57 +00:00
|
|
|
package doubleratchet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2018-08-21 09:18:46 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2017-06-19 14:21:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
sk = Key{0xeb, 0x8, 0x10, 0x7c, 0x33, 0x54, 0x0, 0x20, 0xe9, 0x4f, 0x6c, 0x84, 0xe4, 0x39, 0x50, 0x5a, 0x2f, 0x60, 0xbe, 0x81, 0xa, 0x78, 0x8b, 0xeb, 0x1e, 0x2c, 0x9, 0x8d, 0x4b, 0x4d, 0xc1, 0x40}
|
|
|
|
bobPair = dhPair{
|
|
|
|
privateKey: Key{0xf0, 0x22, 0x54, 0xf4, 0xcb, 0xa2, 0x60, 0xc8, 0xeb, 0xe, 0x83, 0xb, 0xc8, 0xb2, 0xfb, 0x18, 0x6f, 0x1b, 0xa4, 0xa2, 0x6e, 0x45, 0xc, 0xeb, 0xff, 0x74, 0xce, 0x65, 0x8b, 0x6e, 0x4c, 0x5d},
|
|
|
|
publicKey: Key{0xe3, 0xbe, 0xb9, 0x4e, 0x70, 0x17, 0x37, 0xc, 0x1, 0x8f, 0xa9, 0x7e, 0xef, 0x4, 0xfb, 0x23, 0xac, 0xea, 0x28, 0xf7, 0xa9, 0x56, 0xcc, 0x1d, 0x46, 0xf3, 0xb5, 0x1d, 0x7d, 0x7d, 0x5e, 0x2c},
|
|
|
|
}
|
|
|
|
alicePair = dhPair{
|
|
|
|
privateKey: Key{0x78, 0xa1, 0x5e, 0xc7, 0xbe, 0x74, 0x9f, 0x1, 0x4b, 0xdc, 0x21, 0xeb, 0x60, 0xd4, 0xff, 0xac, 0x1e, 0x31, 0x8b, 0x16, 0xf8, 0x12, 0xd4, 0x40, 0xd, 0x82, 0x7a, 0xf0, 0xe, 0xba, 0xc2, 0x7a},
|
|
|
|
publicKey: Key{0x3b, 0x93, 0x57, 0x64, 0xd1, 0x47, 0xf1, 0xf, 0xc7, 0x13, 0x1, 0xc6, 0xf9, 0xed, 0x49, 0xa4, 0xad, 0x59, 0x92, 0x87, 0xb1, 0x0, 0xf1, 0x4a, 0x8e, 0x43, 0x4d, 0xa7, 0x2e, 0x3d, 0xf8, 0x72},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewState_Basic(t *testing.T) {
|
|
|
|
// Act.
|
|
|
|
s, err := newState(sk)
|
|
|
|
|
|
|
|
// Assert.
|
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, sk, s.RootCh.CK)
|
|
|
|
require.NotNil(t, sk, s.RootCh.Crypto)
|
|
|
|
|
|
|
|
require.Equal(t, sk, s.SendCh.CK)
|
|
|
|
require.NotNil(t, sk, s.SendCh.Crypto)
|
|
|
|
require.Empty(t, s.SendCh.N)
|
|
|
|
|
|
|
|
require.Equal(t, sk, s.RecvCh.CK)
|
|
|
|
require.NotNil(t, sk, s.RecvCh.Crypto)
|
|
|
|
require.Empty(t, s.RecvCh.N)
|
|
|
|
|
2019-10-31 15:13:07 +00:00
|
|
|
require.Nil(t, s.DHr)
|
2017-06-19 14:21:57 +00:00
|
|
|
require.Equal(t, dhPair{}, s.DHs)
|
|
|
|
|
|
|
|
require.Empty(t, s.PN)
|
|
|
|
require.NotEmpty(t, s.MaxSkip)
|
|
|
|
require.NotEmpty(t, s.MaxKeep)
|
|
|
|
|
|
|
|
require.NotNil(t, s.MkSkipped)
|
|
|
|
require.NotNil(t, s.Crypto)
|
|
|
|
}
|
|
|
|
|
2017-06-19 15:56:13 +00:00
|
|
|
func TestNewState_BadSharedKey(t *testing.T) {
|
2017-06-19 14:21:57 +00:00
|
|
|
// Act.
|
2019-10-31 15:13:07 +00:00
|
|
|
_, err := newState(nil)
|
2017-06-19 14:21:57 +00:00
|
|
|
|
|
|
|
// Assert.
|
|
|
|
require.NotNil(t, err)
|
|
|
|
}
|