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