1package keycard
2
3import (
4	"errors"
5	"testing"
6
7	"github.com/status-im/keycard-go/apdu"
8	"github.com/status-im/keycard-go/hexutils"
9	"github.com/stretchr/testify/assert"
10)
11
12type fakeChannel struct {
13	lastCmd *apdu.Command
14}
15
16func (fc *fakeChannel) Send(cmd *apdu.Command) (*apdu.Response, error) {
17	fc.lastCmd = cmd
18	return nil, errors.New("test error")
19}
20
21func TestSecureChannel_Send(t *testing.T) {
22	c := &fakeChannel{}
23	sc := &SecureChannel{
24		c:      c,
25		encKey: hexutils.HexToBytes("FDBCB1637597CF3F8F5E8263007D4E45F64C12D44066D4576EB1443D60AEF441"),
26		macKey: hexutils.HexToBytes("2FB70219E6635EE0958AB3F7A428BA87E8CD6E6F873A5725A55F25B102D0F1F7"),
27		iv:     hexutils.HexToBytes("627E64358FA9BDCDAD4442BD8006E0A5"),
28		open:   true,
29	}
30
31	data := hexutils.HexToBytes("D545A5E95963B6BCED86A6AE826D34C5E06AC64A1217EFFA1415A96674A82500")
32
33	cmd := NewCommandMutuallyAuthenticate(data)
34	sc.Send(cmd)
35
36	expectedData := "BA796BF8FAD1FD50407B87127B94F5023EF8903AE926EAD8A204F961B8A0EDAEE7CCCFE7F7F6380CE2C6F188E598E4468B7DEDD0E807C18CCBDA71A55F3E1F9A"
37	assert.Equal(t, expectedData, hexutils.BytesToHex(c.lastCmd.Data))
38
39	expectedIV := "BA796BF8FAD1FD50407B87127B94F502"
40	assert.Equal(t, expectedIV, hexutils.BytesToHex(sc.iv))
41}
42