Path: blob/main/devices/src/usb/backend/fido_backend/fido_provider.rs
5394 views
// Copyright 2024 The ChromiumOS Authors1// Use of this source code is governed by a BSD-style license that can be2// found in the LICENSE file.34use std::fs::File;5use std::sync::Arc;67use sync::Mutex;89use crate::usb::backend::device::BackendDeviceType;10use crate::usb::backend::device::DeviceState;11use crate::usb::backend::error::Error;12use crate::usb::backend::error::Result;13use crate::usb::backend::fido_backend::fido_device::FidoDevice;14use crate::usb::backend::fido_backend::fido_passthrough::FidoPassthroughDevice;15use crate::usb::backend::utils::UsbUtilEventHandler;16use crate::utils::EventHandler;17use crate::utils::EventLoop;1819/// Utility function to attach a security key device to the backend provider. It initializes a20/// `FidoPassthroughDevice` and returns it with its `EventHandler` to the backend.21pub fn attach_security_key(22hidraw: File,23event_loop: Arc<EventLoop>,24device_state: DeviceState,25) -> Result<(Arc<Mutex<BackendDeviceType>>, Arc<dyn EventHandler>)> {26let device =27FidoDevice::new(hidraw, event_loop.clone()).map_err(Error::CreateFidoBackendDevice)?;28let passthrough_device =29FidoPassthroughDevice::new(Arc::new(Mutex::new(device)), device_state, event_loop)30.map_err(Error::CreateFidoBackendDevice)?;31let device_impl = BackendDeviceType::FidoDevice(passthrough_device);32let arc_mutex_device = Arc::new(Mutex::new(device_impl));3334let event_handler: Arc<dyn EventHandler> = Arc::new(UsbUtilEventHandler {35device: arc_mutex_device.clone(),36});3738Ok((arc_mutex_device, event_handler))39}404142