fidl_fuchsia_tee_manager/
fidl_fuchsia_tee_manager.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_tee_manager_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct ProviderRequestPersistentStorageRequest {
16    pub dir: fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for ProviderRequestPersistentStorageRequest
21{
22}
23
24#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
25pub struct ProviderMarker;
26
27impl fidl::endpoints::ProtocolMarker for ProviderMarker {
28    type Proxy = ProviderProxy;
29    type RequestStream = ProviderRequestStream;
30    #[cfg(target_os = "fuchsia")]
31    type SynchronousProxy = ProviderSynchronousProxy;
32
33    const DEBUG_NAME: &'static str = "(anonymous) Provider";
34}
35
36pub trait ProviderProxyInterface: Send + Sync {
37    fn r#request_persistent_storage(
38        &self,
39        dir: fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
40    ) -> Result<(), fidl::Error>;
41}
42#[derive(Debug)]
43#[cfg(target_os = "fuchsia")]
44pub struct ProviderSynchronousProxy {
45    client: fidl::client::sync::Client,
46}
47
48#[cfg(target_os = "fuchsia")]
49impl fidl::endpoints::SynchronousProxy for ProviderSynchronousProxy {
50    type Proxy = ProviderProxy;
51    type Protocol = ProviderMarker;
52
53    fn from_channel(inner: fidl::Channel) -> Self {
54        Self::new(inner)
55    }
56
57    fn into_channel(self) -> fidl::Channel {
58        self.client.into_channel()
59    }
60
61    fn as_channel(&self) -> &fidl::Channel {
62        self.client.as_channel()
63    }
64}
65
66#[cfg(target_os = "fuchsia")]
67impl ProviderSynchronousProxy {
68    pub fn new(channel: fidl::Channel) -> Self {
69        let protocol_name = <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
70        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
71    }
72
73    pub fn into_channel(self) -> fidl::Channel {
74        self.client.into_channel()
75    }
76
77    /// Waits until an event arrives and returns it. It is safe for other
78    /// threads to make concurrent requests while waiting for an event.
79    pub fn wait_for_event(
80        &self,
81        deadline: zx::MonotonicInstant,
82    ) -> Result<ProviderEvent, fidl::Error> {
83        ProviderEvent::decode(self.client.wait_for_event(deadline)?)
84    }
85
86    pub fn r#request_persistent_storage(
87        &self,
88        mut dir: fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
89    ) -> Result<(), fidl::Error> {
90        self.client.send::<ProviderRequestPersistentStorageRequest>(
91            (dir,),
92            0x3ef6bac9b6490a0d,
93            fidl::encoding::DynamicFlags::empty(),
94        )
95    }
96}
97
98#[cfg(target_os = "fuchsia")]
99impl From<ProviderSynchronousProxy> for zx::Handle {
100    fn from(value: ProviderSynchronousProxy) -> Self {
101        value.into_channel().into()
102    }
103}
104
105#[cfg(target_os = "fuchsia")]
106impl From<fidl::Channel> for ProviderSynchronousProxy {
107    fn from(value: fidl::Channel) -> Self {
108        Self::new(value)
109    }
110}
111
112#[derive(Debug, Clone)]
113pub struct ProviderProxy {
114    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
115}
116
117impl fidl::endpoints::Proxy for ProviderProxy {
118    type Protocol = ProviderMarker;
119
120    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
121        Self::new(inner)
122    }
123
124    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
125        self.client.into_channel().map_err(|client| Self { client })
126    }
127
128    fn as_channel(&self) -> &::fidl::AsyncChannel {
129        self.client.as_channel()
130    }
131}
132
133impl ProviderProxy {
134    /// Create a new Proxy for fuchsia.tee.manager/Provider.
135    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
136        let protocol_name = <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
137        Self { client: fidl::client::Client::new(channel, protocol_name) }
138    }
139
140    /// Get a Stream of events from the remote end of the protocol.
141    ///
142    /// # Panics
143    ///
144    /// Panics if the event stream was already taken.
145    pub fn take_event_stream(&self) -> ProviderEventStream {
146        ProviderEventStream { event_receiver: self.client.take_event_receiver() }
147    }
148
149    pub fn r#request_persistent_storage(
150        &self,
151        mut dir: fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
152    ) -> Result<(), fidl::Error> {
153        ProviderProxyInterface::r#request_persistent_storage(self, dir)
154    }
155}
156
157impl ProviderProxyInterface for ProviderProxy {
158    fn r#request_persistent_storage(
159        &self,
160        mut dir: fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
161    ) -> Result<(), fidl::Error> {
162        self.client.send::<ProviderRequestPersistentStorageRequest>(
163            (dir,),
164            0x3ef6bac9b6490a0d,
165            fidl::encoding::DynamicFlags::empty(),
166        )
167    }
168}
169
170pub struct ProviderEventStream {
171    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
172}
173
174impl std::marker::Unpin for ProviderEventStream {}
175
176impl futures::stream::FusedStream for ProviderEventStream {
177    fn is_terminated(&self) -> bool {
178        self.event_receiver.is_terminated()
179    }
180}
181
182impl futures::Stream for ProviderEventStream {
183    type Item = Result<ProviderEvent, fidl::Error>;
184
185    fn poll_next(
186        mut self: std::pin::Pin<&mut Self>,
187        cx: &mut std::task::Context<'_>,
188    ) -> std::task::Poll<Option<Self::Item>> {
189        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
190            &mut self.event_receiver,
191            cx
192        )?) {
193            Some(buf) => std::task::Poll::Ready(Some(ProviderEvent::decode(buf))),
194            None => std::task::Poll::Ready(None),
195        }
196    }
197}
198
199#[derive(Debug)]
200pub enum ProviderEvent {}
201
202impl ProviderEvent {
203    /// Decodes a message buffer as a [`ProviderEvent`].
204    fn decode(
205        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
206    ) -> Result<ProviderEvent, fidl::Error> {
207        let (bytes, _handles) = buf.split_mut();
208        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
209        debug_assert_eq!(tx_header.tx_id, 0);
210        match tx_header.ordinal {
211            _ => Err(fidl::Error::UnknownOrdinal {
212                ordinal: tx_header.ordinal,
213                protocol_name: <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
214            }),
215        }
216    }
217}
218
219/// A Stream of incoming requests for fuchsia.tee.manager/Provider.
220pub struct ProviderRequestStream {
221    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
222    is_terminated: bool,
223}
224
225impl std::marker::Unpin for ProviderRequestStream {}
226
227impl futures::stream::FusedStream for ProviderRequestStream {
228    fn is_terminated(&self) -> bool {
229        self.is_terminated
230    }
231}
232
233impl fidl::endpoints::RequestStream for ProviderRequestStream {
234    type Protocol = ProviderMarker;
235    type ControlHandle = ProviderControlHandle;
236
237    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
238        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
239    }
240
241    fn control_handle(&self) -> Self::ControlHandle {
242        ProviderControlHandle { inner: self.inner.clone() }
243    }
244
245    fn into_inner(
246        self,
247    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
248    {
249        (self.inner, self.is_terminated)
250    }
251
252    fn from_inner(
253        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
254        is_terminated: bool,
255    ) -> Self {
256        Self { inner, is_terminated }
257    }
258}
259
260impl futures::Stream for ProviderRequestStream {
261    type Item = Result<ProviderRequest, fidl::Error>;
262
263    fn poll_next(
264        mut self: std::pin::Pin<&mut Self>,
265        cx: &mut std::task::Context<'_>,
266    ) -> std::task::Poll<Option<Self::Item>> {
267        let this = &mut *self;
268        if this.inner.check_shutdown(cx) {
269            this.is_terminated = true;
270            return std::task::Poll::Ready(None);
271        }
272        if this.is_terminated {
273            panic!("polled ProviderRequestStream after completion");
274        }
275        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
276            |bytes, handles| {
277                match this.inner.channel().read_etc(cx, bytes, handles) {
278                    std::task::Poll::Ready(Ok(())) => {}
279                    std::task::Poll::Pending => return std::task::Poll::Pending,
280                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
281                        this.is_terminated = true;
282                        return std::task::Poll::Ready(None);
283                    }
284                    std::task::Poll::Ready(Err(e)) => {
285                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
286                            e.into(),
287                        ))))
288                    }
289                }
290
291                // A message has been received from the channel
292                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
293
294                std::task::Poll::Ready(Some(match header.ordinal {
295                    0x3ef6bac9b6490a0d => {
296                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
297                        let mut req = fidl::new_empty!(
298                            ProviderRequestPersistentStorageRequest,
299                            fidl::encoding::DefaultFuchsiaResourceDialect
300                        );
301                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ProviderRequestPersistentStorageRequest>(&header, _body_bytes, handles, &mut req)?;
302                        let control_handle = ProviderControlHandle { inner: this.inner.clone() };
303                        Ok(ProviderRequest::RequestPersistentStorage {
304                            dir: req.dir,
305
306                            control_handle,
307                        })
308                    }
309                    _ => Err(fidl::Error::UnknownOrdinal {
310                        ordinal: header.ordinal,
311                        protocol_name:
312                            <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
313                    }),
314                }))
315            },
316        )
317    }
318}
319
320/// Provider provides service access and support to the TEE driver
321/// for things like persistent storage, since the TEE may make upward RPC-like
322/// requests to the REE.
323#[derive(Debug)]
324pub enum ProviderRequest {
325    RequestPersistentStorage {
326        dir: fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
327        control_handle: ProviderControlHandle,
328    },
329}
330
331impl ProviderRequest {
332    #[allow(irrefutable_let_patterns)]
333    pub fn into_request_persistent_storage(
334        self,
335    ) -> Option<(fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>, ProviderControlHandle)>
336    {
337        if let ProviderRequest::RequestPersistentStorage { dir, control_handle } = self {
338            Some((dir, control_handle))
339        } else {
340            None
341        }
342    }
343
344    /// Name of the method defined in FIDL
345    pub fn method_name(&self) -> &'static str {
346        match *self {
347            ProviderRequest::RequestPersistentStorage { .. } => "request_persistent_storage",
348        }
349    }
350}
351
352#[derive(Debug, Clone)]
353pub struct ProviderControlHandle {
354    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
355}
356
357impl fidl::endpoints::ControlHandle for ProviderControlHandle {
358    fn shutdown(&self) {
359        self.inner.shutdown()
360    }
361    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
362        self.inner.shutdown_with_epitaph(status)
363    }
364
365    fn is_closed(&self) -> bool {
366        self.inner.channel().is_closed()
367    }
368    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
369        self.inner.channel().on_closed()
370    }
371
372    #[cfg(target_os = "fuchsia")]
373    fn signal_peer(
374        &self,
375        clear_mask: zx::Signals,
376        set_mask: zx::Signals,
377    ) -> Result<(), zx_status::Status> {
378        use fidl::Peered;
379        self.inner.channel().signal_peer(clear_mask, set_mask)
380    }
381}
382
383impl ProviderControlHandle {}
384
385mod internal {
386    use super::*;
387
388    impl fidl::encoding::ResourceTypeMarker for ProviderRequestPersistentStorageRequest {
389        type Borrowed<'a> = &'a mut Self;
390        fn take_or_borrow<'a>(
391            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
392        ) -> Self::Borrowed<'a> {
393            value
394        }
395    }
396
397    unsafe impl fidl::encoding::TypeMarker for ProviderRequestPersistentStorageRequest {
398        type Owned = Self;
399
400        #[inline(always)]
401        fn inline_align(_context: fidl::encoding::Context) -> usize {
402            4
403        }
404
405        #[inline(always)]
406        fn inline_size(_context: fidl::encoding::Context) -> usize {
407            4
408        }
409    }
410
411    unsafe impl
412        fidl::encoding::Encode<
413            ProviderRequestPersistentStorageRequest,
414            fidl::encoding::DefaultFuchsiaResourceDialect,
415        > for &mut ProviderRequestPersistentStorageRequest
416    {
417        #[inline]
418        unsafe fn encode(
419            self,
420            encoder: &mut fidl::encoding::Encoder<
421                '_,
422                fidl::encoding::DefaultFuchsiaResourceDialect,
423            >,
424            offset: usize,
425            _depth: fidl::encoding::Depth,
426        ) -> fidl::Result<()> {
427            encoder.debug_check_bounds::<ProviderRequestPersistentStorageRequest>(offset);
428            // Delegate to tuple encoding.
429            fidl::encoding::Encode::<
430                ProviderRequestPersistentStorageRequest,
431                fidl::encoding::DefaultFuchsiaResourceDialect,
432            >::encode(
433                (<fidl::encoding::Endpoint<
434                    fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
435                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
436                    &mut self.dir
437                ),),
438                encoder,
439                offset,
440                _depth,
441            )
442        }
443    }
444    unsafe impl<
445            T0: fidl::encoding::Encode<
446                fidl::encoding::Endpoint<
447                    fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
448                >,
449                fidl::encoding::DefaultFuchsiaResourceDialect,
450            >,
451        >
452        fidl::encoding::Encode<
453            ProviderRequestPersistentStorageRequest,
454            fidl::encoding::DefaultFuchsiaResourceDialect,
455        > for (T0,)
456    {
457        #[inline]
458        unsafe fn encode(
459            self,
460            encoder: &mut fidl::encoding::Encoder<
461                '_,
462                fidl::encoding::DefaultFuchsiaResourceDialect,
463            >,
464            offset: usize,
465            depth: fidl::encoding::Depth,
466        ) -> fidl::Result<()> {
467            encoder.debug_check_bounds::<ProviderRequestPersistentStorageRequest>(offset);
468            // Zero out padding regions. There's no need to apply masks
469            // because the unmasked parts will be overwritten by fields.
470            // Write the fields.
471            self.0.encode(encoder, offset + 0, depth)?;
472            Ok(())
473        }
474    }
475
476    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
477        for ProviderRequestPersistentStorageRequest
478    {
479        #[inline(always)]
480        fn new_empty() -> Self {
481            Self {
482                dir: fidl::new_empty!(
483                    fidl::encoding::Endpoint<
484                        fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
485                    >,
486                    fidl::encoding::DefaultFuchsiaResourceDialect
487                ),
488            }
489        }
490
491        #[inline]
492        unsafe fn decode(
493            &mut self,
494            decoder: &mut fidl::encoding::Decoder<
495                '_,
496                fidl::encoding::DefaultFuchsiaResourceDialect,
497            >,
498            offset: usize,
499            _depth: fidl::encoding::Depth,
500        ) -> fidl::Result<()> {
501            decoder.debug_check_bounds::<Self>(offset);
502            // Verify that padding bytes are zero.
503            fidl::decode!(
504                fidl::encoding::Endpoint<
505                    fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
506                >,
507                fidl::encoding::DefaultFuchsiaResourceDialect,
508                &mut self.dir,
509                decoder,
510                offset + 0,
511                _depth
512            )?;
513            Ok(())
514        }
515    }
516}