Package apdu implements encoding and decoding of Application Protocol Data Units (APDU) as defined in ISO 7816-4. Both standard and extended length APDUs are supported.
go get github.com/skythen/apdu
c, err := apdu.ParseCapdu([]byte{0x80, 0xF2, 0xE0, 0x02, 0x02, 0x4F, 0x00, 0x00})
c, err := apdu.ParseCapduHexString("80F2E002024F0000")Ne is the expected number of response bytes (not the encoded LE value).
c := apdu.Capdu{Cla: 0x00, Ins: 0xA4, P1: 0x04, P2: 0x00, Data: []byte{0xA0, 0x00, 0x00, 0x00, 0x03}, Ne: 256}The APDU case and format (standard/extended) are determined automatically.
b, err := c.Bytes()
s, err := c.String()if c.IsExtendedLength() {
// len(Data) > 255 or Ne > 256
}r, err := apdu.ParseRapdu([]byte{0x01, 0x02, 0x03, 0x90, 0x00})
r, err := apdu.ParseRapduHexString("0102039000")r := apdu.Rapdu{Data: []byte{0x01, 0x02, 0x03}, SW1: 0x90, SW2: 0x00}b, err := r.Bytes()
s, err := r.String()r.IsSuccess() // SW1=0x61xx or SW1SW2=0x9000
r.IsWarning() // SW1=0x62xx or SW1=0x63xx
r.IsError() // SW1=0x64xx, 0x65xx, or 0x67xx-0x6Fxx