2018-09-25 13:26:06 +00:00
|
|
|
package apdu
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-10-19 08:54:02 +00:00
|
|
|
"github.com/status-im/smartcard-go/hexutils"
|
2018-09-25 13:26:06 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFindTag(t *testing.T) {
|
|
|
|
var (
|
|
|
|
tagData []byte
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2018-09-27 09:23:12 +00:00
|
|
|
data := hexutils.HexToBytes("C1 02 BB CC C2 04 C3 02 11 22 C3 02 88 99")
|
2018-09-25 13:26:06 +00:00
|
|
|
|
|
|
|
tagData, err = FindTag(data, uint8(0xC1))
|
|
|
|
assert.NoError(t, err)
|
2018-09-27 09:23:12 +00:00
|
|
|
assert.Equal(t, "BB CC", hexutils.BytesToHexWithSpaces(tagData))
|
2018-09-25 13:26:06 +00:00
|
|
|
|
|
|
|
tagData, err = FindTag(data, uint8(0xC2))
|
|
|
|
assert.NoError(t, err)
|
2018-09-27 09:23:12 +00:00
|
|
|
assert.Equal(t, "C3 02 11 22", hexutils.BytesToHexWithSpaces(tagData))
|
2018-09-25 13:26:06 +00:00
|
|
|
|
|
|
|
tagData, err = FindTag(data, uint8(0xC3))
|
|
|
|
assert.NoError(t, err)
|
2018-09-27 09:23:12 +00:00
|
|
|
assert.Equal(t, "88 99", hexutils.BytesToHexWithSpaces(tagData))
|
2018-09-25 13:26:06 +00:00
|
|
|
|
|
|
|
tagData, err = FindTag(data, uint8(0xC2), uint8(0xC3))
|
|
|
|
assert.NoError(t, err)
|
2018-09-27 09:23:12 +00:00
|
|
|
assert.Equal(t, "11 22", hexutils.BytesToHexWithSpaces(tagData))
|
2018-09-25 13:26:06 +00:00
|
|
|
|
|
|
|
// tag not found
|
2018-09-27 09:23:12 +00:00
|
|
|
data = hexutils.HexToBytes("C1 00")
|
2018-09-25 15:44:25 +00:00
|
|
|
_, err = FindTag(data, uint8(0xC2))
|
2018-09-25 13:26:06 +00:00
|
|
|
assert.Equal(t, &ErrTagNotFound{uint8(0xC2)}, err)
|
|
|
|
|
|
|
|
// sub-tag not found
|
2018-09-27 09:23:12 +00:00
|
|
|
data = hexutils.HexToBytes("C1 02 C2 00")
|
2018-09-25 15:44:25 +00:00
|
|
|
_, err = FindTag(data, uint8(0xC1), uint8(0xC3))
|
2018-09-25 13:26:06 +00:00
|
|
|
assert.Equal(t, &ErrTagNotFound{uint8(0xC3)}, err)
|
|
|
|
}
|