Skip to main content

SmartCard

Struct SmartCard 

Source
pub struct SmartCard;
Expand description

Main handle for reading Thai National ID smart cards.

Implementations§

Source§

impl SmartCard

Source

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}
Source

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}
Source

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}
Source

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§

Source§

impl Default for SmartCard

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.