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>
impl<'device> GatekeeperReader<'device>
Sourcepub fn new(connection_string: String, realm: Realm<'device>) -> Option<Self>
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}
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}