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