apdu

package
v0.0.0-...-8d18b63 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SwOK is returned from smartcards as a positive response code.
	SwOK = 0x9000
)

Variables

View Source
var (
	ErrUnsupportedLenth80 = errors.New("length cannot be 0x80")
	ErrLengthTooBig       = errors.New("length cannot be more than 3 bytes")
)
View Source
var ErrBadRawResponse = errors.New("response data must be at least 2 bytes")

ErrBadRawResponse is an error returned by ParseResponse in case the response data is not long enough.

Functions

func FindTag

func FindTag(raw []byte, tags ...uint8) ([]byte, error)

FindTag searches for a tag value within a TLV sequence.

func FindTagN

func FindTagN(raw []byte, n int, tags ...uint8) ([]byte, error)

FindTagN searches for a tag value within a TLV sequence and returns the n occurrence

Types

type Command

type Command struct {
	Cla  uint8
	Ins  uint8
	P1   uint8
	P2   uint8
	Data []byte
	// contains filtered or unexported fields
}

Command struct represent the data sent as an APDU command with CLA, Ins, P1, P2, Lc, Data, and Le.

func NewCommand

func NewCommand(cla, ins, p1, p2 uint8, data []byte) *Command

NewCommand returns a new apdu Command.

func (*Command) Le

func (c *Command) Le() (bool, uint8)

Le returns if Le is set and its value.

func (*Command) Serialize

func (c *Command) Serialize() ([]byte, error)

Serialize serielizes the command into a raw bytes sequence.

func (*Command) SetLe

func (c *Command) SetLe(le uint8)

SetLe sets the expected Le value and makes sure the Le value is sent in the apdu Command.

type ErrBadResponse

type ErrBadResponse struct {
	Sw uint16
	// contains filtered or unexported fields
}

ErrBadResponse defines an error conaining the returned Sw code and a description message.

func NewErrBadResponse

func NewErrBadResponse(sw uint16, message string) *ErrBadResponse

NewErrBadResponse returns a ErrBadResponse with the specified sw and message values.

func (*ErrBadResponse) Error

func (e *ErrBadResponse) Error() string

Error implements the error interface.

type ErrTagNotFound

type ErrTagNotFound struct {
	// contains filtered or unexported fields
}

ErrTagNotFound is an error returned if a tag is not found in a TLV sequence.

func (*ErrTagNotFound) Error

func (e *ErrTagNotFound) Error() string

Error implements the error interface

type Response

type Response struct {
	Data []byte
	Sw1  uint8
	Sw2  uint8
	Sw   uint16
}

Response represents a struct containing the smartcard response fields.

func ParseResponse

func ParseResponse(data []byte) (*Response, error)

ParseResponse parses a raw response and return a Response.

func (*Response) IsOK

func (r *Response) IsOK() bool

IsOK returns true if the response Sw code is 0x9000.

Jump to

Keyboard shortcuts

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