Renamed ./examples/external to ./examples/extensions. No code changes. (0.40.6)
This commit is contained in:
parent
28545fa8d4
commit
c68244d6f6
32 changed files with 40 additions and 41 deletions
44
examples/extensions/pcsc/pcsc_demo.fun
Executable file
44
examples/extensions/pcsc/pcsc_demo.fun
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-10-02
|
||||
*/
|
||||
|
||||
// PCSC demo using stdlib PCSC class.
|
||||
// Establishes context, lists readers, optionally connects to the first,
|
||||
// transmits a sample APDU (SELECT MF), and cleans up.
|
||||
|
||||
#include <io/pcsc.fun>
|
||||
|
||||
pc = PCSC()
|
||||
|
||||
ctx = pc.establish()
|
||||
print("ctx=" + to_string(ctx))
|
||||
|
||||
readers = pc.list_readers(ctx)
|
||||
print("readers=" + to_string(readers))
|
||||
|
||||
number h = 0
|
||||
if len(readers) > 0
|
||||
// Connect to first reader
|
||||
h = pc.connect(ctx, readers[1])
|
||||
print("handle=" + to_string(h))
|
||||
|
||||
if h != 0
|
||||
// Sample APDU: SELECT MF (00 A4 00 00 02 3F 00)
|
||||
// Use the safe convenience transmitter which returns a map {data, sw1, sw2, code}
|
||||
resp = pc.transmit("00A40000023F00")
|
||||
print("resp.data.len=" + to_string(len(resp["data"])) + " bytes")
|
||||
print("resp.sw1=" + to_string(resp["sw1"]) + " sw2=" + to_string(resp["sw2"]) + " code=" + to_string(resp["code"]))
|
||||
|
||||
_ = pc.disconnect(h)
|
||||
|
||||
_ = pc.release(ctx)
|
||||
print("done")
|
||||
83
examples/extensions/pcsc/pcsc_example.fun
Executable file
83
examples/extensions/pcsc/pcsc_example.fun
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-10-02
|
||||
*/
|
||||
|
||||
// Minimal PCSC example for Fun language
|
||||
// Establish context and list readers (prints [] if none or unsupported)
|
||||
|
||||
// This example is very smartcard specific, but it works in my test environment.
|
||||
// The card I am using is a german "eTicket" (local transport ticket).
|
||||
|
||||
//include <hex.fun>
|
||||
include <io/pcsc.fun>
|
||||
|
||||
p = PCSC()
|
||||
|
||||
readers = p.get_readers()
|
||||
number rc = len(readers)
|
||||
|
||||
print("Found " + to_string(rc) + " readers:")
|
||||
|
||||
for i in range(0, rc)
|
||||
print(" " + to_string(i+1) + ". " + readers[i])
|
||||
print("Dump:")
|
||||
print(readers)
|
||||
|
||||
// Select Applet
|
||||
string apdu = "00a4040c0cD2760001354B414E4D30310000"
|
||||
print("Transmit APDU (Select Applet): " + apdu)
|
||||
result = p.transmit(apdu)
|
||||
|
||||
print("Response:")
|
||||
print(" Data: " + to_string(len(result["data"])) + " bytes")
|
||||
print(" SW1: " + to_string(result["sw1"]))
|
||||
print(" SW2: " + to_string(result["sw2"]))
|
||||
print(" Code: " + to_string(result["code"]))
|
||||
print("Dump:")
|
||||
print(result)
|
||||
|
||||
// Call the random number generator (RNG)
|
||||
apdu = "0084000008"
|
||||
print("Transmit APDU (Call the random number generator (RNG): " + apdu)
|
||||
result = p.transmit(apdu)
|
||||
|
||||
print("Response:")
|
||||
print(" Data: " + to_string(len(result["data"])) + " bytes")
|
||||
print(" SW1: " + to_string(result["sw1"]))
|
||||
print(" SW2: " + to_string(result["sw2"]))
|
||||
print(" Code: " + to_string(result["code"]))
|
||||
print("Dump:")
|
||||
print(result)
|
||||
|
||||
/* Possible output:
|
||||
Found 2 readers:
|
||||
1. OMNIKEY CardMan (076B:5321) 5321 00 00
|
||||
2. OMNIKEY CardMan (076B:5321) 5321 00 01
|
||||
Dump:
|
||||
[OMNIKEY CardMan (076B:5321) 5321 00 00, OMNIKEY CardMan (076B:5321) 5321 00 01]
|
||||
Transmit APDU (Select Applet): 00a4040c0cD2760001354B414E4D30310000
|
||||
Response:
|
||||
Data: 251 bytes
|
||||
SW1: 144
|
||||
SW2: 0
|
||||
Code: 0
|
||||
Dump:
|
||||
{"data": [224, 129, 248, 226, 24, 192, 1, 1, 129, 15, 0, 0, 5, 250, 136, 243, 17, 36, 236, 105, 135, 46, 236, 105, 135, 128, 2, 7, 131, 228, 7, 192, 1, 2, 130, 2, 0, 162, 231, 3, 192, 1, 3, 236, 29, 192, 1, 4, 134, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 135, 2, 0, 0, 195, 2, 1, 9, 144, 16, 9, 8, 7, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 233, 29, 192, 1, 9, 131, 20, 0, 0, 0, 1, 136, 243, 41, 106, 136, 142, 136, 42, 38, 33, 139, 156, 45, 30, 191, 125, 132, 2, 7, 1, 233, 29, 192, 1, 8, 131, 20, 0, 0, 0, 1, 136, 243, 41, 106, 136, 142, 136, 42, 38, 33, 139, 156, 45, 30, 191, 125, 132, 2, 7, 1, 233, 29, 192, 1, 7, 131, 20, 0, 0, 0, 1, 136, 243, 41, 106, 136, 142, 136, 42, 38, 33, 139, 156, 45, 30, 191, 125, 132, 2, 7, 1, 233, 29, 192, 1, 6, 131, 20, 0, 0, 15, 22, 136, 243, 31, 143, 136, 142, 136, 42, 37, 55, 0, 1, 47, 55, 191, 125, 132, 2, 7, 1, 233, 29, 192, 1, 5, 131, 20, 0, 0, 15, 21, 136, 243, 7, 216, 136, 143, 136, 42, 37, 55, 0, 1, 37, 58, 191, 125, 132, 2, 7, 1], "sw1": 144, "sw2": 0, "code": 0}
|
||||
Transmit APDU (Call the random number generator (RNG): 0084000008
|
||||
Response:
|
||||
Data: 8 bytes
|
||||
SW1: 144
|
||||
SW2: 0
|
||||
Code: 0
|
||||
Dump:
|
||||
{"data": [25, 179, 169, 196, 57, 36, 89, 139], "sw1": 144, "sw2": 0, "code": 0}
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue