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