{"id":28731611,"url":"https://github.com/kofi-q/pcsc-z","last_synced_at":"2025-06-15T18:18:18.958Z","repository":{"id":298805077,"uuid":"1001166095","full_name":"kofi-q/pcsc-z","owner":"kofi-q","description":"Zig PC/SC API bindings for smart card access on Linux / MacOS / Win32","archived":false,"fork":false,"pushed_at":"2025-06-13T01:43:48.000Z","size":147,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-13T02:37:29.166Z","etag":null,"topics":["pcsc","pcsclite","smartcard","winscard","zig","zig-package","ziglang"],"latest_commit_sha":null,"homepage":"https://kofi-q.github.io/pcsc-z/","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kofi-q.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-12T23:49:06.000Z","updated_at":"2025-06-13T01:43:52.000Z","dependencies_parsed_at":"2025-06-13T02:37:55.408Z","dependency_job_id":"6991a601-b2fa-4be7-ba06-8fb4e8072b1a","html_url":"https://github.com/kofi-q/pcsc-z","commit_stats":null,"previous_names":["kofi-q/pcsc-z"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kofi-q/pcsc-z","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kofi-q%2Fpcsc-z","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kofi-q%2Fpcsc-z/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kofi-q%2Fpcsc-z/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kofi-q%2Fpcsc-z/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kofi-q","download_url":"https://codeload.github.com/kofi-q/pcsc-z/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kofi-q%2Fpcsc-z/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260027182,"owners_count":22947794,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pcsc","pcsclite","smartcard","winscard","zig","zig-package","ziglang"],"created_at":"2025-06-15T18:18:18.142Z","updated_at":"2025-06-15T18:18:18.948Z","avatar_url":"https://github.com/kofi-q.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pcsc-z\n\n` › Zig PC/SC API bindings for smart card access on Linux / MacOS / Win32 `\n\n[Docs ↗](https://kofi-q.github.io/pcsc-z) | | [Prerequisites](#prerequisites) | | [Installation](#installation) | | [Usage](#usage)\n\n## Prerequisites\n\n### Linux - Alpine\n\nRequired packages:\n\n- `ccid`\n- `pcsc-lite`\n- `pcsc-lite-libs`\n\n```sh\ndoas apk add ccid pcsc-lite pcsc-lite-libs\n```\nTo run the server daemon:\n```sh\ndoas rc-service pcscd start\n```\n\n### Linux - Debian/Ubuntu/etc\n\nRequired packages:\n\n- `libpcsclite1`\n- `pcscd`\n\n```sh\nsudo apt install libpcsclite1 pcscd\n```\nTo run the server daemon:\n```sh\nsudo systemctl start pcscd\n```\n\n### MacOS/Windows\n\n**`N/A` ::** MacOS and Windows come pre-installed with smart card support. No additional installation needed.\n\n\u003cbr /\u003e\n\n## Installation\n\n```sh\nzig fetch --save=pcsc \"git+https://github.com/kofi-q/pcsc-z.git\"\n```\n\n## Usage\n\n```zig\nconst std = @import(\"std\");\nconst pcsc = @import(\"pcsc\");\n\npub fn main() !void {\n    const client = try pcsc.Client.init(.SYSTEM);\n    defer client.deinit() catch |err| std.debug.print(\n        \"Unable to release client: {}\",\n        .{err},\n    );\n\n    // Detect connected card readers:\n    var readers = [_]pcsc.Reader{.empty};\n    while (true) {\n        var reader_names = try client.readerNames();\n        if (reader_names.next()) |name| {\n            std.debug.print(\"Reader detected: {s}\\n\", .{name});\n            readers[0].name_ptr = name.ptr;\n            break;\n        }\n\n        std.debug.print(\"Connect a reader to continue...\\n\", .{});\n\n        try client.waitForUpdates(\u0026[_]pcsc.Reader{.pnp_query}, .infinite);\n    }\n\n    // Detect inserted cards:\n    while (true) {\n        try client.waitForUpdates(\u0026readers, .infinite);\n\n        readers[0].status = readers[0].status_new;\n\n        if (readers[0].status.flags.IN_USE) {\n            std.debug.print(\"Card in use. Waiting...\\n\", .{});\n            continue;\n        }\n\n        if (readers[0].status.flags.MUTE) {\n            std.debug.print(\"Card not readable. Check orientation...\\n\", .{});\n            continue;\n        }\n\n        if (readers[0].status.flags.PRESENT) break;\n\n        std.debug.print(\"Insert a card to continue...\\n\", .{});\n    }\n\n    std.debug.print(\"Connecting to card...\\n\", .{});\n\n    // Connect to an inserted card:\n    const card = try client.connect(readers[0].name_ptr, .SHARED, .ANY);\n    defer card.disconnect(.RESET) catch |err| std.debug.print(\n        \"Unable to disconnect card: {}\\n\",\n        .{err},\n    );\n\n    std.debug.print(\"Card connected with protocol {}\\n\", .{card.protocol});\n\n    const command = [_]u8{ 0xca, 0xfe, 0xf0, 0x0d };\n\n    std.debug.print(\"Transmitting APDU: {x:0\u003e2}\\n\", .{command});\n\n    // Transmit/receive data to/from a card:\n    var buf_response: [pcsc.max_buffer_len]u8 = undefined;\n    const response = try card.transmit(\u0026command, \u0026buf_response);\n\n    std.debug.print(\"Received response: {x:0\u003e2}\\n\", .{response});\n}\n```\n```console\n$ zig build example:transmit\nConnect a reader to continue...\nReader detected: Gemalto USB SmartCard Reader\nInsert a card to continue...\nConnecting to card...\nCard connected with protocol T=1\nTransmitting APDU: { ca, fe, f0, 0d }\nReceived response: { 68, 81 }\n```\n\n\u003e [!TIP]\n\u003e\n\u003e See the [E2E test application](./e2e/main.zig) for more involved usage.\n\n## Developing\n\n### Prerequisites\n\n#### Zig\n\nv0.14.1 required - see [`.zigversion`](.zigversion) for latest compatible version.\n\n#### Linux\n\nSee [Linux](#linux) section above for a list of runtime prerequisites.\n\nOther relevant development libraries (e.g. `libpcsclite-dev` on Debian-based distros) are included in this repo to ease cross-compilation. No additional installation needed.\n\n#### MacOS\n\n**`N/A` ::** Required MacOS Framework `.tbd`s are included here. No additional installation needed.\n\n**NOTE:** To update the `.tbd`s, however, an XCode installation is needed.\n\n#### Windows\n\n**`N/A` ::** Required DLLs are shipped with the Zig compiler. No additional installation needed.\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkofi-q%2Fpcsc-z","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkofi-q%2Fpcsc-z","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkofi-q%2Fpcsc-z/lists"}