Skip to content

skythen/apdu

Repository files navigation

APDU

CI codecov GoDoc Go Report Card

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.

Install

go get github.com/skythen/apdu

Command APDU (Capdu)

Parse from bytes or hex string

c, err := apdu.ParseCapdu([]byte{0x80, 0xF2, 0xE0, 0x02, 0x02, 0x4F, 0x00, 0x00})

c, err := apdu.ParseCapduHexString("80F2E002024F0000")

Create from struct

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}

Convert to bytes or hex string

The APDU case and format (standard/extended) are determined automatically.

b, err := c.Bytes()
s, err := c.String()

Check extended length

if c.IsExtendedLength() {
    // len(Data) > 255 or Ne > 256
}

Response APDU (Rapdu)

Parse from bytes or hex string

r, err := apdu.ParseRapdu([]byte{0x01, 0x02, 0x03, 0x90, 0x00})

r, err := apdu.ParseRapduHexString("0102039000")

Create from struct

r := apdu.Rapdu{Data: []byte{0x01, 0x02, 0x03}, SW1: 0x90, SW2: 0x00}

Convert to bytes or hex string

b, err := r.Bytes()
s, err := r.String()

Check response status

r.IsSuccess() // SW1=0x61xx or SW1SW2=0x9000
r.IsWarning() // SW1=0x62xx or SW1=0x63xx
r.IsError()   // SW1=0x64xx, 0x65xx, or 0x67xx-0x6Fxx

About

Go APDU

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors