Documentation ¶
Overview ¶
Package smartcard implements a portable high-level API for communicating with smart cards.
Example:
ctx, err := smartcard.EstablishContext() // handle error, if any defer ctx.Release() reader, err := ctx.WaitForCardPresent() // handle error, if any card, err := reader.Connect() // handle error, if any defer card.Disconnect() fmt.Printf("Card ATR: %s\n", card.ATR()) command := SelectCommand(0xa0, 0x00, 0x00, 0x00, 0x62, 0x03, 0x01, 0xc, 0x01, 0x01) response, err := card.TransmitAPDU(command) // handle error, if any fmt.Printf("Response: %s\n", response)
Index ¶
Constants ¶
const ( // Scope SCOPE_USER = pcsc.CARD_SCOPE_USER SCOPE_TERMINAL = pcsc.CARD_SCOPE_TERMINAL SCOPE_SYSTEM = pcsc.CARD_SCOPE_SYSTEM )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Card ¶
type Card struct {
// contains filtered or unexported fields
}
Smart card.
func (*Card) TransmitAPDU ¶
func (c *Card) TransmitAPDU(cmd CommandAPDU) (ResponseAPDU, error)
Transmit command APDU to the card and return response.
type CommandAPDU ¶
type CommandAPDU []byte
ISO7816-4 command APDU.
func Command1 ¶
func Command1(cla, ins, p1, p2 byte) CommandAPDU
Create command APDU with CLA, INS, P1, P2 as specified. No command data, no response required.
func Command2 ¶
func Command2(cla, ins, p1, p2, le byte) CommandAPDU
Create command APDU with CLA, INS, P1, P2 as specified. Response of length Le required.
func Command3 ¶
func Command3(cla, ins, p1, p2 byte, data []byte) CommandAPDU
Create command APDU with CLA, INS, P1, P2 and data as specified. No response required.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
A smart card context is required to access readers and cards.
func EstablishContext ¶
Establish smart card context. This should be the first function to be called.
func (*Context) ListReaders ¶
List all smart card readers.
func (*Context) ListReadersWithCard ¶
List smart card readers with inserted cards.
func (*Context) WaitForCardPresent ¶
Block until a smart card is inserted into any reader. Returns immediately if card already present.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Smart card reader. Note that physical card readers with slots for multiple cards are represented by one Reader instance per slot.
func (*Reader) WaitUntilCardRemoved ¶
func (r *Reader) WaitUntilCardRemoved()
type ResponseAPDU ¶
type ResponseAPDU []byte
ISO7816-4 response APDU.
func Response ¶
func Response(bytes []byte) (ResponseAPDU, error)