No description
Find a file
2025-08-27 19:29:15 +02:00
examples Improvements 2025-08-26 09:09:36 +02:00
src Improvements 2025-08-26 09:51:11 +02:00
tests Split into modules 2025-08-26 07:08:42 +02:00
.gitignore Initial commit 2025-08-24 17:52:04 +00:00
CHANGELOG.md Add changelog. 2025-08-27 19:29:15 +02:00
LICENSE Initial commit 2025-08-24 17:52:04 +00:00
pcsc.nimble Add changelog. 2025-08-27 19:29:15 +02:00
README.md Add github link and update readme 2025-08-26 09:18:00 +02:00

pcsc-nim

🔒 PC/SC bindings + idiomatic Nim wrapper

pcsc-nim is a cross-platform PC/SC library for smart card access from Nim.
It provides both low-level FFI bindings to PCSC/winscard as well as a high-level API for everyday use.

  • Linux (libpcsclite.so)
  • Windows (winscard.dll)
  • macOS (PCSC.framework)

Features

  • Establish and release PC/SC contexts
  • Enumerate available smart card readers
  • Connect to a card with T=0 or T=1 protocol
  • Send/receive raw APDUs
  • Helper utilities for hex parsing & pretty printing
  • Safe error handling with Nim exceptions

📦 Installation

nimble install https://github.com/mmlado/pcsc-nim

Or for development:

git clone https://github.com/mmlado/pcsc-nim
cd pcsc-nim
nimble develop

🚀 Usage

List readers & select a card

import pcsc

let ctx = establishContext()
let readers = ctx.listReaders()

if readers.len == 0:
  quit "No readers found"

echo "Readers:"
for r in readers:
  echo "  ", r

let card = ctx.connect(readers[0])

Transmit an APDU

# SELECT example AID
let resp = card.transmitHex("00 A4 04 00 08 A0 00 00 08 04 00 01 01")

echo "Response:"
echo "  ", prettyHex(resp)

let (sw1, sw2) = sw(resp)
echo "SW1SW2: 0x", (sw1.int shl 8 or sw2.int).toHex(4)

Example output:

Readers:
  Generic USB2.0-CRW [Smart Card Reader Interface]
Response:
  A4 61 8F 10 ... 90 00
SW1SW2: 0x9000

🛠 Development

Run the test suite:

nimble test

Run examples:

nimble transmit_apdu

📜 License

MIT © mmlado