Documentation
¶
Index ¶
- Constants
- Variables
- func ControlCode(function uint32) uint32
- func Enumerate() iter.Seq2[*ReaderInfo, error]
- type Attribute
- type Card
- func (card *Card) BeginTransaction(ctx context.Context) error
- func (card *Card) Close() error
- func (card *Card) Control(ctx context.Context, controlCode uint32, input []byte, responseSize int) ([]byte, error)
- func (card *Card) EndTransaction(disposition Disposition) error
- func (card *Card) GetAttribute(attribute Attribute) ([]byte, error)
- func (card *Card) Interface() CardInterface
- func (card *Card) Reconnect(ctx context.Context, shareMode ShareMode, preferredProtocols Protocol, ...) (Protocol, error)
- func (card *Card) SetAttribute(attribute Attribute, value []byte) error
- func (card *Card) Status() (*CardStatus, error)
- func (card *Card) Transmit(ctx context.Context, apdu []byte) ([]byte, error)
- type CardInterface
- type CardState
- type CardStatus
- type DeviceEvent
- type DeviceEventType
- type Disposition
- type Error
- type OpenOption
- type Protocol
- type ReaderInfo
- type ReaderState
- type ShareMode
- type Snapshot
- type Watcher
Constants ¶
const ( AttributeAsyncProtocolTypes Attribute = attributeClassProtocol<<16 | 0x0120 AttributeSyncProtocolTypes Attribute = attributeClassProtocol<<16 | 0x0126 AttributeDeviceFriendlyName = AttributeDeviceFriendlyNameA AttributeDeviceSystemName = AttributeDeviceSystemNameA )
Variables ¶
var ( ErrUnavailable = errors.New("pcsc: unavailable") ErrInternalError = errors.New("pcsc: internal error") ErrCanceled = errors.New("pcsc: canceled") ErrInvalidHandle = errors.New("pcsc: invalid handle") ErrInvalidParameter = errors.New("pcsc: invalid parameter") ErrInvalidTarget = errors.New("pcsc: invalid target") ErrNoMemory = errors.New("pcsc: not enough memory") ErrWaitedTooLong = errors.New("pcsc: waited too long") ErrTimeout = errors.New("pcsc: timeout") ErrInsufficientBuffer = errors.New("pcsc: insufficient buffer") ErrUnknownReader = errors.New("pcsc: unknown reader") ErrNoCard = errors.New("pcsc: no smart card") ErrUnknownCard = errors.New("pcsc: unknown card") ErrCannotDispose = errors.New("pcsc: cannot dispose") ErrProtocolMismatch = errors.New("pcsc: protocol mismatch") ErrNotReady = errors.New("pcsc: not ready") ErrInvalidValue = errors.New("pcsc: invalid value") ErrSystemCanceled = errors.New("pcsc: canceled by system") ErrCommunication = errors.New("pcsc: communication error") ErrUnknownError = errors.New("pcsc: unknown internal error") ErrInvalidATR = errors.New("pcsc: invalid ATR") ErrNotTransacted = errors.New("pcsc: not transacted") ErrShutdown = errors.New("pcsc: shutdown") ErrPCITooSmall = errors.New("pcsc: PCI buffer too small") ErrReaderUnsupported = errors.New("pcsc: reader unsupported") ErrDuplicateReader = errors.New("pcsc: duplicate reader") ErrCardUnsupported = errors.New("pcsc: card unsupported") ErrCardReset = errors.New("pcsc: card reset") ErrCardRemoved = errors.New("pcsc: card removed") ErrSharingViolation = errors.New("pcsc: sharing violation") ErrNoService = errors.New("pcsc: no service") ErrServiceStopped = errors.New("pcsc: service stopped") ErrUnexpected = errors.New("pcsc: unexpected error") ErrICCInstallation = errors.New("pcsc: ICC installation unavailable") ErrICCCreationOrder = errors.New("pcsc: ICC creation order unsupported") ErrUnsupportedFeature = errors.New("pcsc: unsupported feature") ErrDirectoryNotFound = errors.New("pcsc: directory not found") ErrFileNotFound = errors.New("pcsc: file not found") ErrNotDirectory = errors.New("pcsc: path is not a directory") ErrNotFile = errors.New("pcsc: path is not a file") ErrNoAccess = errors.New("pcsc: access denied") ErrWriteTooMany = errors.New("pcsc: insufficient card memory") ErrBadSeek = errors.New("pcsc: bad seek") ErrInvalidCHV = errors.New("pcsc: invalid CHV") ErrUnknownResourceManager = errors.New("pcsc: unknown resource manager error") ErrNoSuchCertificate = errors.New("pcsc: certificate not found") ErrNoReaders = errors.New("pcsc: no readers available") ErrCommunicationDataLost = errors.New("pcsc: communication data lost") ErrNoKeyContainer = errors.New("pcsc: key container not found") ErrServerTooBusy = errors.New("pcsc: server too busy") ErrUnsupportedCard = errors.New("pcsc: unsupported card") ErrUnresponsiveCard = errors.New("pcsc: unresponsive card") ErrUnpoweredCard = errors.New("pcsc: unpowered card") ErrSecurityViolation = errors.New("pcsc: security violation") ErrWrongCHV = errors.New("pcsc: wrong CHV") ErrCHVBlocked = errors.New("pcsc: CHV blocked") ErrEndOfFile = errors.New("pcsc: end of file") ErrCanceledByUser = errors.New("pcsc: canceled by user") ErrCardNotAuthenticated = errors.New("pcsc: card not authenticated") ErrClosed = errors.New("pcsc: card closed") )
Functions ¶
func ControlCode ¶
ControlCode converts a PC/SC function number to the platform control code accepted by Card.Control.
Types ¶
type Attribute ¶
type Attribute uint32
Attribute identifies a PC/SC reader or card attribute.
const ( AttributeVendorName Attribute = attributeClassVendorInfo<<16 | 0x0100 AttributeVendorIFDType Attribute = attributeClassVendorInfo<<16 | 0x0101 AttributeVendorIFDVersion Attribute = attributeClassVendorInfo<<16 | 0x0102 AttributeVendorIFDSerialNo Attribute = attributeClassVendorInfo<<16 | 0x0103 AttributeChannelID Attribute = attributeClassCommunication<<16 | 0x0110 AttributeDefaultCLK Attribute = attributeClassProtocol<<16 | 0x0121 AttributeMaxCLK Attribute = attributeClassProtocol<<16 | 0x0122 AttributeDefaultDataRate Attribute = attributeClassProtocol<<16 | 0x0123 AttributeMaxDataRate Attribute = attributeClassProtocol<<16 | 0x0124 AttributeMaxIFSD Attribute = attributeClassProtocol<<16 | 0x0125 )
const ( AttributePowerManagementSupport Attribute = attributeClassPower<<16 | 0x0131 AttributeUserToCardAuthDevice Attribute = attributeClassSecurity<<16 | 0x0140 AttributeUserAuthInputDevice Attribute = attributeClassSecurity<<16 | 0x0142 AttributeCharacteristics Attribute = attributeClassMechanical<<16 | 0x0150 )
const ( AttributeCurrentProtocolType Attribute = attributeClassIFDProtocol<<16 | 0x0201 AttributeCurrentCLK Attribute = attributeClassIFDProtocol<<16 | 0x0202 AttributeCurrentF Attribute = attributeClassIFDProtocol<<16 | 0x0203 AttributeCurrentD Attribute = attributeClassIFDProtocol<<16 | 0x0204 AttributeCurrentN Attribute = attributeClassIFDProtocol<<16 | 0x0205 AttributeCurrentW Attribute = attributeClassIFDProtocol<<16 | 0x0206 AttributeCurrentIFSC Attribute = attributeClassIFDProtocol<<16 | 0x0207 AttributeCurrentIFSD Attribute = attributeClassIFDProtocol<<16 | 0x0208 AttributeCurrentBWT Attribute = attributeClassIFDProtocol<<16 | 0x0209 AttributeCurrentCWT Attribute = attributeClassIFDProtocol<<16 | 0x020a AttributeCurrentEBCEncoding Attribute = attributeClassIFDProtocol<<16 | 0x020b AttributeExtendedBWT Attribute = attributeClassIFDProtocol<<16 | 0x020c )
const ( AttributeICCPresence Attribute = attributeClassICCState<<16 | 0x0300 AttributeICCInterfaceStatus Attribute = attributeClassICCState<<16 | 0x0301 AttributeCurrentIOState Attribute = attributeClassICCState<<16 | 0x0302 AttributeATRString Attribute = attributeClassICCState<<16 | 0x0303 AttributeICCTypePerATR Attribute = attributeClassICCState<<16 | 0x0304 )
const ( AttributeESCReset Attribute = attributeClassVendorDefined<<16 | 0xa000 AttributeESCCancel Attribute = attributeClassVendorDefined<<16 | 0xa003 AttributeESCAuthRequest Attribute = attributeClassVendorDefined<<16 | 0xa005 AttributeMaxInput Attribute = attributeClassVendorDefined<<16 | 0xa007 )
const ( AttributeDeviceUnit Attribute = attributeClassSystem<<16 | 0x0001 AttributeDeviceInUse Attribute = attributeClassSystem<<16 | 0x0002 AttributeDeviceFriendlyNameA Attribute = attributeClassSystem<<16 | 0x0003 AttributeDeviceSystemNameA Attribute = attributeClassSystem<<16 | 0x0004 AttributeDeviceFriendlyNameW Attribute = attributeClassSystem<<16 | 0x0005 AttributeDeviceSystemNameW Attribute = attributeClassSystem<<16 | 0x0006 // AttributeSupressT1IFSRequest retains the spelling used by the native // SCARD_ATTR_SUPRESS_T1_IFS_REQUEST constant. AttributeSupressT1IFSRequest Attribute = attributeClassSystem<<16 | 0x0007 )
type Card ¶
type Card struct {
// contains filtered or unexported fields
}
Card is a connection to a smart card. Context cancellation returns promptly, but the native operation may continue in the background on implementations that cannot cancel card operations, including pcsc-lite.
func Open ¶
func Open(reader string, opts ...OpenOption) (*Card, error)
Open connects to the card in reader. By default it uses shared access, negotiates T=0 or T=1, and leaves the card powered when closed.
func (*Card) BeginTransaction ¶
BeginTransaction prevents other PC/SC applications from interleaving card operations until EndTransaction is called.
func (*Card) Close ¶
Close prevents new operations, asks the native implementation to cancel an in-flight card operation when supported, waits for it to finish, disconnects from the card, and releases its PC/SC context.
func (*Card) Control ¶
func (card *Card) Control( ctx context.Context, controlCode uint32, input []byte, responseSize int, ) ([]byte, error)
Control sends a reader-specific control request using an output buffer of responseSize bytes. It does not retry the request because a control operation may have side effects.
func (*Card) EndTransaction ¶
func (card *Card) EndTransaction(disposition Disposition) error
EndTransaction releases a transaction and applies disposition to the card.
func (*Card) GetAttribute ¶
GetAttribute returns a reader or card attribute.
func (*Card) Interface ¶
func (card *Card) Interface() CardInterface
Interface returns the best-effort physical interface of the connected card. Drivers that do not expose enough information produce CardInterfaceUnknown.
func (*Card) Reconnect ¶
func (card *Card) Reconnect( ctx context.Context, shareMode ShareMode, preferredProtocols Protocol, initialization Disposition, ) (Protocol, error)
Reconnect changes the connection parameters and optionally resets the card.
func (*Card) SetAttribute ¶
SetAttribute sets a reader or card attribute.
func (*Card) Status ¶
func (card *Card) Status() (*CardStatus, error)
type CardInterface ¶
type CardInterface string
CardInterface identifies how a card is coupled to its reader.
const ( CardInterfaceUnknown CardInterface = "unknown" CardInterfaceContact CardInterface = "contact" CardInterfaceContactless CardInterface = "contactless" )
type CardState ¶
type CardState uint32
CardState is the state reported for an open card by SCardStatus. PC/SC uses platform-specific values for this type.
const ( CardStateUnknown CardState = 0x0001 CardStateAbsent CardState = 0x0002 CardStatePresent CardState = 0x0004 CardStateSwallowed CardState = 0x0008 CardStatePowered CardState = 0x0010 CardStateNegotiable CardState = 0x0020 CardStateSpecific CardState = 0x0040 )
pcsc-lite and Apple's PCSC framework report SCardStatus states as a bitmask.
type CardStatus ¶
type CardStatus struct {
// ReaderNames contains every reader name or alias returned by SCardStatus.
ReaderNames []string
State CardState
Protocol Protocol
ATR []byte
}
CardStatus is a snapshot of a connected card.
type DeviceEvent ¶
type DeviceEvent struct {
Type DeviceEventType
ReaderInfo *ReaderInfo
}
DeviceEvent describes a PC/SC reader or card-presence change.
type DeviceEventType ¶
type DeviceEventType string
const ( DeviceEventReaderConnected DeviceEventType = "reader-connected" DeviceEventReaderDisconnected DeviceEventType = "reader-disconnected" DeviceEventCardInserted DeviceEventType = "card-inserted" DeviceEventCardRemoved DeviceEventType = "card-removed" )
type Disposition ¶
type Disposition uint32
Disposition controls what PC/SC does with a card when a connection or transaction ends.
const ( DispositionLeaveCard Disposition = 0 DispositionResetCard Disposition = 1 DispositionUnpowerCard Disposition = 2 DispositionEjectCard Disposition = 3 )
type OpenOption ¶
type OpenOption func(*openOptions)
func WithDisconnectDisposition ¶
func WithDisconnectDisposition(disposition Disposition) OpenOption
WithDisconnectDisposition configures what Close does with the card.
func WithPreferredProtocols ¶
func WithPreferredProtocols(protocols Protocol) OpenOption
WithPreferredProtocols configures the protocols offered to SCardConnect.
func WithShareMode ¶
func WithShareMode(mode ShareMode) OpenOption
WithShareMode configures how the card connection is shared with other applications.
type Protocol ¶
type Protocol uint32
Protocol is the transport protocol negotiated with a card.
const ( ProtocolRaw Protocol = 0x0004 ProtocolAny Protocol = ProtocolT0 | ProtocolT1 )
type ReaderInfo ¶
type ReaderInfo struct {
Name string
State ReaderState
ATR []byte
}
ReaderInfo describes a PC/SC reader snapshot. Name is the reader name accepted by Open for this snapshot.
type ReaderState ¶
type ReaderState uint32
ReaderState is the state bitmask used by SCardGetStatusChange.
const ( ReaderStateUnaware ReaderState = 0x0000 ReaderStateIgnore ReaderState = 0x0001 ReaderStateChanged ReaderState = 0x0002 ReaderStateUnknown ReaderState = 0x0004 ReaderStateEmpty ReaderState = 0x0010 ReaderStatePresent ReaderState = 0x0020 ReaderStateATRMatch ReaderState = 0x0040 ReaderStateExclusive ReaderState = 0x0080 ReaderStateInUse ReaderState = 0x0100 ReaderStateMute ReaderState = 0x0200 ReaderStateUnpowered ReaderState = 0x0400 )
type ShareMode ¶
type ShareMode uint32
ShareMode controls how a card connection is shared with other applications.
const ( )
type Snapshot ¶
type Snapshot struct {
Readers []*ReaderInfo
}
Snapshot is the initial reader state captured by Watch.
type Watcher ¶
type Watcher interface {
Snapshot() Snapshot
Listen() <-chan DeviceEvent
Close() error
}
Watcher publishes reader and card changes which happen after Snapshot.