keycard-go/apdu/response_test.go

35 lines
884 B
Go
Raw Normal View History

2018-09-14 13:30:16 +02:00
package apdu
import (
"testing"
2018-10-19 10:54:02 +02:00
"github.com/status-im/smartcard-go/hexutils"
2018-09-14 13:30:16 +02:00
"github.com/stretchr/testify/assert"
)
func TestParseResponse(t *testing.T) {
2018-09-27 11:23:12 +02:00
raw := hexutils.HexToBytes("000002650183039536622002003b5e508f751c0af3016e3fbc23d3a69000")
2018-09-14 13:30:16 +02:00
resp, err := ParseResponse(raw)
assert.NoError(t, err)
assert.Equal(t, uint8(0x90), resp.Sw1)
assert.Equal(t, uint8(0x00), resp.Sw2)
assert.Equal(t, uint16(0x9000), resp.Sw)
expected := "000002650183039536622002003B5E508F751C0AF3016E3FBC23D3A6"
2018-09-27 11:23:12 +02:00
assert.Equal(t, expected, hexutils.BytesToHex(resp.Data))
2018-09-14 13:30:16 +02:00
}
func TestParseResponse_BadData(t *testing.T) {
2018-09-27 11:23:12 +02:00
raw := hexutils.HexToBytes("")
2018-09-14 13:30:16 +02:00
_, err := ParseResponse(raw)
assert.Equal(t, ErrBadRawResponse, err)
}
2018-09-25 17:48:21 +02:00
func TestResp_IsOK(t *testing.T) {
2018-09-27 11:23:12 +02:00
raw := hexutils.HexToBytes("01029000")
2018-09-25 17:48:21 +02:00
resp, err := ParseResponse(raw)
assert.NoError(t, err)
assert.True(t, resp.IsOK())
}