transport

package
v0.0.0-...-15d4781 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2019 License: ISC Imports: 7 Imported by: 0

Documentation

Overview

Package transport defines smart card transports

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterTransport

func RegisterTransport(name string, factory TransportFactory)

RegisterTransport registers a transport factory

Types

type Card

type Card interface {
	// Lock locks the card for exclusive use.
	// You should minimize the amount of time you lock
	// cards for (as this prevents other applications
	// from using the card) but it is necessary around multiple
	// command operations
	Lock() error

	// Unlock unlocks the card
	Unlock() error

	// Transact sends a request to the card and gets a response
	Transact(ReqAPDU) (RespAPDU, error)

	// Close connection to the card
	Close() error
}

type OnReaderStateChange

type OnReaderStateChange func(ctx context.Context, states []ReaderState)

type ReaderState

type ReaderState struct {
	// ID of the Reader, which can be used to connect to cards
	ID string

	// CardInserted indicates that a card is present in the reader
	CardInserted bool

	// ATR is the ATR of the inserted card (if one is inserted)
	ATR []byte
}

type ReqAPDU

type ReqAPDU struct {
	Cla  byte
	Ins  byte
	P1   byte
	P2   byte
	Data []byte
	Le   uint
}

func (ReqAPDU) Serialize

func (apdu ReqAPDU) Serialize() ([]byte, error)

type RespAPDU

type RespAPDU struct {
	SW1  byte
	SW2  byte
	Data []byte
}

func ParseRespAPDU

func ParseRespAPDU(data []byte) (RespAPDU, error)

func (*RespAPDU) OK

func (r *RespAPDU) OK() bool

type Transport

type Transport interface {
	Info() TransportInfo
	Readers() []ReaderState
	OnReaderStateChange(ctx context.Context, cb OnReaderStateChange)
	ConnectCard(ID string) (Card, error)
	Close()
}

func New

func New(descr string) (Transport, error)

New creates a transport from a description. If the description contains a colon, then the part preceding the colon is interpreted as a driver name and the portion following as parameters. If no colon is present, then the entire description is interpreted as a driver name

func NewSCardTransport

func NewSCardTransport(params string) (Transport, error)

type TransportFactory

type TransportFactory func(params string) (Transport, error)

type TransportInfo

type TransportInfo struct {
	// ID of the transport, which can be used to construct
	// new instances
	ID string

	// DisplayName is a human readable name for the transport
	DisplayName string
}

Jump to

Keyboard shortcuts

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