Skip to main content

fidl_fuchsia_hardware_block_encrypted/
fidl_fuchsia_hardware_block_encrypted.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_hardware_block_encrypted__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DeviceManagerMarker;
16
17impl fidl::endpoints::ProtocolMarker for DeviceManagerMarker {
18    type Proxy = DeviceManagerProxy;
19    type RequestStream = DeviceManagerRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = DeviceManagerSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "(anonymous) DeviceManager";
24}
25
26pub trait DeviceManagerProxyInterface: Send + Sync {
27    type FormatResponseFut: std::future::Future<Output = Result<i32, fidl::Error>> + Send;
28    fn r#format(&self, key: &[u8], slot: u8) -> Self::FormatResponseFut;
29    type UnsealResponseFut: std::future::Future<Output = Result<i32, fidl::Error>> + Send;
30    fn r#unseal(&self, key: &[u8], slot: u8) -> Self::UnsealResponseFut;
31    type SealResponseFut: std::future::Future<Output = Result<i32, fidl::Error>> + Send;
32    fn r#seal(&self) -> Self::SealResponseFut;
33    type ShredResponseFut: std::future::Future<Output = Result<i32, fidl::Error>> + Send;
34    fn r#shred(&self) -> Self::ShredResponseFut;
35}
36#[derive(Debug)]
37#[cfg(target_os = "fuchsia")]
38pub struct DeviceManagerSynchronousProxy {
39    client: fidl::client::sync::Client,
40}
41
42#[cfg(target_os = "fuchsia")]
43impl fidl::endpoints::SynchronousProxy for DeviceManagerSynchronousProxy {
44    type Proxy = DeviceManagerProxy;
45    type Protocol = DeviceManagerMarker;
46
47    fn from_channel(inner: fidl::Channel) -> Self {
48        Self::new(inner)
49    }
50
51    fn into_channel(self) -> fidl::Channel {
52        self.client.into_channel()
53    }
54
55    fn as_channel(&self) -> &fidl::Channel {
56        self.client.as_channel()
57    }
58}
59
60#[cfg(target_os = "fuchsia")]
61impl DeviceManagerSynchronousProxy {
62    pub fn new(channel: fidl::Channel) -> Self {
63        Self { client: fidl::client::sync::Client::new(channel) }
64    }
65
66    pub fn into_channel(self) -> fidl::Channel {
67        self.client.into_channel()
68    }
69
70    /// Waits until an event arrives and returns it. It is safe for other
71    /// threads to make concurrent requests while waiting for an event.
72    pub fn wait_for_event(
73        &self,
74        deadline: zx::MonotonicInstant,
75    ) -> Result<DeviceManagerEvent, fidl::Error> {
76        DeviceManagerEvent::decode(self.client.wait_for_event::<DeviceManagerMarker>(deadline)?)
77    }
78
79    /// Formats the device, destroying any previously-secured data.  A new data
80    /// key is generated and wrapped with the provided `key` into key slot `slot`,
81    /// Returns `ZX_ERR_BAD_STATE` if the device is not currently sealed.
82    /// Returns `ZX_OK` on success.
83    pub fn r#format(
84        &self,
85        mut key: &[u8],
86        mut slot: u8,
87        ___deadline: zx::MonotonicInstant,
88    ) -> Result<i32, fidl::Error> {
89        let _response = self.client.send_query::<
90            DeviceManagerFormatRequest,
91            DeviceManagerFormatResponse,
92            DeviceManagerMarker,
93        >(
94            (key, slot,),
95            0x5d10415465425f82,
96            fidl::encoding::DynamicFlags::empty(),
97            ___deadline,
98        )?;
99        Ok(_response.status)
100    }
101
102    /// Attempts to unseal the device by using the provided master key to unwrap
103    /// the data key wrapped in the specified key slot.  If the key provided was
104    /// the correct key for this slot, then the device node responding to this
105    /// protocol will create an unsealed zxcrypt device as a child of itself in
106    /// the device tree before returning success.
107    /// Returns `ZX_ERR_INVALID_ARGS` if `slot` is invalid.
108    /// Returns `ZX_ERR_BAD_STATE` and keeps the device open if the device is already unsealed.
109    /// Returns other errors if operations on the underlying block device return errors.
110    /// Returns `ZX_OK` on success.
111    pub fn r#unseal(
112        &self,
113        mut key: &[u8],
114        mut slot: u8,
115        ___deadline: zx::MonotonicInstant,
116    ) -> Result<i32, fidl::Error> {
117        let _response = self.client.send_query::<
118            DeviceManagerUnsealRequest,
119            DeviceManagerUnsealResponse,
120            DeviceManagerMarker,
121        >(
122            (key, slot,),
123            0x170f834d39ed94fb,
124            fidl::encoding::DynamicFlags::empty(),
125            ___deadline,
126        )?;
127        Ok(_response.status)
128    }
129
130    /// Seals the device, causing any previously-created child zxcrypt Device to
131    /// be removed some time later.  (Someday we'd like this to only return once
132    /// the unsealed child device is removed, but that's not straightforward today.)
133    /// Returns `ZX_ERR_BAD_STATE` if the device is already sealed.
134    /// Returns `ZX_OK` on success.
135    pub fn r#seal(&self, ___deadline: zx::MonotonicInstant) -> Result<i32, fidl::Error> {
136        let _response = self.client.send_query::<
137            fidl::encoding::EmptyPayload,
138            DeviceManagerSealResponse,
139            DeviceManagerMarker,
140        >(
141            (),
142            0xe63c7aa7840fbf4,
143            fidl::encoding::DynamicFlags::empty(),
144            ___deadline,
145        )?;
146        Ok(_response.status)
147    }
148
149    /// Shreds the device, permanently overwriting the keys that would allow
150    /// `Unseal()`ing the device again in the future.  This call does *not*
151    /// impact the current sealed/unsealed state of the device -- if currently
152    /// unsealed, the device will remain in that state until `Seal()` is called
153    /// or the device is unbound.
154    /// Returns `ZX_OK` on success.
155    /// Returns other errors if operations on the underlying block device return errors.
156    pub fn r#shred(&self, ___deadline: zx::MonotonicInstant) -> Result<i32, fidl::Error> {
157        let _response = self.client.send_query::<
158            fidl::encoding::EmptyPayload,
159            DeviceManagerShredResponse,
160            DeviceManagerMarker,
161        >(
162            (),
163            0x1fbff042770086c,
164            fidl::encoding::DynamicFlags::empty(),
165            ___deadline,
166        )?;
167        Ok(_response.status)
168    }
169}
170
171#[cfg(target_os = "fuchsia")]
172impl From<DeviceManagerSynchronousProxy> for zx::NullableHandle {
173    fn from(value: DeviceManagerSynchronousProxy) -> Self {
174        value.into_channel().into()
175    }
176}
177
178#[cfg(target_os = "fuchsia")]
179impl From<fidl::Channel> for DeviceManagerSynchronousProxy {
180    fn from(value: fidl::Channel) -> Self {
181        Self::new(value)
182    }
183}
184
185#[cfg(target_os = "fuchsia")]
186impl fidl::endpoints::FromClient for DeviceManagerSynchronousProxy {
187    type Protocol = DeviceManagerMarker;
188
189    fn from_client(value: fidl::endpoints::ClientEnd<DeviceManagerMarker>) -> Self {
190        Self::new(value.into_channel())
191    }
192}
193
194#[derive(Debug, Clone)]
195pub struct DeviceManagerProxy {
196    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
197}
198
199impl fidl::endpoints::Proxy for DeviceManagerProxy {
200    type Protocol = DeviceManagerMarker;
201
202    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
203        Self::new(inner)
204    }
205
206    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
207        self.client.into_channel().map_err(|client| Self { client })
208    }
209
210    fn as_channel(&self) -> &::fidl::AsyncChannel {
211        self.client.as_channel()
212    }
213}
214
215impl DeviceManagerProxy {
216    /// Create a new Proxy for fuchsia.hardware.block.encrypted/DeviceManager.
217    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
218        let protocol_name = <DeviceManagerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
219        Self { client: fidl::client::Client::new(channel, protocol_name) }
220    }
221
222    /// Get a Stream of events from the remote end of the protocol.
223    ///
224    /// # Panics
225    ///
226    /// Panics if the event stream was already taken.
227    pub fn take_event_stream(&self) -> DeviceManagerEventStream {
228        DeviceManagerEventStream { event_receiver: self.client.take_event_receiver() }
229    }
230
231    /// Formats the device, destroying any previously-secured data.  A new data
232    /// key is generated and wrapped with the provided `key` into key slot `slot`,
233    /// Returns `ZX_ERR_BAD_STATE` if the device is not currently sealed.
234    /// Returns `ZX_OK` on success.
235    pub fn r#format(
236        &self,
237        mut key: &[u8],
238        mut slot: u8,
239    ) -> fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect> {
240        DeviceManagerProxyInterface::r#format(self, key, slot)
241    }
242
243    /// Attempts to unseal the device by using the provided master key to unwrap
244    /// the data key wrapped in the specified key slot.  If the key provided was
245    /// the correct key for this slot, then the device node responding to this
246    /// protocol will create an unsealed zxcrypt device as a child of itself in
247    /// the device tree before returning success.
248    /// Returns `ZX_ERR_INVALID_ARGS` if `slot` is invalid.
249    /// Returns `ZX_ERR_BAD_STATE` and keeps the device open if the device is already unsealed.
250    /// Returns other errors if operations on the underlying block device return errors.
251    /// Returns `ZX_OK` on success.
252    pub fn r#unseal(
253        &self,
254        mut key: &[u8],
255        mut slot: u8,
256    ) -> fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect> {
257        DeviceManagerProxyInterface::r#unseal(self, key, slot)
258    }
259
260    /// Seals the device, causing any previously-created child zxcrypt Device to
261    /// be removed some time later.  (Someday we'd like this to only return once
262    /// the unsealed child device is removed, but that's not straightforward today.)
263    /// Returns `ZX_ERR_BAD_STATE` if the device is already sealed.
264    /// Returns `ZX_OK` on success.
265    pub fn r#seal(
266        &self,
267    ) -> fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect> {
268        DeviceManagerProxyInterface::r#seal(self)
269    }
270
271    /// Shreds the device, permanently overwriting the keys that would allow
272    /// `Unseal()`ing the device again in the future.  This call does *not*
273    /// impact the current sealed/unsealed state of the device -- if currently
274    /// unsealed, the device will remain in that state until `Seal()` is called
275    /// or the device is unbound.
276    /// Returns `ZX_OK` on success.
277    /// Returns other errors if operations on the underlying block device return errors.
278    pub fn r#shred(
279        &self,
280    ) -> fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect> {
281        DeviceManagerProxyInterface::r#shred(self)
282    }
283}
284
285impl DeviceManagerProxyInterface for DeviceManagerProxy {
286    type FormatResponseFut =
287        fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect>;
288    fn r#format(&self, mut key: &[u8], mut slot: u8) -> Self::FormatResponseFut {
289        fn _decode(
290            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
291        ) -> Result<i32, fidl::Error> {
292            let _response = fidl::client::decode_transaction_body::<
293                DeviceManagerFormatResponse,
294                fidl::encoding::DefaultFuchsiaResourceDialect,
295                0x5d10415465425f82,
296            >(_buf?)?;
297            Ok(_response.status)
298        }
299        self.client.send_query_and_decode::<DeviceManagerFormatRequest, i32>(
300            (key, slot),
301            0x5d10415465425f82,
302            fidl::encoding::DynamicFlags::empty(),
303            _decode,
304        )
305    }
306
307    type UnsealResponseFut =
308        fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect>;
309    fn r#unseal(&self, mut key: &[u8], mut slot: u8) -> Self::UnsealResponseFut {
310        fn _decode(
311            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
312        ) -> Result<i32, fidl::Error> {
313            let _response = fidl::client::decode_transaction_body::<
314                DeviceManagerUnsealResponse,
315                fidl::encoding::DefaultFuchsiaResourceDialect,
316                0x170f834d39ed94fb,
317            >(_buf?)?;
318            Ok(_response.status)
319        }
320        self.client.send_query_and_decode::<DeviceManagerUnsealRequest, i32>(
321            (key, slot),
322            0x170f834d39ed94fb,
323            fidl::encoding::DynamicFlags::empty(),
324            _decode,
325        )
326    }
327
328    type SealResponseFut =
329        fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect>;
330    fn r#seal(&self) -> Self::SealResponseFut {
331        fn _decode(
332            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
333        ) -> Result<i32, fidl::Error> {
334            let _response = fidl::client::decode_transaction_body::<
335                DeviceManagerSealResponse,
336                fidl::encoding::DefaultFuchsiaResourceDialect,
337                0xe63c7aa7840fbf4,
338            >(_buf?)?;
339            Ok(_response.status)
340        }
341        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, i32>(
342            (),
343            0xe63c7aa7840fbf4,
344            fidl::encoding::DynamicFlags::empty(),
345            _decode,
346        )
347    }
348
349    type ShredResponseFut =
350        fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect>;
351    fn r#shred(&self) -> Self::ShredResponseFut {
352        fn _decode(
353            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
354        ) -> Result<i32, fidl::Error> {
355            let _response = fidl::client::decode_transaction_body::<
356                DeviceManagerShredResponse,
357                fidl::encoding::DefaultFuchsiaResourceDialect,
358                0x1fbff042770086c,
359            >(_buf?)?;
360            Ok(_response.status)
361        }
362        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, i32>(
363            (),
364            0x1fbff042770086c,
365            fidl::encoding::DynamicFlags::empty(),
366            _decode,
367        )
368    }
369}
370
371pub struct DeviceManagerEventStream {
372    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
373}
374
375impl std::marker::Unpin for DeviceManagerEventStream {}
376
377impl futures::stream::FusedStream for DeviceManagerEventStream {
378    fn is_terminated(&self) -> bool {
379        self.event_receiver.is_terminated()
380    }
381}
382
383impl futures::Stream for DeviceManagerEventStream {
384    type Item = Result<DeviceManagerEvent, fidl::Error>;
385
386    fn poll_next(
387        mut self: std::pin::Pin<&mut Self>,
388        cx: &mut std::task::Context<'_>,
389    ) -> std::task::Poll<Option<Self::Item>> {
390        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
391            &mut self.event_receiver,
392            cx
393        )?) {
394            Some(buf) => std::task::Poll::Ready(Some(DeviceManagerEvent::decode(buf))),
395            None => std::task::Poll::Ready(None),
396        }
397    }
398}
399
400#[derive(Debug)]
401pub enum DeviceManagerEvent {}
402
403impl DeviceManagerEvent {
404    /// Decodes a message buffer as a [`DeviceManagerEvent`].
405    fn decode(
406        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
407    ) -> Result<DeviceManagerEvent, fidl::Error> {
408        let (bytes, _handles) = buf.split_mut();
409        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
410        debug_assert_eq!(tx_header.tx_id, 0);
411        match tx_header.ordinal {
412            _ => Err(fidl::Error::UnknownOrdinal {
413                ordinal: tx_header.ordinal,
414                protocol_name: <DeviceManagerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
415            }),
416        }
417    }
418}
419
420/// A Stream of incoming requests for fuchsia.hardware.block.encrypted/DeviceManager.
421pub struct DeviceManagerRequestStream {
422    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
423    is_terminated: bool,
424}
425
426impl std::marker::Unpin for DeviceManagerRequestStream {}
427
428impl futures::stream::FusedStream for DeviceManagerRequestStream {
429    fn is_terminated(&self) -> bool {
430        self.is_terminated
431    }
432}
433
434impl fidl::endpoints::RequestStream for DeviceManagerRequestStream {
435    type Protocol = DeviceManagerMarker;
436    type ControlHandle = DeviceManagerControlHandle;
437
438    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
439        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
440    }
441
442    fn control_handle(&self) -> Self::ControlHandle {
443        DeviceManagerControlHandle { inner: self.inner.clone() }
444    }
445
446    fn into_inner(
447        self,
448    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
449    {
450        (self.inner, self.is_terminated)
451    }
452
453    fn from_inner(
454        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
455        is_terminated: bool,
456    ) -> Self {
457        Self { inner, is_terminated }
458    }
459}
460
461impl futures::Stream for DeviceManagerRequestStream {
462    type Item = Result<DeviceManagerRequest, fidl::Error>;
463
464    fn poll_next(
465        mut self: std::pin::Pin<&mut Self>,
466        cx: &mut std::task::Context<'_>,
467    ) -> std::task::Poll<Option<Self::Item>> {
468        let this = &mut *self;
469        if this.inner.check_shutdown(cx) {
470            this.is_terminated = true;
471            return std::task::Poll::Ready(None);
472        }
473        if this.is_terminated {
474            panic!("polled DeviceManagerRequestStream after completion");
475        }
476        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
477            |bytes, handles| {
478                match this.inner.channel().read_etc(cx, bytes, handles) {
479                    std::task::Poll::Ready(Ok(())) => {}
480                    std::task::Poll::Pending => return std::task::Poll::Pending,
481                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
482                        this.is_terminated = true;
483                        return std::task::Poll::Ready(None);
484                    }
485                    std::task::Poll::Ready(Err(e)) => {
486                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
487                            e.into(),
488                        ))));
489                    }
490                }
491
492                // A message has been received from the channel
493                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
494
495                std::task::Poll::Ready(Some(match header.ordinal {
496                    0x5d10415465425f82 => {
497                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
498                        let mut req = fidl::new_empty!(
499                            DeviceManagerFormatRequest,
500                            fidl::encoding::DefaultFuchsiaResourceDialect
501                        );
502                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceManagerFormatRequest>(&header, _body_bytes, handles, &mut req)?;
503                        let control_handle =
504                            DeviceManagerControlHandle { inner: this.inner.clone() };
505                        Ok(DeviceManagerRequest::Format {
506                            key: req.key,
507                            slot: req.slot,
508
509                            responder: DeviceManagerFormatResponder {
510                                control_handle: std::mem::ManuallyDrop::new(control_handle),
511                                tx_id: header.tx_id,
512                            },
513                        })
514                    }
515                    0x170f834d39ed94fb => {
516                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
517                        let mut req = fidl::new_empty!(
518                            DeviceManagerUnsealRequest,
519                            fidl::encoding::DefaultFuchsiaResourceDialect
520                        );
521                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceManagerUnsealRequest>(&header, _body_bytes, handles, &mut req)?;
522                        let control_handle =
523                            DeviceManagerControlHandle { inner: this.inner.clone() };
524                        Ok(DeviceManagerRequest::Unseal {
525                            key: req.key,
526                            slot: req.slot,
527
528                            responder: DeviceManagerUnsealResponder {
529                                control_handle: std::mem::ManuallyDrop::new(control_handle),
530                                tx_id: header.tx_id,
531                            },
532                        })
533                    }
534                    0xe63c7aa7840fbf4 => {
535                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
536                        let mut req = fidl::new_empty!(
537                            fidl::encoding::EmptyPayload,
538                            fidl::encoding::DefaultFuchsiaResourceDialect
539                        );
540                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
541                        let control_handle =
542                            DeviceManagerControlHandle { inner: this.inner.clone() };
543                        Ok(DeviceManagerRequest::Seal {
544                            responder: DeviceManagerSealResponder {
545                                control_handle: std::mem::ManuallyDrop::new(control_handle),
546                                tx_id: header.tx_id,
547                            },
548                        })
549                    }
550                    0x1fbff042770086c => {
551                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
552                        let mut req = fidl::new_empty!(
553                            fidl::encoding::EmptyPayload,
554                            fidl::encoding::DefaultFuchsiaResourceDialect
555                        );
556                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
557                        let control_handle =
558                            DeviceManagerControlHandle { inner: this.inner.clone() };
559                        Ok(DeviceManagerRequest::Shred {
560                            responder: DeviceManagerShredResponder {
561                                control_handle: std::mem::ManuallyDrop::new(control_handle),
562                                tx_id: header.tx_id,
563                            },
564                        })
565                    }
566                    _ => Err(fidl::Error::UnknownOrdinal {
567                        ordinal: header.ordinal,
568                        protocol_name:
569                            <DeviceManagerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
570                    }),
571                }))
572            },
573        )
574    }
575}
576
577/// An interface to the zxcrypt driver, as bound to a single block device with
578/// a zxcrypt superblock.  zxcrypt devices are encrypted, and before their
579/// plaintext contents can be accessed, they must be unsealed with a key.
580/// This protocol allows the caller to make requests to unseal the device (by
581/// providing the appropriate key) and to seal the device (rendering its
582/// contents inaccessible).
583#[derive(Debug)]
584pub enum DeviceManagerRequest {
585    /// Formats the device, destroying any previously-secured data.  A new data
586    /// key is generated and wrapped with the provided `key` into key slot `slot`,
587    /// Returns `ZX_ERR_BAD_STATE` if the device is not currently sealed.
588    /// Returns `ZX_OK` on success.
589    Format { key: Vec<u8>, slot: u8, responder: DeviceManagerFormatResponder },
590    /// Attempts to unseal the device by using the provided master key to unwrap
591    /// the data key wrapped in the specified key slot.  If the key provided was
592    /// the correct key for this slot, then the device node responding to this
593    /// protocol will create an unsealed zxcrypt device as a child of itself in
594    /// the device tree before returning success.
595    /// Returns `ZX_ERR_INVALID_ARGS` if `slot` is invalid.
596    /// Returns `ZX_ERR_BAD_STATE` and keeps the device open if the device is already unsealed.
597    /// Returns other errors if operations on the underlying block device return errors.
598    /// Returns `ZX_OK` on success.
599    Unseal { key: Vec<u8>, slot: u8, responder: DeviceManagerUnsealResponder },
600    /// Seals the device, causing any previously-created child zxcrypt Device to
601    /// be removed some time later.  (Someday we'd like this to only return once
602    /// the unsealed child device is removed, but that's not straightforward today.)
603    /// Returns `ZX_ERR_BAD_STATE` if the device is already sealed.
604    /// Returns `ZX_OK` on success.
605    Seal { responder: DeviceManagerSealResponder },
606    /// Shreds the device, permanently overwriting the keys that would allow
607    /// `Unseal()`ing the device again in the future.  This call does *not*
608    /// impact the current sealed/unsealed state of the device -- if currently
609    /// unsealed, the device will remain in that state until `Seal()` is called
610    /// or the device is unbound.
611    /// Returns `ZX_OK` on success.
612    /// Returns other errors if operations on the underlying block device return errors.
613    Shred { responder: DeviceManagerShredResponder },
614}
615
616impl DeviceManagerRequest {
617    #[allow(irrefutable_let_patterns)]
618    pub fn into_format(self) -> Option<(Vec<u8>, u8, DeviceManagerFormatResponder)> {
619        if let DeviceManagerRequest::Format { key, slot, responder } = self {
620            Some((key, slot, responder))
621        } else {
622            None
623        }
624    }
625
626    #[allow(irrefutable_let_patterns)]
627    pub fn into_unseal(self) -> Option<(Vec<u8>, u8, DeviceManagerUnsealResponder)> {
628        if let DeviceManagerRequest::Unseal { key, slot, responder } = self {
629            Some((key, slot, responder))
630        } else {
631            None
632        }
633    }
634
635    #[allow(irrefutable_let_patterns)]
636    pub fn into_seal(self) -> Option<(DeviceManagerSealResponder)> {
637        if let DeviceManagerRequest::Seal { responder } = self { Some((responder)) } else { None }
638    }
639
640    #[allow(irrefutable_let_patterns)]
641    pub fn into_shred(self) -> Option<(DeviceManagerShredResponder)> {
642        if let DeviceManagerRequest::Shred { responder } = self { Some((responder)) } else { None }
643    }
644
645    /// Name of the method defined in FIDL
646    pub fn method_name(&self) -> &'static str {
647        match *self {
648            DeviceManagerRequest::Format { .. } => "format",
649            DeviceManagerRequest::Unseal { .. } => "unseal",
650            DeviceManagerRequest::Seal { .. } => "seal",
651            DeviceManagerRequest::Shred { .. } => "shred",
652        }
653    }
654}
655
656#[derive(Debug, Clone)]
657pub struct DeviceManagerControlHandle {
658    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
659}
660
661impl fidl::endpoints::ControlHandle for DeviceManagerControlHandle {
662    fn shutdown(&self) {
663        self.inner.shutdown()
664    }
665
666    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
667        self.inner.shutdown_with_epitaph(status)
668    }
669
670    fn is_closed(&self) -> bool {
671        self.inner.channel().is_closed()
672    }
673    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
674        self.inner.channel().on_closed()
675    }
676
677    #[cfg(target_os = "fuchsia")]
678    fn signal_peer(
679        &self,
680        clear_mask: zx::Signals,
681        set_mask: zx::Signals,
682    ) -> Result<(), zx_status::Status> {
683        use fidl::Peered;
684        self.inner.channel().signal_peer(clear_mask, set_mask)
685    }
686}
687
688impl DeviceManagerControlHandle {}
689
690#[must_use = "FIDL methods require a response to be sent"]
691#[derive(Debug)]
692pub struct DeviceManagerFormatResponder {
693    control_handle: std::mem::ManuallyDrop<DeviceManagerControlHandle>,
694    tx_id: u32,
695}
696
697/// Set the the channel to be shutdown (see [`DeviceManagerControlHandle::shutdown`])
698/// if the responder is dropped without sending a response, so that the client
699/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
700impl std::ops::Drop for DeviceManagerFormatResponder {
701    fn drop(&mut self) {
702        self.control_handle.shutdown();
703        // Safety: drops once, never accessed again
704        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
705    }
706}
707
708impl fidl::endpoints::Responder for DeviceManagerFormatResponder {
709    type ControlHandle = DeviceManagerControlHandle;
710
711    fn control_handle(&self) -> &DeviceManagerControlHandle {
712        &self.control_handle
713    }
714
715    fn drop_without_shutdown(mut self) {
716        // Safety: drops once, never accessed again due to mem::forget
717        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
718        // Prevent Drop from running (which would shut down the channel)
719        std::mem::forget(self);
720    }
721}
722
723impl DeviceManagerFormatResponder {
724    /// Sends a response to the FIDL transaction.
725    ///
726    /// Sets the channel to shutdown if an error occurs.
727    pub fn send(self, mut status: i32) -> Result<(), fidl::Error> {
728        let _result = self.send_raw(status);
729        if _result.is_err() {
730            self.control_handle.shutdown();
731        }
732        self.drop_without_shutdown();
733        _result
734    }
735
736    /// Similar to "send" but does not shutdown the channel if an error occurs.
737    pub fn send_no_shutdown_on_err(self, mut status: i32) -> Result<(), fidl::Error> {
738        let _result = self.send_raw(status);
739        self.drop_without_shutdown();
740        _result
741    }
742
743    fn send_raw(&self, mut status: i32) -> Result<(), fidl::Error> {
744        self.control_handle.inner.send::<DeviceManagerFormatResponse>(
745            (status,),
746            self.tx_id,
747            0x5d10415465425f82,
748            fidl::encoding::DynamicFlags::empty(),
749        )
750    }
751}
752
753#[must_use = "FIDL methods require a response to be sent"]
754#[derive(Debug)]
755pub struct DeviceManagerUnsealResponder {
756    control_handle: std::mem::ManuallyDrop<DeviceManagerControlHandle>,
757    tx_id: u32,
758}
759
760/// Set the the channel to be shutdown (see [`DeviceManagerControlHandle::shutdown`])
761/// if the responder is dropped without sending a response, so that the client
762/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
763impl std::ops::Drop for DeviceManagerUnsealResponder {
764    fn drop(&mut self) {
765        self.control_handle.shutdown();
766        // Safety: drops once, never accessed again
767        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
768    }
769}
770
771impl fidl::endpoints::Responder for DeviceManagerUnsealResponder {
772    type ControlHandle = DeviceManagerControlHandle;
773
774    fn control_handle(&self) -> &DeviceManagerControlHandle {
775        &self.control_handle
776    }
777
778    fn drop_without_shutdown(mut self) {
779        // Safety: drops once, never accessed again due to mem::forget
780        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
781        // Prevent Drop from running (which would shut down the channel)
782        std::mem::forget(self);
783    }
784}
785
786impl DeviceManagerUnsealResponder {
787    /// Sends a response to the FIDL transaction.
788    ///
789    /// Sets the channel to shutdown if an error occurs.
790    pub fn send(self, mut status: i32) -> Result<(), fidl::Error> {
791        let _result = self.send_raw(status);
792        if _result.is_err() {
793            self.control_handle.shutdown();
794        }
795        self.drop_without_shutdown();
796        _result
797    }
798
799    /// Similar to "send" but does not shutdown the channel if an error occurs.
800    pub fn send_no_shutdown_on_err(self, mut status: i32) -> Result<(), fidl::Error> {
801        let _result = self.send_raw(status);
802        self.drop_without_shutdown();
803        _result
804    }
805
806    fn send_raw(&self, mut status: i32) -> Result<(), fidl::Error> {
807        self.control_handle.inner.send::<DeviceManagerUnsealResponse>(
808            (status,),
809            self.tx_id,
810            0x170f834d39ed94fb,
811            fidl::encoding::DynamicFlags::empty(),
812        )
813    }
814}
815
816#[must_use = "FIDL methods require a response to be sent"]
817#[derive(Debug)]
818pub struct DeviceManagerSealResponder {
819    control_handle: std::mem::ManuallyDrop<DeviceManagerControlHandle>,
820    tx_id: u32,
821}
822
823/// Set the the channel to be shutdown (see [`DeviceManagerControlHandle::shutdown`])
824/// if the responder is dropped without sending a response, so that the client
825/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
826impl std::ops::Drop for DeviceManagerSealResponder {
827    fn drop(&mut self) {
828        self.control_handle.shutdown();
829        // Safety: drops once, never accessed again
830        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
831    }
832}
833
834impl fidl::endpoints::Responder for DeviceManagerSealResponder {
835    type ControlHandle = DeviceManagerControlHandle;
836
837    fn control_handle(&self) -> &DeviceManagerControlHandle {
838        &self.control_handle
839    }
840
841    fn drop_without_shutdown(mut self) {
842        // Safety: drops once, never accessed again due to mem::forget
843        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
844        // Prevent Drop from running (which would shut down the channel)
845        std::mem::forget(self);
846    }
847}
848
849impl DeviceManagerSealResponder {
850    /// Sends a response to the FIDL transaction.
851    ///
852    /// Sets the channel to shutdown if an error occurs.
853    pub fn send(self, mut status: i32) -> Result<(), fidl::Error> {
854        let _result = self.send_raw(status);
855        if _result.is_err() {
856            self.control_handle.shutdown();
857        }
858        self.drop_without_shutdown();
859        _result
860    }
861
862    /// Similar to "send" but does not shutdown the channel if an error occurs.
863    pub fn send_no_shutdown_on_err(self, mut status: i32) -> Result<(), fidl::Error> {
864        let _result = self.send_raw(status);
865        self.drop_without_shutdown();
866        _result
867    }
868
869    fn send_raw(&self, mut status: i32) -> Result<(), fidl::Error> {
870        self.control_handle.inner.send::<DeviceManagerSealResponse>(
871            (status,),
872            self.tx_id,
873            0xe63c7aa7840fbf4,
874            fidl::encoding::DynamicFlags::empty(),
875        )
876    }
877}
878
879#[must_use = "FIDL methods require a response to be sent"]
880#[derive(Debug)]
881pub struct DeviceManagerShredResponder {
882    control_handle: std::mem::ManuallyDrop<DeviceManagerControlHandle>,
883    tx_id: u32,
884}
885
886/// Set the the channel to be shutdown (see [`DeviceManagerControlHandle::shutdown`])
887/// if the responder is dropped without sending a response, so that the client
888/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
889impl std::ops::Drop for DeviceManagerShredResponder {
890    fn drop(&mut self) {
891        self.control_handle.shutdown();
892        // Safety: drops once, never accessed again
893        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
894    }
895}
896
897impl fidl::endpoints::Responder for DeviceManagerShredResponder {
898    type ControlHandle = DeviceManagerControlHandle;
899
900    fn control_handle(&self) -> &DeviceManagerControlHandle {
901        &self.control_handle
902    }
903
904    fn drop_without_shutdown(mut self) {
905        // Safety: drops once, never accessed again due to mem::forget
906        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
907        // Prevent Drop from running (which would shut down the channel)
908        std::mem::forget(self);
909    }
910}
911
912impl DeviceManagerShredResponder {
913    /// Sends a response to the FIDL transaction.
914    ///
915    /// Sets the channel to shutdown if an error occurs.
916    pub fn send(self, mut status: i32) -> Result<(), fidl::Error> {
917        let _result = self.send_raw(status);
918        if _result.is_err() {
919            self.control_handle.shutdown();
920        }
921        self.drop_without_shutdown();
922        _result
923    }
924
925    /// Similar to "send" but does not shutdown the channel if an error occurs.
926    pub fn send_no_shutdown_on_err(self, mut status: i32) -> Result<(), fidl::Error> {
927        let _result = self.send_raw(status);
928        self.drop_without_shutdown();
929        _result
930    }
931
932    fn send_raw(&self, mut status: i32) -> Result<(), fidl::Error> {
933        self.control_handle.inner.send::<DeviceManagerShredResponse>(
934            (status,),
935            self.tx_id,
936            0x1fbff042770086c,
937            fidl::encoding::DynamicFlags::empty(),
938        )
939    }
940}
941
942mod internal {
943    use super::*;
944}