card

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package card provides functions for communication with smart cards. It includes implementations for handling different types of smart cards and reading associated documents.

Index

Constants

This section is empty.

Variables

View Source
var APOLLO_ATR = []byte{
	0x3B, 0xB9, 0x18, 0x00, 0x81, 0x31, 0xFE, 0x9E, 0x80,
	0x73, 0xFF, 0x61, 0x40, 0x83, 0x00, 0x00, 0x00, 0xDF,
}
View Source
var DOCUMENT_FILE_LOC = []byte{0x0F, 0x02}

Location of the file with document data.

View Source
var ErrInvalidFormat = errors.New("invalid format")
View Source
var ErrInvalidLength = errors.New("invalid length")
View Source
var GEMALTO_ATR_1 = []byte{
	0x3B, 0xFF, 0x94, 0x00, 0x00, 0x81, 0x31, 0x80,
	0x43, 0x80, 0x31, 0x80, 0x65, 0xB0, 0x85, 0x02,
	0x01, 0xF3, 0x12, 0x0F, 0xFF, 0x82, 0x90, 0x00,
	0x79,
}
View Source
var GEMALTO_ATR_2 = []byte{
	0x3B, 0xF9, 0x96, 0x00, 0x00, 0x80, 0x31, 0xFE,
	0x45, 0x53, 0x43, 0x45, 0x37, 0x20, 0x47, 0x43,
	0x4E, 0x33, 0x5E,
}

Available since January 2023 (maybe). Replaced very soon with an even newer version.

View Source
var GEMALTO_ATR_3 = []byte{
	0x3B, 0x9E, 0x96, 0x80, 0x31, 0xFE, 0x45, 0x53,
	0x43, 0x45, 0x20, 0x38, 0x2E, 0x30, 0x2D, 0x43,
	0x31, 0x56, 0x30, 0x0D, 0x0A, 0x6F,
}

Available since July 2023.

View Source
var GEMALTO_ATR_4 = []byte{
	0x3B, 0x9E, 0x96, 0x80, 0x31, 0xFE, 0x45, 0x53,
	0x43, 0x45, 0x20, 0x38, 0x2E, 0x30, 0x2D, 0x43,
	0x32, 0x56, 0x30, 0x0D, 0x0A, 0x6C,
}

Available since June 2024.

View Source
var MEDICAL_ATR = []byte{
	0x3B, 0xF4, 0x13, 0x00, 0x00, 0x81, 0x31, 0xFE,
	0x45, 0x52, 0x46, 0x5A, 0x4F, 0xED,
}

Possibly the first version of the medical card. Newer version has the GEMALTO_ATR_2 for the ATR.

View Source
var MEDICAL_ATR_2 = []byte{
	0x3B, 0x9E, 0x97, 0x80, 0x31, 0xFE, 0x45, 0x53,
	0x43, 0x45, 0x20, 0x38, 0x2E, 0x30, 0x2D, 0x43,
	0x31, 0x56, 0x30, 0x0D, 0x0A, 0x6E,
}

Available since March 2023?

View Source
var PERSONAL_FILE_LOC = []byte{0x0F, 0x03}

Location of the file with personal data.

View Source
var PHOTO_FILE_LOC = []byte{0x0F, 0x06}

Location of the the portrait. Portrait is encoded as JPEG.

View Source
var RESIDENCE_FILE_LOC = []byte{0x0F, 0x04}

Location of the file with residence data.

View Source
var VEHICLE_ATR_0 = []byte{
	0x3B, 0xDB, 0x96, 0x00, 0x80, 0xB1, 0xFE, 0x45,
	0x1F, 0x83, 0x00, 0x31, 0xC0, 0x64, 0x1A, 0x18,
	0x01, 0x00, 0x0F, 0x90, 0x00, 0x52,
}

Possibly deprecated.

View Source
var VEHICLE_ATR_1 = []byte{
	0x3B, 0xFF, 0x94, 0x00, 0x00, 0x81, 0x31, 0x80,
	0x43, 0x80, 0x31, 0x80, 0x65, 0xB0, 0x85, 0x02,
	0x01, 0xF3, 0x12, 0x0F, 0xFF, 0x82, 0x90, 0x00,
	0x79,
}
View Source
var VEHICLE_ATR_2 = []byte{
	0x3B, 0x9D, 0x13, 0x81, 0x31, 0x60, 0x37, 0x80,
	0x31, 0xC0, 0x69, 0x4D, 0x54, 0x43, 0x4F, 0x53,
	0x73, 0x02, 0x02, 0x04, 0x40,
}
View Source
var VEHICLE_ATR_3 = []byte{
	0x3B, 0x9D, 0x13, 0x81, 0x31, 0x60, 0x37, 0x80,
	0x31, 0xC0, 0x69, 0x4D, 0x54, 0x43, 0x4F, 0x53,
	0x73, 0x02, 0x05, 0x04, 0x47,
}
View Source
var VEHICLE_ATR_4 = []byte{
	0x3B, 0x9D, 0x18, 0x81, 0x31, 0xFC, 0x35, 0x80,
	0x31, 0xC0, 0x69, 0x4D, 0x54, 0x43, 0x4F, 0x53,
	0x73, 0x02, 0x05, 0x02, 0xD4,
}

Functions

func ReadCard

func ReadCard(sc Card) (doc.Document, error)

Reads a smart card and returns the associated document. It determines the type of the card based on its ATR value and initializes the appropriate card implementation for further reading.

func Transmit added in v1.5.2

func Transmit(cmd []byte) ([]byte, error)

Types

type Apollo

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

Apollo is the type of the first smart ID cards. Apollo cards are not manufactured anymore, and this code could be removed in the future.

type BER added in v1.4.0

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

Represents a node (or a tree) of a BER structure. Each leaf node contains data, and it is considered 'primitive'. Non-leaf nodes don't contain any data, but they contain references to child nodes.

func ParseBER added in v1.5.0

func ParseBER(data []byte) (*BER, error)

Parses BER data (described in ISO/IEC 7816-4 (2005)).

func (BER) String added in v1.5.0

func (tree BER) String() string

Flattens a BER tree into single string. Each line represents single node of a tree.

type Card

type Card interface {
	Status() (*scard.CardStatus, error)
	Transmit(cmd []byte) ([]byte, error)
}

Represents a physical or virtual smart card. Essentially it is just a wrapper for the scard.Card type, but it also allows virtual cards which can be useful for testing.

type CardDocument added in v1.5.2

type CardDocument interface {
	// contains filtered or unexported methods
}

Represents a smart card with a document. All types of documents that Bas Celik can read should satisfy this interface

type Gemalto

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

Gemalto represents ID cards based with Gemalto Java OS. Gemalto replaced Apollo cards around 2014.

type IdDocument added in v1.5.2

type IdDocument interface {
	Apollo | Gemalto
	CardDocument
}

Represents a smart card that contains a Serbian ID document.

type MedicalCard added in v1.2.0

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

Represents a smart card that holds a Serbian medical insurance document.

type VehicleCard added in v1.4.0

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

Represents a smart card that contains a Serbian vehicle document.

type VirtualCard added in v1.5.2

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

func MakeVirtualCard added in v1.5.2

func MakeVirtualCard(atr []byte, fs map[uint32][]byte) *VirtualCard

func (*VirtualCard) Status added in v1.5.2

func (card *VirtualCard) Status() (*scard.CardStatus, error)

Jump to

Keyboard shortcuts

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