Struct GatekeeperReader

Source
pub struct GatekeeperReader<'device> { /* private fields */ }
Expand description

High-level interface over an NFC reader. Allows reading association IDs from the realm for which it was created.

Implementations§

Source§

impl<'device> GatekeeperReader<'device>

Source

pub fn new(connection_string: String, realm: Realm<'device>) -> Option<Self>

Opens a connection with the NFC reader located at connection_string. Readers are tied to a particular Realm, and can only read association IDs from that particular realm.

Examples found in repository?
examples/member_project.rs (line 22)
3fn main() {
4  let auth_key = std::env::var("GK_REALM_MEMBER_PROJECTS_AUTH_KEY").unwrap();
5  let read_key = std::env::var("GK_REALM_MEMBER_PROJECTS_READ_KEY").unwrap();
6  let signing_public_key =
7    std::env::var("GK_REALM_MEMBER_PROJECTS_PUBLIC_KEY").unwrap();
8  let mobile_decryption_private_key =
9    std::env::var("GK_REALM_MEMBER_PROJECTS_MOBILE_CRYPT_PRIVATE_KEY").unwrap();
10  let mobile_private_key =
11    std::env::var("GK_REALM_MEMBER_PROJECTS_MOBILE_PRIVATE_KEY").unwrap();
12  let realm = Realm::new(
13    RealmType::MemberProjects,
14    auth_key.into_bytes(),
15    read_key.into_bytes(),
16    signing_public_key.as_bytes(),
17    mobile_decryption_private_key.as_bytes(),
18    mobile_private_key.as_bytes(),
19    None,
20  );
21  let mut gatekeeper_reader =
22    GatekeeperReader::new("pn532_uart:/dev/ttyUSB0".to_string(), realm)
23      .expect("Failed to open gatekeeper");
24  for tag in gatekeeper_reader.get_nearby_tags() {
25    println!("Found a tag nearby: {tag}");
26    if let Ok(association_id) = tag.authenticate() {
27      println!("Association ID for tag: {association_id}");
28    }
29  }
30}
Source

pub fn get_nearby_tags(&mut self) -> Vec<UndifferentiatedTag<'_>>

Searches for nearby NFC tags.

Note: This doesn’t actually authenticate the NFC tags, just searches for them. You must call NfcTag::authenticate before you can know who it belongs to (or if it’s even a valid tag!)

Examples found in repository?
examples/member_project.rs (line 24)
3fn main() {
4  let auth_key = std::env::var("GK_REALM_MEMBER_PROJECTS_AUTH_KEY").unwrap();
5  let read_key = std::env::var("GK_REALM_MEMBER_PROJECTS_READ_KEY").unwrap();
6  let signing_public_key =
7    std::env::var("GK_REALM_MEMBER_PROJECTS_PUBLIC_KEY").unwrap();
8  let mobile_decryption_private_key =
9    std::env::var("GK_REALM_MEMBER_PROJECTS_MOBILE_CRYPT_PRIVATE_KEY").unwrap();
10  let mobile_private_key =
11    std::env::var("GK_REALM_MEMBER_PROJECTS_MOBILE_PRIVATE_KEY").unwrap();
12  let realm = Realm::new(
13    RealmType::MemberProjects,
14    auth_key.into_bytes(),
15    read_key.into_bytes(),
16    signing_public_key.as_bytes(),
17    mobile_decryption_private_key.as_bytes(),
18    mobile_private_key.as_bytes(),
19    None,
20  );
21  let mut gatekeeper_reader =
22    GatekeeperReader::new("pn532_uart:/dev/ttyUSB0".to_string(), realm)
23      .expect("Failed to open gatekeeper");
24  for tag in gatekeeper_reader.get_nearby_tags() {
25    println!("Found a tag nearby: {tag}");
26    if let Ok(association_id) = tag.authenticate() {
27      println!("Association ID for tag: {association_id}");
28    }
29  }
30}

Auto Trait Implementations§

§

impl<'device> Freeze for GatekeeperReader<'device>

§

impl<'device> RefUnwindSafe for GatekeeperReader<'device>

§

impl<'device> !Send for GatekeeperReader<'device>

§

impl<'device> !Sync for GatekeeperReader<'device>

§

impl<'device> Unpin for GatekeeperReader<'device>

§

impl<'device> UnwindSafe for GatekeeperReader<'device>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V