pub struct SmartCard;Expand description
Main handle for reading Thai National ID smart cards.
Implementations§
Source§impl SmartCard
impl SmartCard
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new SmartCard instance.
Examples found in repository?
examples/rust_usage.rs (line 31)
13fn main() {
14 let reader_name = env::args().nth(1);
15
16 match SmartCard::list_readers() {
17 Ok(readers) => {
18 println!("Found {} reader(s):", readers.len());
19 for (i, r) in readers.iter().enumerate() {
20 println!(" [{}] {}", i, r);
21 }
22 }
23 Err(e) => eprintln!("Failed to list readers: {}", e),
24 }
25
26 let opts = Options {
27 show_nhso_data: true,
28 ..Options::default()
29 };
30
31 let card = SmartCard::new();
32 println!("\nWaiting for card...");
33 match card.read(reader_name.as_deref(), &opts) {
34 Ok(data) => {
35 print_card_data(&data);
36 }
37 Err(e) => eprintln!("Read error: {}", e),
38 }
39}Sourcepub fn list_readers() -> Result<Vec<String>, CardError>
pub fn list_readers() -> Result<Vec<String>, CardError>
Return all available PC/SC smart card reader names.
Examples found in repository?
examples/rust_usage.rs (line 16)
13fn main() {
14 let reader_name = env::args().nth(1);
15
16 match SmartCard::list_readers() {
17 Ok(readers) => {
18 println!("Found {} reader(s):", readers.len());
19 for (i, r) in readers.iter().enumerate() {
20 println!(" [{}] {}", i, r);
21 }
22 }
23 Err(e) => eprintln!("Failed to list readers: {}", e),
24 }
25
26 let opts = Options {
27 show_nhso_data: true,
28 ..Options::default()
29 };
30
31 let card = SmartCard::new();
32 println!("\nWaiting for card...");
33 match card.read(reader_name.as_deref(), &opts) {
34 Ok(data) => {
35 print_card_data(&data);
36 }
37 Err(e) => eprintln!("Read error: {}", e),
38 }
39}Sourcepub fn read(
&self,
reader_name: Option<&str>,
opts: &Options,
) -> Result<CardData, CardError>
pub fn read( &self, reader_name: Option<&str>, opts: &Options, ) -> Result<CardData, CardError>
Perform a single card read. If reader_name is None, the first
available reader with a card present is used.
Examples found in repository?
examples/rust_usage.rs (line 33)
13fn main() {
14 let reader_name = env::args().nth(1);
15
16 match SmartCard::list_readers() {
17 Ok(readers) => {
18 println!("Found {} reader(s):", readers.len());
19 for (i, r) in readers.iter().enumerate() {
20 println!(" [{}] {}", i, r);
21 }
22 }
23 Err(e) => eprintln!("Failed to list readers: {}", e),
24 }
25
26 let opts = Options {
27 show_nhso_data: true,
28 ..Options::default()
29 };
30
31 let card = SmartCard::new();
32 println!("\nWaiting for card...");
33 match card.read(reader_name.as_deref(), &opts) {
34 Ok(data) => {
35 print_card_data(&data);
36 }
37 Err(e) => eprintln!("Read error: {}", e),
38 }
39}Sourcepub fn start_daemon(opts: Options) -> Receiver<Event>
pub fn start_daemon(opts: Options) -> Receiver<Event>
Monitor readers continuously and emit events on the returned channel. The daemon runs until the receiver is dropped.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SmartCard
impl RefUnwindSafe for SmartCard
impl Send for SmartCard
impl Sync for SmartCard
impl Unpin for SmartCard
impl UnsafeUnpin for SmartCard
impl UnwindSafe for SmartCard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more