• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Convenience API for Trusty apps to access PinWeaver.
2 
3 use binder::Strong;
4 use rpcbinder::RpcSession;
5 use std::ffi::CStr;
6 
7 pub use android_desktop_security_pinweaver::aidl::android::desktop::security::pinweaver::{
8     self as aidl,
9     DelayScheduleEntry::DelayScheduleEntry,
10     IPinWeaver::{IPinWeaver, IPinWeaverAsync},
11     InsertMode::InsertMode,
12     LeafId::LeafId,
13     LeafSet::LeafSet,
14     TryAuthResponse::TryAuthResponse,
15 };
16 
17 /// Constructs the appropriate delay schedule entry table to request no rate limiting.
18 ///
19 /// An empty delay schedule table is rejected, so use this to opt-out of rate limiting.
ignore_rate_limiting_table() -> &'static [DelayScheduleEntry]20 pub fn ignore_rate_limiting_table() -> &'static [DelayScheduleEntry] {
21     &[DelayScheduleEntry { attemptCount: i32::MAX, delaySecs: 0 }]
22 }
23 
24 pub const PORT: &str = match PORT_CSTR.to_str() {
25     Ok(x) => x,
26     Err(_) => unreachable!(),
27 };
28 const PORT_CSTR: &CStr = c"com.android.desktop.security.PinWeaver.V1";
29 
30 /// Creates a new PinWeaver client.
connect_pinweaver() -> Result<Strong<dyn IPinWeaver>, binder::StatusCode>31 pub fn connect_pinweaver() -> Result<Strong<dyn IPinWeaver>, binder::StatusCode> {
32     RpcSession::new().setup_trusty_client(PORT_CSTR)
33 }
34 
35 /// Creates a new async PinWeaver client.
connect_pinweaver_async<P: binder::BinderAsyncPool + 'static>( ) -> Result<Strong<dyn IPinWeaverAsync<P>>, binder::StatusCode>36 pub fn connect_pinweaver_async<P: binder::BinderAsyncPool + 'static>(
37 ) -> Result<Strong<dyn IPinWeaverAsync<P>>, binder::StatusCode> {
38     RpcSession::new().setup_trusty_client(PORT_CSTR)
39 }
40