apdu

package
v0.4.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package apdu implements the ISO/IEC 7816-4 command and response APDU subset used by Token2 devices.

Index

Constants

View Source
const (
	// StatusSuccess is the ISO/IEC 7816 success status word.
	StatusSuccess uint16 = 0x9000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	CLA byte
	INS byte
	P1  byte
	P2  byte

	Data     []byte
	Extended bool
}

Command describes a command APDU. The encoder supports the cases currently used by Token2: a four-byte header with optional short or extended data.

func (Command) Bytes

func (c Command) Bytes() []byte

Bytes encodes the command APDU.

type Response

type Response struct {
	Data []byte
	SW   uint16
}

Response is a parsed response APDU.

func Exchange

func Exchange(ctx context.Context, card Transceiver, command Command) (Response, error)

Exchange sends command and follows ISO GET RESPONSE status words until the device returns a final response.

func ParseResponse

func ParseResponse(response []byte) (Response, error)

ParseResponse separates response data from the trailing status word.

func (Response) Err

func (r Response) Err(operation string) error

Err returns nil for a successful response and a StatusError otherwise.

func (Response) OK

func (r Response) OK() bool

OK reports whether the response status is 9000.

type StatusError

type StatusError struct {
	Operation string
	SW        uint16
}

StatusError reports a non-success APDU status for a logical operation.

func (*StatusError) Error

func (e *StatusError) Error() string

type Transceiver

type Transceiver interface {
	Transmit(context.Context, []byte) ([]byte, error)
}

Transceiver sends one encoded command APDU and returns one encoded response APDU.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL