Skip to content

Commit

Permalink
Add support for D-Bus virtual devices
Browse files Browse the repository at this point in the history
  • Loading branch information
ueno committed Jan 6, 2021
1 parent b1c128b commit 4d7e2dc
Show file tree
Hide file tree
Showing 7 changed files with 503 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ maintenance = { status = "actively-developed" }
[features]
binding-recompile = ["bindgen"]
webdriver = ["base64", "bytes", "warp", "tokio", "serde", "serde_json"]
dbus = ["zbus", "zvariant"]

[target.'cfg(target_os = "linux")'.dependencies]
libudev = "^0.2"
Expand Down Expand Up @@ -52,6 +53,8 @@ serde = { version = "1.0", optional = true, features = ["derive"] }
serde_json = { version = "1.0", optional = true }
bytes = { version = "0.5", optional = true, features = ["serde"] }
base64 = { version = "^0.10", optional = true }
zbus = { version = "1.7", optional = true }
zvariant = { version = "2.4", optional = true }

[dev-dependencies]
base64 = "^0.10"
Expand Down
9 changes: 9 additions & 0 deletions examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ fn main() {
opts.optflag("x", "no-u2f-usb-hid", "do not enable u2f-usb-hid platforms");
#[cfg(feature = "webdriver")]
opts.optflag("w", "webdriver", "enable WebDriver virtual bus");
#[cfg(feature = "dbus")]
opts.optflag("d", "dbus", "enable access to remote token through D-Bus");

opts.optflag("h", "help", "print this help menu").optopt(
"t",
Expand Down Expand Up @@ -74,6 +76,13 @@ fn main() {
}
}

#[cfg(feature = "dbus")]
{
if matches.opt_present("dbus") {
manager.add_dbus();
}
}

let timeout_ms = match matches.opt_get_default::<u64>("timeout", 15) {
Ok(timeout_s) => {
println!("Using {}s as the timeout", &timeout_s);
Expand Down
8 changes: 8 additions & 0 deletions src/authenticatorservice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ impl AuthenticatorService {
}
}

#[cfg(feature = "dbus")]
pub fn add_dbus(&mut self) {
match crate::virtualdevices::dbus::VirtualManager::new() {
Ok(token) => self.add_transport(Box::new(token)),
Err(e) => error!("Could not add D-Bus transport: {}", e),
}
}

pub fn register(
&mut self,
flags: crate::RegisterFlags,
Expand Down
Loading

0 comments on commit 4d7e2dc

Please sign in to comment.