Skip to main content

fidl_fuchsia_hardware_inlineencryption/
fidl_fuchsia_hardware_inlineencryption.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_inlineencryption_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct ControllerDeriveRawSecretRequest {
16    pub wrapped_key: Vec<u8>,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for ControllerDeriveRawSecretRequest
21{
22}
23
24#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
25pub struct ControllerProgramKeySlotRequest {
26    pub wrapped_key: Vec<u8>,
27    pub data_unit_size: u32,
28}
29
30impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
31    for ControllerProgramKeySlotRequest
32{
33}
34
35#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
36pub struct ControllerDeriveRawSecretResponse {
37    pub secret: Vec<u8>,
38}
39
40impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
41    for ControllerDeriveRawSecretResponse
42{
43}
44
45#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
46pub struct DeviceDeriveRawSecretRequest {
47    pub wrapped_key: Vec<u8>,
48}
49
50impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
51    for DeviceDeriveRawSecretRequest
52{
53}
54
55#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
56pub struct DeviceProgramKeyRequest {
57    pub wrapped_key: Vec<u8>,
58    pub data_unit_size: u32,
59}
60
61impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for DeviceProgramKeyRequest {}
62
63#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
64pub struct DeviceDeriveRawSecretResponse {
65    pub secret: Vec<u8>,
66}
67
68impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
69    for DeviceDeriveRawSecretResponse
70{
71}
72
73#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
74pub struct DeviceProgramKeyResponse {
75    pub key_token: fidl::EventPair,
76}
77
78impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for DeviceProgramKeyResponse {}
79
80#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
81pub struct ControllerMarker;
82
83impl fidl::endpoints::ProtocolMarker for ControllerMarker {
84    type Proxy = ControllerProxy;
85    type RequestStream = ControllerRequestStream;
86    #[cfg(target_os = "fuchsia")]
87    type SynchronousProxy = ControllerSynchronousProxy;
88
89    const DEBUG_NAME: &'static str = "fuchsia.hardware.inlineencryption.Controller";
90}
91impl fidl::endpoints::DiscoverableProtocolMarker for ControllerMarker {}
92pub type ControllerProgramKeySlotResult = Result<u8, i32>;
93pub type ControllerDeriveRawSecretResult = Result<Vec<u8>, i32>;
94
95pub trait ControllerProxyInterface: Send + Sync {
96    type ProgramKeySlotResponseFut: std::future::Future<Output = Result<ControllerProgramKeySlotResult, fidl::Error>>
97        + Send;
98    fn r#program_key_slot(
99        &self,
100        wrapped_key: &[u8],
101        data_unit_size: u32,
102    ) -> Self::ProgramKeySlotResponseFut;
103    type DeriveRawSecretResponseFut: std::future::Future<Output = Result<ControllerDeriveRawSecretResult, fidl::Error>>
104        + Send;
105    fn r#derive_raw_secret(&self, wrapped_key: &[u8]) -> Self::DeriveRawSecretResponseFut;
106}
107#[derive(Debug)]
108#[cfg(target_os = "fuchsia")]
109pub struct ControllerSynchronousProxy {
110    client: fidl::client::sync::Client,
111}
112
113#[cfg(target_os = "fuchsia")]
114impl fidl::endpoints::SynchronousProxy for ControllerSynchronousProxy {
115    type Proxy = ControllerProxy;
116    type Protocol = ControllerMarker;
117
118    fn from_channel(inner: fidl::Channel) -> Self {
119        Self::new(inner)
120    }
121
122    fn into_channel(self) -> fidl::Channel {
123        self.client.into_channel()
124    }
125
126    fn as_channel(&self) -> &fidl::Channel {
127        self.client.as_channel()
128    }
129}
130
131#[cfg(target_os = "fuchsia")]
132impl ControllerSynchronousProxy {
133    pub fn new(channel: fidl::Channel) -> Self {
134        Self { client: fidl::client::sync::Client::new(channel) }
135    }
136
137    pub fn into_channel(self) -> fidl::Channel {
138        self.client.into_channel()
139    }
140
141    /// Waits until an event arrives and returns it. It is safe for other
142    /// threads to make concurrent requests while waiting for an event.
143    pub fn wait_for_event(
144        &self,
145        deadline: zx::MonotonicInstant,
146    ) -> Result<ControllerEvent, fidl::Error> {
147        ControllerEvent::decode(self.client.wait_for_event::<ControllerMarker>(deadline)?)
148    }
149
150    pub fn r#program_key_slot(
151        &self,
152        mut wrapped_key: &[u8],
153        mut data_unit_size: u32,
154        ___deadline: zx::MonotonicInstant,
155    ) -> Result<ControllerProgramKeySlotResult, fidl::Error> {
156        let _response = self.client.send_query::<
157            ControllerProgramKeySlotRequest,
158            fidl::encoding::ResultType<ControllerProgramKeySlotResponse, i32>,
159            ControllerMarker,
160        >(
161            (wrapped_key, data_unit_size,),
162            0xacf9189df7f52e7,
163            fidl::encoding::DynamicFlags::empty(),
164            ___deadline,
165        )?;
166        Ok(_response.map(|x| x.slot))
167    }
168
169    pub fn r#derive_raw_secret(
170        &self,
171        mut wrapped_key: &[u8],
172        ___deadline: zx::MonotonicInstant,
173    ) -> Result<ControllerDeriveRawSecretResult, fidl::Error> {
174        let _response = self.client.send_query::<
175            ControllerDeriveRawSecretRequest,
176            fidl::encoding::ResultType<ControllerDeriveRawSecretResponse, i32>,
177            ControllerMarker,
178        >(
179            (wrapped_key,),
180            0x7141b24312e43ca4,
181            fidl::encoding::DynamicFlags::empty(),
182            ___deadline,
183        )?;
184        Ok(_response.map(|x| x.secret))
185    }
186}
187
188#[cfg(target_os = "fuchsia")]
189impl From<ControllerSynchronousProxy> for zx::NullableHandle {
190    fn from(value: ControllerSynchronousProxy) -> Self {
191        value.into_channel().into()
192    }
193}
194
195#[cfg(target_os = "fuchsia")]
196impl From<fidl::Channel> for ControllerSynchronousProxy {
197    fn from(value: fidl::Channel) -> Self {
198        Self::new(value)
199    }
200}
201
202#[cfg(target_os = "fuchsia")]
203impl fidl::endpoints::FromClient for ControllerSynchronousProxy {
204    type Protocol = ControllerMarker;
205
206    fn from_client(value: fidl::endpoints::ClientEnd<ControllerMarker>) -> Self {
207        Self::new(value.into_channel())
208    }
209}
210
211#[derive(Debug, Clone)]
212pub struct ControllerProxy {
213    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
214}
215
216impl fidl::endpoints::Proxy for ControllerProxy {
217    type Protocol = ControllerMarker;
218
219    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
220        Self::new(inner)
221    }
222
223    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
224        self.client.into_channel().map_err(|client| Self { client })
225    }
226
227    fn as_channel(&self) -> &::fidl::AsyncChannel {
228        self.client.as_channel()
229    }
230}
231
232impl ControllerProxy {
233    /// Create a new Proxy for fuchsia.hardware.inlineencryption/Controller.
234    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
235        let protocol_name = <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
236        Self { client: fidl::client::Client::new(channel, protocol_name) }
237    }
238
239    /// Get a Stream of events from the remote end of the protocol.
240    ///
241    /// # Panics
242    ///
243    /// Panics if the event stream was already taken.
244    pub fn take_event_stream(&self) -> ControllerEventStream {
245        ControllerEventStream { event_receiver: self.client.take_event_receiver() }
246    }
247
248    pub fn r#program_key_slot(
249        &self,
250        mut wrapped_key: &[u8],
251        mut data_unit_size: u32,
252    ) -> fidl::client::QueryResponseFut<
253        ControllerProgramKeySlotResult,
254        fidl::encoding::DefaultFuchsiaResourceDialect,
255    > {
256        ControllerProxyInterface::r#program_key_slot(self, wrapped_key, data_unit_size)
257    }
258
259    pub fn r#derive_raw_secret(
260        &self,
261        mut wrapped_key: &[u8],
262    ) -> fidl::client::QueryResponseFut<
263        ControllerDeriveRawSecretResult,
264        fidl::encoding::DefaultFuchsiaResourceDialect,
265    > {
266        ControllerProxyInterface::r#derive_raw_secret(self, wrapped_key)
267    }
268}
269
270impl ControllerProxyInterface for ControllerProxy {
271    type ProgramKeySlotResponseFut = fidl::client::QueryResponseFut<
272        ControllerProgramKeySlotResult,
273        fidl::encoding::DefaultFuchsiaResourceDialect,
274    >;
275    fn r#program_key_slot(
276        &self,
277        mut wrapped_key: &[u8],
278        mut data_unit_size: u32,
279    ) -> Self::ProgramKeySlotResponseFut {
280        fn _decode(
281            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
282        ) -> Result<ControllerProgramKeySlotResult, fidl::Error> {
283            let _response = fidl::client::decode_transaction_body::<
284                fidl::encoding::ResultType<ControllerProgramKeySlotResponse, i32>,
285                fidl::encoding::DefaultFuchsiaResourceDialect,
286                0xacf9189df7f52e7,
287            >(_buf?)?;
288            Ok(_response.map(|x| x.slot))
289        }
290        self.client.send_query_and_decode::<
291            ControllerProgramKeySlotRequest,
292            ControllerProgramKeySlotResult,
293        >(
294            (wrapped_key, data_unit_size,),
295            0xacf9189df7f52e7,
296            fidl::encoding::DynamicFlags::empty(),
297            _decode,
298        )
299    }
300
301    type DeriveRawSecretResponseFut = fidl::client::QueryResponseFut<
302        ControllerDeriveRawSecretResult,
303        fidl::encoding::DefaultFuchsiaResourceDialect,
304    >;
305    fn r#derive_raw_secret(&self, mut wrapped_key: &[u8]) -> Self::DeriveRawSecretResponseFut {
306        fn _decode(
307            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
308        ) -> Result<ControllerDeriveRawSecretResult, fidl::Error> {
309            let _response = fidl::client::decode_transaction_body::<
310                fidl::encoding::ResultType<ControllerDeriveRawSecretResponse, i32>,
311                fidl::encoding::DefaultFuchsiaResourceDialect,
312                0x7141b24312e43ca4,
313            >(_buf?)?;
314            Ok(_response.map(|x| x.secret))
315        }
316        self.client.send_query_and_decode::<
317            ControllerDeriveRawSecretRequest,
318            ControllerDeriveRawSecretResult,
319        >(
320            (wrapped_key,),
321            0x7141b24312e43ca4,
322            fidl::encoding::DynamicFlags::empty(),
323            _decode,
324        )
325    }
326}
327
328pub struct ControllerEventStream {
329    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
330}
331
332impl std::marker::Unpin for ControllerEventStream {}
333
334impl futures::stream::FusedStream for ControllerEventStream {
335    fn is_terminated(&self) -> bool {
336        self.event_receiver.is_terminated()
337    }
338}
339
340impl futures::Stream for ControllerEventStream {
341    type Item = Result<ControllerEvent, fidl::Error>;
342
343    fn poll_next(
344        mut self: std::pin::Pin<&mut Self>,
345        cx: &mut std::task::Context<'_>,
346    ) -> std::task::Poll<Option<Self::Item>> {
347        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
348            &mut self.event_receiver,
349            cx
350        )?) {
351            Some(buf) => std::task::Poll::Ready(Some(ControllerEvent::decode(buf))),
352            None => std::task::Poll::Ready(None),
353        }
354    }
355}
356
357#[derive(Debug)]
358pub enum ControllerEvent {}
359
360impl ControllerEvent {
361    /// Decodes a message buffer as a [`ControllerEvent`].
362    fn decode(
363        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
364    ) -> Result<ControllerEvent, fidl::Error> {
365        let (bytes, _handles) = buf.split_mut();
366        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
367        debug_assert_eq!(tx_header.tx_id, 0);
368        match tx_header.ordinal {
369            _ => Err(fidl::Error::UnknownOrdinal {
370                ordinal: tx_header.ordinal,
371                protocol_name: <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
372            }),
373        }
374    }
375}
376
377/// A Stream of incoming requests for fuchsia.hardware.inlineencryption/Controller.
378pub struct ControllerRequestStream {
379    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
380    is_terminated: bool,
381}
382
383impl std::marker::Unpin for ControllerRequestStream {}
384
385impl futures::stream::FusedStream for ControllerRequestStream {
386    fn is_terminated(&self) -> bool {
387        self.is_terminated
388    }
389}
390
391impl fidl::endpoints::RequestStream for ControllerRequestStream {
392    type Protocol = ControllerMarker;
393    type ControlHandle = ControllerControlHandle;
394
395    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
396        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
397    }
398
399    fn control_handle(&self) -> Self::ControlHandle {
400        ControllerControlHandle { inner: self.inner.clone() }
401    }
402
403    fn into_inner(
404        self,
405    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
406    {
407        (self.inner, self.is_terminated)
408    }
409
410    fn from_inner(
411        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
412        is_terminated: bool,
413    ) -> Self {
414        Self { inner, is_terminated }
415    }
416}
417
418impl futures::Stream for ControllerRequestStream {
419    type Item = Result<ControllerRequest, fidl::Error>;
420
421    fn poll_next(
422        mut self: std::pin::Pin<&mut Self>,
423        cx: &mut std::task::Context<'_>,
424    ) -> std::task::Poll<Option<Self::Item>> {
425        let this = &mut *self;
426        if this.inner.check_shutdown(cx) {
427            this.is_terminated = true;
428            return std::task::Poll::Ready(None);
429        }
430        if this.is_terminated {
431            panic!("polled ControllerRequestStream after completion");
432        }
433        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
434            |bytes, handles| {
435                match this.inner.channel().read_etc(cx, bytes, handles) {
436                    std::task::Poll::Ready(Ok(())) => {}
437                    std::task::Poll::Pending => return std::task::Poll::Pending,
438                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
439                        this.is_terminated = true;
440                        return std::task::Poll::Ready(None);
441                    }
442                    std::task::Poll::Ready(Err(e)) => {
443                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
444                            e.into(),
445                        ))));
446                    }
447                }
448
449                // A message has been received from the channel
450                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
451
452                std::task::Poll::Ready(Some(match header.ordinal {
453                    0xacf9189df7f52e7 => {
454                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
455                        let mut req = fidl::new_empty!(
456                            ControllerProgramKeySlotRequest,
457                            fidl::encoding::DefaultFuchsiaResourceDialect
458                        );
459                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ControllerProgramKeySlotRequest>(&header, _body_bytes, handles, &mut req)?;
460                        let control_handle = ControllerControlHandle { inner: this.inner.clone() };
461                        Ok(ControllerRequest::ProgramKeySlot {
462                            wrapped_key: req.wrapped_key,
463                            data_unit_size: req.data_unit_size,
464
465                            responder: ControllerProgramKeySlotResponder {
466                                control_handle: std::mem::ManuallyDrop::new(control_handle),
467                                tx_id: header.tx_id,
468                            },
469                        })
470                    }
471                    0x7141b24312e43ca4 => {
472                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
473                        let mut req = fidl::new_empty!(
474                            ControllerDeriveRawSecretRequest,
475                            fidl::encoding::DefaultFuchsiaResourceDialect
476                        );
477                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ControllerDeriveRawSecretRequest>(&header, _body_bytes, handles, &mut req)?;
478                        let control_handle = ControllerControlHandle { inner: this.inner.clone() };
479                        Ok(ControllerRequest::DeriveRawSecret {
480                            wrapped_key: req.wrapped_key,
481
482                            responder: ControllerDeriveRawSecretResponder {
483                                control_handle: std::mem::ManuallyDrop::new(control_handle),
484                                tx_id: header.tx_id,
485                            },
486                        })
487                    }
488                    _ => Err(fidl::Error::UnknownOrdinal {
489                        ordinal: header.ordinal,
490                        protocol_name:
491                            <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
492                    }),
493                }))
494            },
495        )
496    }
497}
498
499/// Protocol used between block drivers and hardware inline encryption controllers.
500#[derive(Debug)]
501pub enum ControllerRequest {
502    ProgramKeySlot {
503        wrapped_key: Vec<u8>,
504        data_unit_size: u32,
505        responder: ControllerProgramKeySlotResponder,
506    },
507    DeriveRawSecret {
508        wrapped_key: Vec<u8>,
509        responder: ControllerDeriveRawSecretResponder,
510    },
511}
512
513impl ControllerRequest {
514    #[allow(irrefutable_let_patterns)]
515    pub fn into_program_key_slot(
516        self,
517    ) -> Option<(Vec<u8>, u32, ControllerProgramKeySlotResponder)> {
518        if let ControllerRequest::ProgramKeySlot { wrapped_key, data_unit_size, responder } = self {
519            Some((wrapped_key, data_unit_size, responder))
520        } else {
521            None
522        }
523    }
524
525    #[allow(irrefutable_let_patterns)]
526    pub fn into_derive_raw_secret(self) -> Option<(Vec<u8>, ControllerDeriveRawSecretResponder)> {
527        if let ControllerRequest::DeriveRawSecret { wrapped_key, responder } = self {
528            Some((wrapped_key, responder))
529        } else {
530            None
531        }
532    }
533
534    /// Name of the method defined in FIDL
535    pub fn method_name(&self) -> &'static str {
536        match *self {
537            ControllerRequest::ProgramKeySlot { .. } => "program_key_slot",
538            ControllerRequest::DeriveRawSecret { .. } => "derive_raw_secret",
539        }
540    }
541}
542
543#[derive(Debug, Clone)]
544pub struct ControllerControlHandle {
545    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
546}
547
548impl ControllerControlHandle {
549    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
550        self.inner.shutdown_with_epitaph(status.into())
551    }
552}
553
554impl fidl::endpoints::ControlHandle for ControllerControlHandle {
555    fn shutdown(&self) {
556        self.inner.shutdown()
557    }
558
559    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
560        self.inner.shutdown_with_epitaph(status)
561    }
562
563    fn is_closed(&self) -> bool {
564        self.inner.channel().is_closed()
565    }
566    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
567        self.inner.channel().on_closed()
568    }
569
570    #[cfg(target_os = "fuchsia")]
571    fn signal_peer(
572        &self,
573        clear_mask: zx::Signals,
574        set_mask: zx::Signals,
575    ) -> Result<(), zx_status::Status> {
576        use fidl::Peered;
577        self.inner.channel().signal_peer(clear_mask, set_mask)
578    }
579}
580
581impl ControllerControlHandle {}
582
583#[must_use = "FIDL methods require a response to be sent"]
584#[derive(Debug)]
585pub struct ControllerProgramKeySlotResponder {
586    control_handle: std::mem::ManuallyDrop<ControllerControlHandle>,
587    tx_id: u32,
588}
589
590/// Set the the channel to be shutdown (see [`ControllerControlHandle::shutdown`])
591/// if the responder is dropped without sending a response, so that the client
592/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
593impl std::ops::Drop for ControllerProgramKeySlotResponder {
594    fn drop(&mut self) {
595        self.control_handle.shutdown();
596        // Safety: drops once, never accessed again
597        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
598    }
599}
600
601impl fidl::endpoints::Responder for ControllerProgramKeySlotResponder {
602    type ControlHandle = ControllerControlHandle;
603
604    fn control_handle(&self) -> &ControllerControlHandle {
605        &self.control_handle
606    }
607
608    fn drop_without_shutdown(mut self) {
609        // Safety: drops once, never accessed again due to mem::forget
610        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
611        // Prevent Drop from running (which would shut down the channel)
612        std::mem::forget(self);
613    }
614}
615
616impl ControllerProgramKeySlotResponder {
617    /// Sends a response to the FIDL transaction.
618    ///
619    /// Sets the channel to shutdown if an error occurs.
620    pub fn send(self, mut result: Result<u8, i32>) -> Result<(), fidl::Error> {
621        let _result = self.send_raw(result);
622        if _result.is_err() {
623            self.control_handle.shutdown();
624        }
625        self.drop_without_shutdown();
626        _result
627    }
628
629    /// Similar to "send" but does not shutdown the channel if an error occurs.
630    pub fn send_no_shutdown_on_err(self, mut result: Result<u8, i32>) -> Result<(), fidl::Error> {
631        let _result = self.send_raw(result);
632        self.drop_without_shutdown();
633        _result
634    }
635
636    fn send_raw(&self, mut result: Result<u8, i32>) -> Result<(), fidl::Error> {
637        self.control_handle
638            .inner
639            .send::<fidl::encoding::ResultType<ControllerProgramKeySlotResponse, i32>>(
640                result.map(|slot| (slot,)),
641                self.tx_id,
642                0xacf9189df7f52e7,
643                fidl::encoding::DynamicFlags::empty(),
644            )
645    }
646}
647
648#[must_use = "FIDL methods require a response to be sent"]
649#[derive(Debug)]
650pub struct ControllerDeriveRawSecretResponder {
651    control_handle: std::mem::ManuallyDrop<ControllerControlHandle>,
652    tx_id: u32,
653}
654
655/// Set the the channel to be shutdown (see [`ControllerControlHandle::shutdown`])
656/// if the responder is dropped without sending a response, so that the client
657/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
658impl std::ops::Drop for ControllerDeriveRawSecretResponder {
659    fn drop(&mut self) {
660        self.control_handle.shutdown();
661        // Safety: drops once, never accessed again
662        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
663    }
664}
665
666impl fidl::endpoints::Responder for ControllerDeriveRawSecretResponder {
667    type ControlHandle = ControllerControlHandle;
668
669    fn control_handle(&self) -> &ControllerControlHandle {
670        &self.control_handle
671    }
672
673    fn drop_without_shutdown(mut self) {
674        // Safety: drops once, never accessed again due to mem::forget
675        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
676        // Prevent Drop from running (which would shut down the channel)
677        std::mem::forget(self);
678    }
679}
680
681impl ControllerDeriveRawSecretResponder {
682    /// Sends a response to the FIDL transaction.
683    ///
684    /// Sets the channel to shutdown if an error occurs.
685    pub fn send(self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
686        let _result = self.send_raw(result);
687        if _result.is_err() {
688            self.control_handle.shutdown();
689        }
690        self.drop_without_shutdown();
691        _result
692    }
693
694    /// Similar to "send" but does not shutdown the channel if an error occurs.
695    pub fn send_no_shutdown_on_err(
696        self,
697        mut result: Result<&[u8], i32>,
698    ) -> Result<(), fidl::Error> {
699        let _result = self.send_raw(result);
700        self.drop_without_shutdown();
701        _result
702    }
703
704    fn send_raw(&self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
705        self.control_handle
706            .inner
707            .send::<fidl::encoding::ResultType<ControllerDeriveRawSecretResponse, i32>>(
708                result.map(|secret| (secret,)),
709                self.tx_id,
710                0x7141b24312e43ca4,
711                fidl::encoding::DynamicFlags::empty(),
712            )
713    }
714}
715
716#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
717pub struct DeviceMarker;
718
719impl fidl::endpoints::ProtocolMarker for DeviceMarker {
720    type Proxy = DeviceProxy;
721    type RequestStream = DeviceRequestStream;
722    #[cfg(target_os = "fuchsia")]
723    type SynchronousProxy = DeviceSynchronousProxy;
724
725    const DEBUG_NAME: &'static str = "fuchsia.hardware.inlineencryption.Device";
726}
727impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
728pub type DeviceProgramKeyResult = Result<fidl::EventPair, i32>;
729pub type DeviceDeriveRawSecretResult = Result<Vec<u8>, i32>;
730
731pub trait DeviceProxyInterface: Send + Sync {
732    type ProgramKeyResponseFut: std::future::Future<Output = Result<DeviceProgramKeyResult, fidl::Error>>
733        + Send;
734    fn r#program_key(&self, wrapped_key: &[u8], data_unit_size: u32)
735    -> Self::ProgramKeyResponseFut;
736    type DeriveRawSecretResponseFut: std::future::Future<Output = Result<DeviceDeriveRawSecretResult, fidl::Error>>
737        + Send;
738    fn r#derive_raw_secret(&self, wrapped_key: &[u8]) -> Self::DeriveRawSecretResponseFut;
739}
740#[derive(Debug)]
741#[cfg(target_os = "fuchsia")]
742pub struct DeviceSynchronousProxy {
743    client: fidl::client::sync::Client,
744}
745
746#[cfg(target_os = "fuchsia")]
747impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
748    type Proxy = DeviceProxy;
749    type Protocol = DeviceMarker;
750
751    fn from_channel(inner: fidl::Channel) -> Self {
752        Self::new(inner)
753    }
754
755    fn into_channel(self) -> fidl::Channel {
756        self.client.into_channel()
757    }
758
759    fn as_channel(&self) -> &fidl::Channel {
760        self.client.as_channel()
761    }
762}
763
764#[cfg(target_os = "fuchsia")]
765impl DeviceSynchronousProxy {
766    pub fn new(channel: fidl::Channel) -> Self {
767        Self { client: fidl::client::sync::Client::new(channel) }
768    }
769
770    pub fn into_channel(self) -> fidl::Channel {
771        self.client.into_channel()
772    }
773
774    /// Waits until an event arrives and returns it. It is safe for other
775    /// threads to make concurrent requests while waiting for an event.
776    pub fn wait_for_event(
777        &self,
778        deadline: zx::MonotonicInstant,
779    ) -> Result<DeviceEvent, fidl::Error> {
780        DeviceEvent::decode(self.client.wait_for_event::<DeviceMarker>(deadline)?)
781    }
782
783    /// Programs the ephemerally wrapped `wrapped_key` into the inline encryption hardware in the
784    /// next available slot and returns a `key_token` capability representing that slot. The
785    /// returned `key_token` must be registered with a block session via
786    /// `fuchsia.storage.block/Session.RegisterKey` before the slot can be used in block I/O
787    /// requests. All slots programmed via the connection this method is called on will be evicted
788    /// once the connection is dropped. It is not possible to evict individual keys (not for any
789    /// technical reasons; a need for this has not yet arisen). `wrapped_key` must be a key wrapped
790    /// by the inline encryption hardware (in the same session/boot) via a separate mechanism to
791    /// this protocol.
792    ///
793    /// Returns
794    /// - ZX_ERR_NO_RESOURCES if there are no available key slots.
795    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
796    ///   fails authentication (e.g. wrapped_key is from a previous boot).
797    /// - ZX_ERR_TIMED_OUT if the operation times out.
798    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
799    pub fn r#program_key(
800        &self,
801        mut wrapped_key: &[u8],
802        mut data_unit_size: u32,
803        ___deadline: zx::MonotonicInstant,
804    ) -> Result<DeviceProgramKeyResult, fidl::Error> {
805        let _response = self.client.send_query::<
806            DeviceProgramKeyRequest,
807            fidl::encoding::ResultType<DeviceProgramKeyResponse, i32>,
808            DeviceMarker,
809        >(
810            (wrapped_key, data_unit_size,),
811            0x30401dc60fc47cd0,
812            fidl::encoding::DynamicFlags::empty(),
813            ___deadline,
814        )?;
815        Ok(_response.map(|x| x.key_token))
816    }
817
818    /// Derives a raw software secret from the ephemerally wrapped `wrapped_key`. `wrapped_key`
819    /// must be a key wrapped by the inline encryption hardware (in the same session/boot) via a
820    /// separate mechanism to this protocol. The returned secret can be used for non-inline
821    /// cryptographic operations e.g. it can be used for encrypting filesystem metadata not covered
822    /// by inline encryption.
823    /// Returns
824    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
825    ///   fails authentication (e.g. wrapped_key is from a previous boot).
826    /// - ZX_ERR_TIMED_OUT if the operation times out.
827    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
828    pub fn r#derive_raw_secret(
829        &self,
830        mut wrapped_key: &[u8],
831        ___deadline: zx::MonotonicInstant,
832    ) -> Result<DeviceDeriveRawSecretResult, fidl::Error> {
833        let _response = self.client.send_query::<
834            DeviceDeriveRawSecretRequest,
835            fidl::encoding::ResultType<DeviceDeriveRawSecretResponse, i32>,
836            DeviceMarker,
837        >(
838            (wrapped_key,),
839            0x605392dccdef79d4,
840            fidl::encoding::DynamicFlags::empty(),
841            ___deadline,
842        )?;
843        Ok(_response.map(|x| x.secret))
844    }
845}
846
847#[cfg(target_os = "fuchsia")]
848impl From<DeviceSynchronousProxy> for zx::NullableHandle {
849    fn from(value: DeviceSynchronousProxy) -> Self {
850        value.into_channel().into()
851    }
852}
853
854#[cfg(target_os = "fuchsia")]
855impl From<fidl::Channel> for DeviceSynchronousProxy {
856    fn from(value: fidl::Channel) -> Self {
857        Self::new(value)
858    }
859}
860
861#[cfg(target_os = "fuchsia")]
862impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
863    type Protocol = DeviceMarker;
864
865    fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
866        Self::new(value.into_channel())
867    }
868}
869
870#[derive(Debug, Clone)]
871pub struct DeviceProxy {
872    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
873}
874
875impl fidl::endpoints::Proxy for DeviceProxy {
876    type Protocol = DeviceMarker;
877
878    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
879        Self::new(inner)
880    }
881
882    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
883        self.client.into_channel().map_err(|client| Self { client })
884    }
885
886    fn as_channel(&self) -> &::fidl::AsyncChannel {
887        self.client.as_channel()
888    }
889}
890
891impl DeviceProxy {
892    /// Create a new Proxy for fuchsia.hardware.inlineencryption/Device.
893    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
894        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
895        Self { client: fidl::client::Client::new(channel, protocol_name) }
896    }
897
898    /// Get a Stream of events from the remote end of the protocol.
899    ///
900    /// # Panics
901    ///
902    /// Panics if the event stream was already taken.
903    pub fn take_event_stream(&self) -> DeviceEventStream {
904        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
905    }
906
907    /// Programs the ephemerally wrapped `wrapped_key` into the inline encryption hardware in the
908    /// next available slot and returns a `key_token` capability representing that slot. The
909    /// returned `key_token` must be registered with a block session via
910    /// `fuchsia.storage.block/Session.RegisterKey` before the slot can be used in block I/O
911    /// requests. All slots programmed via the connection this method is called on will be evicted
912    /// once the connection is dropped. It is not possible to evict individual keys (not for any
913    /// technical reasons; a need for this has not yet arisen). `wrapped_key` must be a key wrapped
914    /// by the inline encryption hardware (in the same session/boot) via a separate mechanism to
915    /// this protocol.
916    ///
917    /// Returns
918    /// - ZX_ERR_NO_RESOURCES if there are no available key slots.
919    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
920    ///   fails authentication (e.g. wrapped_key is from a previous boot).
921    /// - ZX_ERR_TIMED_OUT if the operation times out.
922    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
923    pub fn r#program_key(
924        &self,
925        mut wrapped_key: &[u8],
926        mut data_unit_size: u32,
927    ) -> fidl::client::QueryResponseFut<
928        DeviceProgramKeyResult,
929        fidl::encoding::DefaultFuchsiaResourceDialect,
930    > {
931        DeviceProxyInterface::r#program_key(self, wrapped_key, data_unit_size)
932    }
933
934    /// Derives a raw software secret from the ephemerally wrapped `wrapped_key`. `wrapped_key`
935    /// must be a key wrapped by the inline encryption hardware (in the same session/boot) via a
936    /// separate mechanism to this protocol. The returned secret can be used for non-inline
937    /// cryptographic operations e.g. it can be used for encrypting filesystem metadata not covered
938    /// by inline encryption.
939    /// Returns
940    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
941    ///   fails authentication (e.g. wrapped_key is from a previous boot).
942    /// - ZX_ERR_TIMED_OUT if the operation times out.
943    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
944    pub fn r#derive_raw_secret(
945        &self,
946        mut wrapped_key: &[u8],
947    ) -> fidl::client::QueryResponseFut<
948        DeviceDeriveRawSecretResult,
949        fidl::encoding::DefaultFuchsiaResourceDialect,
950    > {
951        DeviceProxyInterface::r#derive_raw_secret(self, wrapped_key)
952    }
953}
954
955impl DeviceProxyInterface for DeviceProxy {
956    type ProgramKeyResponseFut = fidl::client::QueryResponseFut<
957        DeviceProgramKeyResult,
958        fidl::encoding::DefaultFuchsiaResourceDialect,
959    >;
960    fn r#program_key(
961        &self,
962        mut wrapped_key: &[u8],
963        mut data_unit_size: u32,
964    ) -> Self::ProgramKeyResponseFut {
965        fn _decode(
966            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
967        ) -> Result<DeviceProgramKeyResult, fidl::Error> {
968            let _response = fidl::client::decode_transaction_body::<
969                fidl::encoding::ResultType<DeviceProgramKeyResponse, i32>,
970                fidl::encoding::DefaultFuchsiaResourceDialect,
971                0x30401dc60fc47cd0,
972            >(_buf?)?;
973            Ok(_response.map(|x| x.key_token))
974        }
975        self.client.send_query_and_decode::<DeviceProgramKeyRequest, DeviceProgramKeyResult>(
976            (wrapped_key, data_unit_size),
977            0x30401dc60fc47cd0,
978            fidl::encoding::DynamicFlags::empty(),
979            _decode,
980        )
981    }
982
983    type DeriveRawSecretResponseFut = fidl::client::QueryResponseFut<
984        DeviceDeriveRawSecretResult,
985        fidl::encoding::DefaultFuchsiaResourceDialect,
986    >;
987    fn r#derive_raw_secret(&self, mut wrapped_key: &[u8]) -> Self::DeriveRawSecretResponseFut {
988        fn _decode(
989            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
990        ) -> Result<DeviceDeriveRawSecretResult, fidl::Error> {
991            let _response = fidl::client::decode_transaction_body::<
992                fidl::encoding::ResultType<DeviceDeriveRawSecretResponse, i32>,
993                fidl::encoding::DefaultFuchsiaResourceDialect,
994                0x605392dccdef79d4,
995            >(_buf?)?;
996            Ok(_response.map(|x| x.secret))
997        }
998        self.client
999            .send_query_and_decode::<DeviceDeriveRawSecretRequest, DeviceDeriveRawSecretResult>(
1000                (wrapped_key,),
1001                0x605392dccdef79d4,
1002                fidl::encoding::DynamicFlags::empty(),
1003                _decode,
1004            )
1005    }
1006}
1007
1008pub struct DeviceEventStream {
1009    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1010}
1011
1012impl std::marker::Unpin for DeviceEventStream {}
1013
1014impl futures::stream::FusedStream for DeviceEventStream {
1015    fn is_terminated(&self) -> bool {
1016        self.event_receiver.is_terminated()
1017    }
1018}
1019
1020impl futures::Stream for DeviceEventStream {
1021    type Item = Result<DeviceEvent, fidl::Error>;
1022
1023    fn poll_next(
1024        mut self: std::pin::Pin<&mut Self>,
1025        cx: &mut std::task::Context<'_>,
1026    ) -> std::task::Poll<Option<Self::Item>> {
1027        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1028            &mut self.event_receiver,
1029            cx
1030        )?) {
1031            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
1032            None => std::task::Poll::Ready(None),
1033        }
1034    }
1035}
1036
1037#[derive(Debug)]
1038pub enum DeviceEvent {}
1039
1040impl DeviceEvent {
1041    /// Decodes a message buffer as a [`DeviceEvent`].
1042    fn decode(
1043        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1044    ) -> Result<DeviceEvent, fidl::Error> {
1045        let (bytes, _handles) = buf.split_mut();
1046        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1047        debug_assert_eq!(tx_header.tx_id, 0);
1048        match tx_header.ordinal {
1049            _ => Err(fidl::Error::UnknownOrdinal {
1050                ordinal: tx_header.ordinal,
1051                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1052            }),
1053        }
1054    }
1055}
1056
1057/// A Stream of incoming requests for fuchsia.hardware.inlineencryption/Device.
1058pub struct DeviceRequestStream {
1059    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1060    is_terminated: bool,
1061}
1062
1063impl std::marker::Unpin for DeviceRequestStream {}
1064
1065impl futures::stream::FusedStream for DeviceRequestStream {
1066    fn is_terminated(&self) -> bool {
1067        self.is_terminated
1068    }
1069}
1070
1071impl fidl::endpoints::RequestStream for DeviceRequestStream {
1072    type Protocol = DeviceMarker;
1073    type ControlHandle = DeviceControlHandle;
1074
1075    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1076        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1077    }
1078
1079    fn control_handle(&self) -> Self::ControlHandle {
1080        DeviceControlHandle { inner: self.inner.clone() }
1081    }
1082
1083    fn into_inner(
1084        self,
1085    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1086    {
1087        (self.inner, self.is_terminated)
1088    }
1089
1090    fn from_inner(
1091        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1092        is_terminated: bool,
1093    ) -> Self {
1094        Self { inner, is_terminated }
1095    }
1096}
1097
1098impl futures::Stream for DeviceRequestStream {
1099    type Item = Result<DeviceRequest, fidl::Error>;
1100
1101    fn poll_next(
1102        mut self: std::pin::Pin<&mut Self>,
1103        cx: &mut std::task::Context<'_>,
1104    ) -> std::task::Poll<Option<Self::Item>> {
1105        let this = &mut *self;
1106        if this.inner.check_shutdown(cx) {
1107            this.is_terminated = true;
1108            return std::task::Poll::Ready(None);
1109        }
1110        if this.is_terminated {
1111            panic!("polled DeviceRequestStream after completion");
1112        }
1113        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1114            |bytes, handles| {
1115                match this.inner.channel().read_etc(cx, bytes, handles) {
1116                    std::task::Poll::Ready(Ok(())) => {}
1117                    std::task::Poll::Pending => return std::task::Poll::Pending,
1118                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1119                        this.is_terminated = true;
1120                        return std::task::Poll::Ready(None);
1121                    }
1122                    std::task::Poll::Ready(Err(e)) => {
1123                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1124                            e.into(),
1125                        ))));
1126                    }
1127                }
1128
1129                // A message has been received from the channel
1130                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1131
1132                std::task::Poll::Ready(Some(match header.ordinal {
1133                    0x30401dc60fc47cd0 => {
1134                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1135                        let mut req = fidl::new_empty!(
1136                            DeviceProgramKeyRequest,
1137                            fidl::encoding::DefaultFuchsiaResourceDialect
1138                        );
1139                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceProgramKeyRequest>(&header, _body_bytes, handles, &mut req)?;
1140                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
1141                        Ok(DeviceRequest::ProgramKey {
1142                            wrapped_key: req.wrapped_key,
1143                            data_unit_size: req.data_unit_size,
1144
1145                            responder: DeviceProgramKeyResponder {
1146                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1147                                tx_id: header.tx_id,
1148                            },
1149                        })
1150                    }
1151                    0x605392dccdef79d4 => {
1152                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1153                        let mut req = fidl::new_empty!(
1154                            DeviceDeriveRawSecretRequest,
1155                            fidl::encoding::DefaultFuchsiaResourceDialect
1156                        );
1157                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceDeriveRawSecretRequest>(&header, _body_bytes, handles, &mut req)?;
1158                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
1159                        Ok(DeviceRequest::DeriveRawSecret {
1160                            wrapped_key: req.wrapped_key,
1161
1162                            responder: DeviceDeriveRawSecretResponder {
1163                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1164                                tx_id: header.tx_id,
1165                            },
1166                        })
1167                    }
1168                    _ => Err(fidl::Error::UnknownOrdinal {
1169                        ordinal: header.ordinal,
1170                        protocol_name:
1171                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1172                    }),
1173                }))
1174            },
1175        )
1176    }
1177}
1178
1179#[derive(Debug)]
1180pub enum DeviceRequest {
1181    /// Programs the ephemerally wrapped `wrapped_key` into the inline encryption hardware in the
1182    /// next available slot and returns a `key_token` capability representing that slot. The
1183    /// returned `key_token` must be registered with a block session via
1184    /// `fuchsia.storage.block/Session.RegisterKey` before the slot can be used in block I/O
1185    /// requests. All slots programmed via the connection this method is called on will be evicted
1186    /// once the connection is dropped. It is not possible to evict individual keys (not for any
1187    /// technical reasons; a need for this has not yet arisen). `wrapped_key` must be a key wrapped
1188    /// by the inline encryption hardware (in the same session/boot) via a separate mechanism to
1189    /// this protocol.
1190    ///
1191    /// Returns
1192    /// - ZX_ERR_NO_RESOURCES if there are no available key slots.
1193    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
1194    ///   fails authentication (e.g. wrapped_key is from a previous boot).
1195    /// - ZX_ERR_TIMED_OUT if the operation times out.
1196    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
1197    ProgramKey { wrapped_key: Vec<u8>, data_unit_size: u32, responder: DeviceProgramKeyResponder },
1198    /// Derives a raw software secret from the ephemerally wrapped `wrapped_key`. `wrapped_key`
1199    /// must be a key wrapped by the inline encryption hardware (in the same session/boot) via a
1200    /// separate mechanism to this protocol. The returned secret can be used for non-inline
1201    /// cryptographic operations e.g. it can be used for encrypting filesystem metadata not covered
1202    /// by inline encryption.
1203    /// Returns
1204    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
1205    ///   fails authentication (e.g. wrapped_key is from a previous boot).
1206    /// - ZX_ERR_TIMED_OUT if the operation times out.
1207    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
1208    DeriveRawSecret { wrapped_key: Vec<u8>, responder: DeviceDeriveRawSecretResponder },
1209}
1210
1211impl DeviceRequest {
1212    #[allow(irrefutable_let_patterns)]
1213    pub fn into_program_key(self) -> Option<(Vec<u8>, u32, DeviceProgramKeyResponder)> {
1214        if let DeviceRequest::ProgramKey { wrapped_key, data_unit_size, responder } = self {
1215            Some((wrapped_key, data_unit_size, responder))
1216        } else {
1217            None
1218        }
1219    }
1220
1221    #[allow(irrefutable_let_patterns)]
1222    pub fn into_derive_raw_secret(self) -> Option<(Vec<u8>, DeviceDeriveRawSecretResponder)> {
1223        if let DeviceRequest::DeriveRawSecret { wrapped_key, responder } = self {
1224            Some((wrapped_key, responder))
1225        } else {
1226            None
1227        }
1228    }
1229
1230    /// Name of the method defined in FIDL
1231    pub fn method_name(&self) -> &'static str {
1232        match *self {
1233            DeviceRequest::ProgramKey { .. } => "program_key",
1234            DeviceRequest::DeriveRawSecret { .. } => "derive_raw_secret",
1235        }
1236    }
1237}
1238
1239#[derive(Debug, Clone)]
1240pub struct DeviceControlHandle {
1241    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1242}
1243
1244impl DeviceControlHandle {
1245    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
1246        self.inner.shutdown_with_epitaph(status.into())
1247    }
1248}
1249
1250impl fidl::endpoints::ControlHandle for DeviceControlHandle {
1251    fn shutdown(&self) {
1252        self.inner.shutdown()
1253    }
1254
1255    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
1256        self.inner.shutdown_with_epitaph(status)
1257    }
1258
1259    fn is_closed(&self) -> bool {
1260        self.inner.channel().is_closed()
1261    }
1262    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1263        self.inner.channel().on_closed()
1264    }
1265
1266    #[cfg(target_os = "fuchsia")]
1267    fn signal_peer(
1268        &self,
1269        clear_mask: zx::Signals,
1270        set_mask: zx::Signals,
1271    ) -> Result<(), zx_status::Status> {
1272        use fidl::Peered;
1273        self.inner.channel().signal_peer(clear_mask, set_mask)
1274    }
1275}
1276
1277impl DeviceControlHandle {}
1278
1279#[must_use = "FIDL methods require a response to be sent"]
1280#[derive(Debug)]
1281pub struct DeviceProgramKeyResponder {
1282    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1283    tx_id: u32,
1284}
1285
1286/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1287/// if the responder is dropped without sending a response, so that the client
1288/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1289impl std::ops::Drop for DeviceProgramKeyResponder {
1290    fn drop(&mut self) {
1291        self.control_handle.shutdown();
1292        // Safety: drops once, never accessed again
1293        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1294    }
1295}
1296
1297impl fidl::endpoints::Responder for DeviceProgramKeyResponder {
1298    type ControlHandle = DeviceControlHandle;
1299
1300    fn control_handle(&self) -> &DeviceControlHandle {
1301        &self.control_handle
1302    }
1303
1304    fn drop_without_shutdown(mut self) {
1305        // Safety: drops once, never accessed again due to mem::forget
1306        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1307        // Prevent Drop from running (which would shut down the channel)
1308        std::mem::forget(self);
1309    }
1310}
1311
1312impl DeviceProgramKeyResponder {
1313    /// Sends a response to the FIDL transaction.
1314    ///
1315    /// Sets the channel to shutdown if an error occurs.
1316    pub fn send(self, mut result: Result<fidl::EventPair, i32>) -> Result<(), fidl::Error> {
1317        let _result = self.send_raw(result);
1318        if _result.is_err() {
1319            self.control_handle.shutdown();
1320        }
1321        self.drop_without_shutdown();
1322        _result
1323    }
1324
1325    /// Similar to "send" but does not shutdown the channel if an error occurs.
1326    pub fn send_no_shutdown_on_err(
1327        self,
1328        mut result: Result<fidl::EventPair, i32>,
1329    ) -> Result<(), fidl::Error> {
1330        let _result = self.send_raw(result);
1331        self.drop_without_shutdown();
1332        _result
1333    }
1334
1335    fn send_raw(&self, mut result: Result<fidl::EventPair, i32>) -> Result<(), fidl::Error> {
1336        self.control_handle.inner.send::<fidl::encoding::ResultType<DeviceProgramKeyResponse, i32>>(
1337            result.map(|key_token| (key_token,)),
1338            self.tx_id,
1339            0x30401dc60fc47cd0,
1340            fidl::encoding::DynamicFlags::empty(),
1341        )
1342    }
1343}
1344
1345#[must_use = "FIDL methods require a response to be sent"]
1346#[derive(Debug)]
1347pub struct DeviceDeriveRawSecretResponder {
1348    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1349    tx_id: u32,
1350}
1351
1352/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1353/// if the responder is dropped without sending a response, so that the client
1354/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1355impl std::ops::Drop for DeviceDeriveRawSecretResponder {
1356    fn drop(&mut self) {
1357        self.control_handle.shutdown();
1358        // Safety: drops once, never accessed again
1359        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1360    }
1361}
1362
1363impl fidl::endpoints::Responder for DeviceDeriveRawSecretResponder {
1364    type ControlHandle = DeviceControlHandle;
1365
1366    fn control_handle(&self) -> &DeviceControlHandle {
1367        &self.control_handle
1368    }
1369
1370    fn drop_without_shutdown(mut self) {
1371        // Safety: drops once, never accessed again due to mem::forget
1372        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1373        // Prevent Drop from running (which would shut down the channel)
1374        std::mem::forget(self);
1375    }
1376}
1377
1378impl DeviceDeriveRawSecretResponder {
1379    /// Sends a response to the FIDL transaction.
1380    ///
1381    /// Sets the channel to shutdown if an error occurs.
1382    pub fn send(self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
1383        let _result = self.send_raw(result);
1384        if _result.is_err() {
1385            self.control_handle.shutdown();
1386        }
1387        self.drop_without_shutdown();
1388        _result
1389    }
1390
1391    /// Similar to "send" but does not shutdown the channel if an error occurs.
1392    pub fn send_no_shutdown_on_err(
1393        self,
1394        mut result: Result<&[u8], i32>,
1395    ) -> Result<(), fidl::Error> {
1396        let _result = self.send_raw(result);
1397        self.drop_without_shutdown();
1398        _result
1399    }
1400
1401    fn send_raw(&self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
1402        self.control_handle
1403            .inner
1404            .send::<fidl::encoding::ResultType<DeviceDeriveRawSecretResponse, i32>>(
1405                result.map(|secret| (secret,)),
1406                self.tx_id,
1407                0x605392dccdef79d4,
1408                fidl::encoding::DynamicFlags::empty(),
1409            )
1410    }
1411}
1412
1413mod internal {
1414    use super::*;
1415
1416    impl fidl::encoding::ResourceTypeMarker for ControllerDeriveRawSecretRequest {
1417        type Borrowed<'a> = &'a mut Self;
1418        fn take_or_borrow<'a>(
1419            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1420        ) -> Self::Borrowed<'a> {
1421            value
1422        }
1423    }
1424
1425    unsafe impl fidl::encoding::TypeMarker for ControllerDeriveRawSecretRequest {
1426        type Owned = Self;
1427
1428        #[inline(always)]
1429        fn inline_align(_context: fidl::encoding::Context) -> usize {
1430            8
1431        }
1432
1433        #[inline(always)]
1434        fn inline_size(_context: fidl::encoding::Context) -> usize {
1435            16
1436        }
1437    }
1438
1439    unsafe impl
1440        fidl::encoding::Encode<
1441            ControllerDeriveRawSecretRequest,
1442            fidl::encoding::DefaultFuchsiaResourceDialect,
1443        > for &mut ControllerDeriveRawSecretRequest
1444    {
1445        #[inline]
1446        unsafe fn encode(
1447            self,
1448            encoder: &mut fidl::encoding::Encoder<
1449                '_,
1450                fidl::encoding::DefaultFuchsiaResourceDialect,
1451            >,
1452            offset: usize,
1453            _depth: fidl::encoding::Depth,
1454        ) -> fidl::Result<()> {
1455            encoder.debug_check_bounds::<ControllerDeriveRawSecretRequest>(offset);
1456            // Delegate to tuple encoding.
1457            fidl::encoding::Encode::<
1458                ControllerDeriveRawSecretRequest,
1459                fidl::encoding::DefaultFuchsiaResourceDialect,
1460            >::encode(
1461                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
1462                    &self.wrapped_key,
1463                ),),
1464                encoder,
1465                offset,
1466                _depth,
1467            )
1468        }
1469    }
1470    unsafe impl<
1471        T0: fidl::encoding::Encode<
1472                fidl::encoding::UnboundedVector<u8>,
1473                fidl::encoding::DefaultFuchsiaResourceDialect,
1474            >,
1475    >
1476        fidl::encoding::Encode<
1477            ControllerDeriveRawSecretRequest,
1478            fidl::encoding::DefaultFuchsiaResourceDialect,
1479        > for (T0,)
1480    {
1481        #[inline]
1482        unsafe fn encode(
1483            self,
1484            encoder: &mut fidl::encoding::Encoder<
1485                '_,
1486                fidl::encoding::DefaultFuchsiaResourceDialect,
1487            >,
1488            offset: usize,
1489            depth: fidl::encoding::Depth,
1490        ) -> fidl::Result<()> {
1491            encoder.debug_check_bounds::<ControllerDeriveRawSecretRequest>(offset);
1492            // Zero out padding regions. There's no need to apply masks
1493            // because the unmasked parts will be overwritten by fields.
1494            // Write the fields.
1495            self.0.encode(encoder, offset + 0, depth)?;
1496            Ok(())
1497        }
1498    }
1499
1500    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1501        for ControllerDeriveRawSecretRequest
1502    {
1503        #[inline(always)]
1504        fn new_empty() -> Self {
1505            Self {
1506                wrapped_key: fidl::new_empty!(
1507                    fidl::encoding::UnboundedVector<u8>,
1508                    fidl::encoding::DefaultFuchsiaResourceDialect
1509                ),
1510            }
1511        }
1512
1513        #[inline]
1514        unsafe fn decode(
1515            &mut self,
1516            decoder: &mut fidl::encoding::Decoder<
1517                '_,
1518                fidl::encoding::DefaultFuchsiaResourceDialect,
1519            >,
1520            offset: usize,
1521            _depth: fidl::encoding::Depth,
1522        ) -> fidl::Result<()> {
1523            decoder.debug_check_bounds::<Self>(offset);
1524            // Verify that padding bytes are zero.
1525            fidl::decode!(
1526                fidl::encoding::UnboundedVector<u8>,
1527                fidl::encoding::DefaultFuchsiaResourceDialect,
1528                &mut self.wrapped_key,
1529                decoder,
1530                offset + 0,
1531                _depth
1532            )?;
1533            Ok(())
1534        }
1535    }
1536
1537    impl fidl::encoding::ResourceTypeMarker for ControllerProgramKeySlotRequest {
1538        type Borrowed<'a> = &'a mut Self;
1539        fn take_or_borrow<'a>(
1540            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1541        ) -> Self::Borrowed<'a> {
1542            value
1543        }
1544    }
1545
1546    unsafe impl fidl::encoding::TypeMarker for ControllerProgramKeySlotRequest {
1547        type Owned = Self;
1548
1549        #[inline(always)]
1550        fn inline_align(_context: fidl::encoding::Context) -> usize {
1551            8
1552        }
1553
1554        #[inline(always)]
1555        fn inline_size(_context: fidl::encoding::Context) -> usize {
1556            24
1557        }
1558    }
1559
1560    unsafe impl
1561        fidl::encoding::Encode<
1562            ControllerProgramKeySlotRequest,
1563            fidl::encoding::DefaultFuchsiaResourceDialect,
1564        > for &mut ControllerProgramKeySlotRequest
1565    {
1566        #[inline]
1567        unsafe fn encode(
1568            self,
1569            encoder: &mut fidl::encoding::Encoder<
1570                '_,
1571                fidl::encoding::DefaultFuchsiaResourceDialect,
1572            >,
1573            offset: usize,
1574            _depth: fidl::encoding::Depth,
1575        ) -> fidl::Result<()> {
1576            encoder.debug_check_bounds::<ControllerProgramKeySlotRequest>(offset);
1577            // Delegate to tuple encoding.
1578            fidl::encoding::Encode::<ControllerProgramKeySlotRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1579                (
1580                    <fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(&self.wrapped_key),
1581                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.data_unit_size),
1582                ),
1583                encoder, offset, _depth
1584            )
1585        }
1586    }
1587    unsafe impl<
1588        T0: fidl::encoding::Encode<
1589                fidl::encoding::UnboundedVector<u8>,
1590                fidl::encoding::DefaultFuchsiaResourceDialect,
1591            >,
1592        T1: fidl::encoding::Encode<u32, fidl::encoding::DefaultFuchsiaResourceDialect>,
1593    >
1594        fidl::encoding::Encode<
1595            ControllerProgramKeySlotRequest,
1596            fidl::encoding::DefaultFuchsiaResourceDialect,
1597        > for (T0, T1)
1598    {
1599        #[inline]
1600        unsafe fn encode(
1601            self,
1602            encoder: &mut fidl::encoding::Encoder<
1603                '_,
1604                fidl::encoding::DefaultFuchsiaResourceDialect,
1605            >,
1606            offset: usize,
1607            depth: fidl::encoding::Depth,
1608        ) -> fidl::Result<()> {
1609            encoder.debug_check_bounds::<ControllerProgramKeySlotRequest>(offset);
1610            // Zero out padding regions. There's no need to apply masks
1611            // because the unmasked parts will be overwritten by fields.
1612            unsafe {
1613                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1614                (ptr as *mut u64).write_unaligned(0);
1615            }
1616            // Write the fields.
1617            self.0.encode(encoder, offset + 0, depth)?;
1618            self.1.encode(encoder, offset + 16, depth)?;
1619            Ok(())
1620        }
1621    }
1622
1623    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1624        for ControllerProgramKeySlotRequest
1625    {
1626        #[inline(always)]
1627        fn new_empty() -> Self {
1628            Self {
1629                wrapped_key: fidl::new_empty!(
1630                    fidl::encoding::UnboundedVector<u8>,
1631                    fidl::encoding::DefaultFuchsiaResourceDialect
1632                ),
1633                data_unit_size: fidl::new_empty!(
1634                    u32,
1635                    fidl::encoding::DefaultFuchsiaResourceDialect
1636                ),
1637            }
1638        }
1639
1640        #[inline]
1641        unsafe fn decode(
1642            &mut self,
1643            decoder: &mut fidl::encoding::Decoder<
1644                '_,
1645                fidl::encoding::DefaultFuchsiaResourceDialect,
1646            >,
1647            offset: usize,
1648            _depth: fidl::encoding::Depth,
1649        ) -> fidl::Result<()> {
1650            decoder.debug_check_bounds::<Self>(offset);
1651            // Verify that padding bytes are zero.
1652            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1653            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1654            let mask = 0xffffffff00000000u64;
1655            let maskedval = padval & mask;
1656            if maskedval != 0 {
1657                return Err(fidl::Error::NonZeroPadding {
1658                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1659                });
1660            }
1661            fidl::decode!(
1662                fidl::encoding::UnboundedVector<u8>,
1663                fidl::encoding::DefaultFuchsiaResourceDialect,
1664                &mut self.wrapped_key,
1665                decoder,
1666                offset + 0,
1667                _depth
1668            )?;
1669            fidl::decode!(
1670                u32,
1671                fidl::encoding::DefaultFuchsiaResourceDialect,
1672                &mut self.data_unit_size,
1673                decoder,
1674                offset + 16,
1675                _depth
1676            )?;
1677            Ok(())
1678        }
1679    }
1680
1681    impl fidl::encoding::ResourceTypeMarker for ControllerDeriveRawSecretResponse {
1682        type Borrowed<'a> = &'a mut Self;
1683        fn take_or_borrow<'a>(
1684            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1685        ) -> Self::Borrowed<'a> {
1686            value
1687        }
1688    }
1689
1690    unsafe impl fidl::encoding::TypeMarker for ControllerDeriveRawSecretResponse {
1691        type Owned = Self;
1692
1693        #[inline(always)]
1694        fn inline_align(_context: fidl::encoding::Context) -> usize {
1695            8
1696        }
1697
1698        #[inline(always)]
1699        fn inline_size(_context: fidl::encoding::Context) -> usize {
1700            16
1701        }
1702    }
1703
1704    unsafe impl
1705        fidl::encoding::Encode<
1706            ControllerDeriveRawSecretResponse,
1707            fidl::encoding::DefaultFuchsiaResourceDialect,
1708        > for &mut ControllerDeriveRawSecretResponse
1709    {
1710        #[inline]
1711        unsafe fn encode(
1712            self,
1713            encoder: &mut fidl::encoding::Encoder<
1714                '_,
1715                fidl::encoding::DefaultFuchsiaResourceDialect,
1716            >,
1717            offset: usize,
1718            _depth: fidl::encoding::Depth,
1719        ) -> fidl::Result<()> {
1720            encoder.debug_check_bounds::<ControllerDeriveRawSecretResponse>(offset);
1721            // Delegate to tuple encoding.
1722            fidl::encoding::Encode::<
1723                ControllerDeriveRawSecretResponse,
1724                fidl::encoding::DefaultFuchsiaResourceDialect,
1725            >::encode(
1726                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
1727                    &self.secret,
1728                ),),
1729                encoder,
1730                offset,
1731                _depth,
1732            )
1733        }
1734    }
1735    unsafe impl<
1736        T0: fidl::encoding::Encode<
1737                fidl::encoding::UnboundedVector<u8>,
1738                fidl::encoding::DefaultFuchsiaResourceDialect,
1739            >,
1740    >
1741        fidl::encoding::Encode<
1742            ControllerDeriveRawSecretResponse,
1743            fidl::encoding::DefaultFuchsiaResourceDialect,
1744        > for (T0,)
1745    {
1746        #[inline]
1747        unsafe fn encode(
1748            self,
1749            encoder: &mut fidl::encoding::Encoder<
1750                '_,
1751                fidl::encoding::DefaultFuchsiaResourceDialect,
1752            >,
1753            offset: usize,
1754            depth: fidl::encoding::Depth,
1755        ) -> fidl::Result<()> {
1756            encoder.debug_check_bounds::<ControllerDeriveRawSecretResponse>(offset);
1757            // Zero out padding regions. There's no need to apply masks
1758            // because the unmasked parts will be overwritten by fields.
1759            // Write the fields.
1760            self.0.encode(encoder, offset + 0, depth)?;
1761            Ok(())
1762        }
1763    }
1764
1765    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1766        for ControllerDeriveRawSecretResponse
1767    {
1768        #[inline(always)]
1769        fn new_empty() -> Self {
1770            Self {
1771                secret: fidl::new_empty!(
1772                    fidl::encoding::UnboundedVector<u8>,
1773                    fidl::encoding::DefaultFuchsiaResourceDialect
1774                ),
1775            }
1776        }
1777
1778        #[inline]
1779        unsafe fn decode(
1780            &mut self,
1781            decoder: &mut fidl::encoding::Decoder<
1782                '_,
1783                fidl::encoding::DefaultFuchsiaResourceDialect,
1784            >,
1785            offset: usize,
1786            _depth: fidl::encoding::Depth,
1787        ) -> fidl::Result<()> {
1788            decoder.debug_check_bounds::<Self>(offset);
1789            // Verify that padding bytes are zero.
1790            fidl::decode!(
1791                fidl::encoding::UnboundedVector<u8>,
1792                fidl::encoding::DefaultFuchsiaResourceDialect,
1793                &mut self.secret,
1794                decoder,
1795                offset + 0,
1796                _depth
1797            )?;
1798            Ok(())
1799        }
1800    }
1801
1802    impl fidl::encoding::ResourceTypeMarker for DeviceDeriveRawSecretRequest {
1803        type Borrowed<'a> = &'a mut Self;
1804        fn take_or_borrow<'a>(
1805            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1806        ) -> Self::Borrowed<'a> {
1807            value
1808        }
1809    }
1810
1811    unsafe impl fidl::encoding::TypeMarker for DeviceDeriveRawSecretRequest {
1812        type Owned = Self;
1813
1814        #[inline(always)]
1815        fn inline_align(_context: fidl::encoding::Context) -> usize {
1816            8
1817        }
1818
1819        #[inline(always)]
1820        fn inline_size(_context: fidl::encoding::Context) -> usize {
1821            16
1822        }
1823    }
1824
1825    unsafe impl
1826        fidl::encoding::Encode<
1827            DeviceDeriveRawSecretRequest,
1828            fidl::encoding::DefaultFuchsiaResourceDialect,
1829        > for &mut DeviceDeriveRawSecretRequest
1830    {
1831        #[inline]
1832        unsafe fn encode(
1833            self,
1834            encoder: &mut fidl::encoding::Encoder<
1835                '_,
1836                fidl::encoding::DefaultFuchsiaResourceDialect,
1837            >,
1838            offset: usize,
1839            _depth: fidl::encoding::Depth,
1840        ) -> fidl::Result<()> {
1841            encoder.debug_check_bounds::<DeviceDeriveRawSecretRequest>(offset);
1842            // Delegate to tuple encoding.
1843            fidl::encoding::Encode::<
1844                DeviceDeriveRawSecretRequest,
1845                fidl::encoding::DefaultFuchsiaResourceDialect,
1846            >::encode(
1847                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
1848                    &self.wrapped_key,
1849                ),),
1850                encoder,
1851                offset,
1852                _depth,
1853            )
1854        }
1855    }
1856    unsafe impl<
1857        T0: fidl::encoding::Encode<
1858                fidl::encoding::UnboundedVector<u8>,
1859                fidl::encoding::DefaultFuchsiaResourceDialect,
1860            >,
1861    >
1862        fidl::encoding::Encode<
1863            DeviceDeriveRawSecretRequest,
1864            fidl::encoding::DefaultFuchsiaResourceDialect,
1865        > for (T0,)
1866    {
1867        #[inline]
1868        unsafe fn encode(
1869            self,
1870            encoder: &mut fidl::encoding::Encoder<
1871                '_,
1872                fidl::encoding::DefaultFuchsiaResourceDialect,
1873            >,
1874            offset: usize,
1875            depth: fidl::encoding::Depth,
1876        ) -> fidl::Result<()> {
1877            encoder.debug_check_bounds::<DeviceDeriveRawSecretRequest>(offset);
1878            // Zero out padding regions. There's no need to apply masks
1879            // because the unmasked parts will be overwritten by fields.
1880            // Write the fields.
1881            self.0.encode(encoder, offset + 0, depth)?;
1882            Ok(())
1883        }
1884    }
1885
1886    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1887        for DeviceDeriveRawSecretRequest
1888    {
1889        #[inline(always)]
1890        fn new_empty() -> Self {
1891            Self {
1892                wrapped_key: fidl::new_empty!(
1893                    fidl::encoding::UnboundedVector<u8>,
1894                    fidl::encoding::DefaultFuchsiaResourceDialect
1895                ),
1896            }
1897        }
1898
1899        #[inline]
1900        unsafe fn decode(
1901            &mut self,
1902            decoder: &mut fidl::encoding::Decoder<
1903                '_,
1904                fidl::encoding::DefaultFuchsiaResourceDialect,
1905            >,
1906            offset: usize,
1907            _depth: fidl::encoding::Depth,
1908        ) -> fidl::Result<()> {
1909            decoder.debug_check_bounds::<Self>(offset);
1910            // Verify that padding bytes are zero.
1911            fidl::decode!(
1912                fidl::encoding::UnboundedVector<u8>,
1913                fidl::encoding::DefaultFuchsiaResourceDialect,
1914                &mut self.wrapped_key,
1915                decoder,
1916                offset + 0,
1917                _depth
1918            )?;
1919            Ok(())
1920        }
1921    }
1922
1923    impl fidl::encoding::ResourceTypeMarker for DeviceProgramKeyRequest {
1924        type Borrowed<'a> = &'a mut Self;
1925        fn take_or_borrow<'a>(
1926            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1927        ) -> Self::Borrowed<'a> {
1928            value
1929        }
1930    }
1931
1932    unsafe impl fidl::encoding::TypeMarker for DeviceProgramKeyRequest {
1933        type Owned = Self;
1934
1935        #[inline(always)]
1936        fn inline_align(_context: fidl::encoding::Context) -> usize {
1937            8
1938        }
1939
1940        #[inline(always)]
1941        fn inline_size(_context: fidl::encoding::Context) -> usize {
1942            24
1943        }
1944    }
1945
1946    unsafe impl
1947        fidl::encoding::Encode<
1948            DeviceProgramKeyRequest,
1949            fidl::encoding::DefaultFuchsiaResourceDialect,
1950        > for &mut DeviceProgramKeyRequest
1951    {
1952        #[inline]
1953        unsafe fn encode(
1954            self,
1955            encoder: &mut fidl::encoding::Encoder<
1956                '_,
1957                fidl::encoding::DefaultFuchsiaResourceDialect,
1958            >,
1959            offset: usize,
1960            _depth: fidl::encoding::Depth,
1961        ) -> fidl::Result<()> {
1962            encoder.debug_check_bounds::<DeviceProgramKeyRequest>(offset);
1963            // Delegate to tuple encoding.
1964            fidl::encoding::Encode::<DeviceProgramKeyRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1965                (
1966                    <fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(&self.wrapped_key),
1967                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.data_unit_size),
1968                ),
1969                encoder, offset, _depth
1970            )
1971        }
1972    }
1973    unsafe impl<
1974        T0: fidl::encoding::Encode<
1975                fidl::encoding::UnboundedVector<u8>,
1976                fidl::encoding::DefaultFuchsiaResourceDialect,
1977            >,
1978        T1: fidl::encoding::Encode<u32, fidl::encoding::DefaultFuchsiaResourceDialect>,
1979    >
1980        fidl::encoding::Encode<
1981            DeviceProgramKeyRequest,
1982            fidl::encoding::DefaultFuchsiaResourceDialect,
1983        > for (T0, T1)
1984    {
1985        #[inline]
1986        unsafe fn encode(
1987            self,
1988            encoder: &mut fidl::encoding::Encoder<
1989                '_,
1990                fidl::encoding::DefaultFuchsiaResourceDialect,
1991            >,
1992            offset: usize,
1993            depth: fidl::encoding::Depth,
1994        ) -> fidl::Result<()> {
1995            encoder.debug_check_bounds::<DeviceProgramKeyRequest>(offset);
1996            // Zero out padding regions. There's no need to apply masks
1997            // because the unmasked parts will be overwritten by fields.
1998            unsafe {
1999                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
2000                (ptr as *mut u64).write_unaligned(0);
2001            }
2002            // Write the fields.
2003            self.0.encode(encoder, offset + 0, depth)?;
2004            self.1.encode(encoder, offset + 16, depth)?;
2005            Ok(())
2006        }
2007    }
2008
2009    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2010        for DeviceProgramKeyRequest
2011    {
2012        #[inline(always)]
2013        fn new_empty() -> Self {
2014            Self {
2015                wrapped_key: fidl::new_empty!(
2016                    fidl::encoding::UnboundedVector<u8>,
2017                    fidl::encoding::DefaultFuchsiaResourceDialect
2018                ),
2019                data_unit_size: fidl::new_empty!(
2020                    u32,
2021                    fidl::encoding::DefaultFuchsiaResourceDialect
2022                ),
2023            }
2024        }
2025
2026        #[inline]
2027        unsafe fn decode(
2028            &mut self,
2029            decoder: &mut fidl::encoding::Decoder<
2030                '_,
2031                fidl::encoding::DefaultFuchsiaResourceDialect,
2032            >,
2033            offset: usize,
2034            _depth: fidl::encoding::Depth,
2035        ) -> fidl::Result<()> {
2036            decoder.debug_check_bounds::<Self>(offset);
2037            // Verify that padding bytes are zero.
2038            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
2039            let padval = unsafe { (ptr as *const u64).read_unaligned() };
2040            let mask = 0xffffffff00000000u64;
2041            let maskedval = padval & mask;
2042            if maskedval != 0 {
2043                return Err(fidl::Error::NonZeroPadding {
2044                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
2045                });
2046            }
2047            fidl::decode!(
2048                fidl::encoding::UnboundedVector<u8>,
2049                fidl::encoding::DefaultFuchsiaResourceDialect,
2050                &mut self.wrapped_key,
2051                decoder,
2052                offset + 0,
2053                _depth
2054            )?;
2055            fidl::decode!(
2056                u32,
2057                fidl::encoding::DefaultFuchsiaResourceDialect,
2058                &mut self.data_unit_size,
2059                decoder,
2060                offset + 16,
2061                _depth
2062            )?;
2063            Ok(())
2064        }
2065    }
2066
2067    impl fidl::encoding::ResourceTypeMarker for DeviceDeriveRawSecretResponse {
2068        type Borrowed<'a> = &'a mut Self;
2069        fn take_or_borrow<'a>(
2070            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2071        ) -> Self::Borrowed<'a> {
2072            value
2073        }
2074    }
2075
2076    unsafe impl fidl::encoding::TypeMarker for DeviceDeriveRawSecretResponse {
2077        type Owned = Self;
2078
2079        #[inline(always)]
2080        fn inline_align(_context: fidl::encoding::Context) -> usize {
2081            8
2082        }
2083
2084        #[inline(always)]
2085        fn inline_size(_context: fidl::encoding::Context) -> usize {
2086            16
2087        }
2088    }
2089
2090    unsafe impl
2091        fidl::encoding::Encode<
2092            DeviceDeriveRawSecretResponse,
2093            fidl::encoding::DefaultFuchsiaResourceDialect,
2094        > for &mut DeviceDeriveRawSecretResponse
2095    {
2096        #[inline]
2097        unsafe fn encode(
2098            self,
2099            encoder: &mut fidl::encoding::Encoder<
2100                '_,
2101                fidl::encoding::DefaultFuchsiaResourceDialect,
2102            >,
2103            offset: usize,
2104            _depth: fidl::encoding::Depth,
2105        ) -> fidl::Result<()> {
2106            encoder.debug_check_bounds::<DeviceDeriveRawSecretResponse>(offset);
2107            // Delegate to tuple encoding.
2108            fidl::encoding::Encode::<
2109                DeviceDeriveRawSecretResponse,
2110                fidl::encoding::DefaultFuchsiaResourceDialect,
2111            >::encode(
2112                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
2113                    &self.secret,
2114                ),),
2115                encoder,
2116                offset,
2117                _depth,
2118            )
2119        }
2120    }
2121    unsafe impl<
2122        T0: fidl::encoding::Encode<
2123                fidl::encoding::UnboundedVector<u8>,
2124                fidl::encoding::DefaultFuchsiaResourceDialect,
2125            >,
2126    >
2127        fidl::encoding::Encode<
2128            DeviceDeriveRawSecretResponse,
2129            fidl::encoding::DefaultFuchsiaResourceDialect,
2130        > for (T0,)
2131    {
2132        #[inline]
2133        unsafe fn encode(
2134            self,
2135            encoder: &mut fidl::encoding::Encoder<
2136                '_,
2137                fidl::encoding::DefaultFuchsiaResourceDialect,
2138            >,
2139            offset: usize,
2140            depth: fidl::encoding::Depth,
2141        ) -> fidl::Result<()> {
2142            encoder.debug_check_bounds::<DeviceDeriveRawSecretResponse>(offset);
2143            // Zero out padding regions. There's no need to apply masks
2144            // because the unmasked parts will be overwritten by fields.
2145            // Write the fields.
2146            self.0.encode(encoder, offset + 0, depth)?;
2147            Ok(())
2148        }
2149    }
2150
2151    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2152        for DeviceDeriveRawSecretResponse
2153    {
2154        #[inline(always)]
2155        fn new_empty() -> Self {
2156            Self {
2157                secret: fidl::new_empty!(
2158                    fidl::encoding::UnboundedVector<u8>,
2159                    fidl::encoding::DefaultFuchsiaResourceDialect
2160                ),
2161            }
2162        }
2163
2164        #[inline]
2165        unsafe fn decode(
2166            &mut self,
2167            decoder: &mut fidl::encoding::Decoder<
2168                '_,
2169                fidl::encoding::DefaultFuchsiaResourceDialect,
2170            >,
2171            offset: usize,
2172            _depth: fidl::encoding::Depth,
2173        ) -> fidl::Result<()> {
2174            decoder.debug_check_bounds::<Self>(offset);
2175            // Verify that padding bytes are zero.
2176            fidl::decode!(
2177                fidl::encoding::UnboundedVector<u8>,
2178                fidl::encoding::DefaultFuchsiaResourceDialect,
2179                &mut self.secret,
2180                decoder,
2181                offset + 0,
2182                _depth
2183            )?;
2184            Ok(())
2185        }
2186    }
2187
2188    impl fidl::encoding::ResourceTypeMarker for DeviceProgramKeyResponse {
2189        type Borrowed<'a> = &'a mut Self;
2190        fn take_or_borrow<'a>(
2191            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2192        ) -> Self::Borrowed<'a> {
2193            value
2194        }
2195    }
2196
2197    unsafe impl fidl::encoding::TypeMarker for DeviceProgramKeyResponse {
2198        type Owned = Self;
2199
2200        #[inline(always)]
2201        fn inline_align(_context: fidl::encoding::Context) -> usize {
2202            4
2203        }
2204
2205        #[inline(always)]
2206        fn inline_size(_context: fidl::encoding::Context) -> usize {
2207            4
2208        }
2209    }
2210
2211    unsafe impl
2212        fidl::encoding::Encode<
2213            DeviceProgramKeyResponse,
2214            fidl::encoding::DefaultFuchsiaResourceDialect,
2215        > for &mut DeviceProgramKeyResponse
2216    {
2217        #[inline]
2218        unsafe fn encode(
2219            self,
2220            encoder: &mut fidl::encoding::Encoder<
2221                '_,
2222                fidl::encoding::DefaultFuchsiaResourceDialect,
2223            >,
2224            offset: usize,
2225            _depth: fidl::encoding::Depth,
2226        ) -> fidl::Result<()> {
2227            encoder.debug_check_bounds::<DeviceProgramKeyResponse>(offset);
2228            // Delegate to tuple encoding.
2229            fidl::encoding::Encode::<
2230                DeviceProgramKeyResponse,
2231                fidl::encoding::DefaultFuchsiaResourceDialect,
2232            >::encode(
2233                (<fidl::encoding::HandleType<
2234                    fidl::EventPair,
2235                    { fidl::ObjectType::EVENTPAIR.into_raw() },
2236                    2147483648,
2237                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
2238                    &mut self.key_token
2239                ),),
2240                encoder,
2241                offset,
2242                _depth,
2243            )
2244        }
2245    }
2246    unsafe impl<
2247        T0: fidl::encoding::Encode<
2248                fidl::encoding::HandleType<
2249                    fidl::EventPair,
2250                    { fidl::ObjectType::EVENTPAIR.into_raw() },
2251                    2147483648,
2252                >,
2253                fidl::encoding::DefaultFuchsiaResourceDialect,
2254            >,
2255    >
2256        fidl::encoding::Encode<
2257            DeviceProgramKeyResponse,
2258            fidl::encoding::DefaultFuchsiaResourceDialect,
2259        > for (T0,)
2260    {
2261        #[inline]
2262        unsafe fn encode(
2263            self,
2264            encoder: &mut fidl::encoding::Encoder<
2265                '_,
2266                fidl::encoding::DefaultFuchsiaResourceDialect,
2267            >,
2268            offset: usize,
2269            depth: fidl::encoding::Depth,
2270        ) -> fidl::Result<()> {
2271            encoder.debug_check_bounds::<DeviceProgramKeyResponse>(offset);
2272            // Zero out padding regions. There's no need to apply masks
2273            // because the unmasked parts will be overwritten by fields.
2274            // Write the fields.
2275            self.0.encode(encoder, offset + 0, depth)?;
2276            Ok(())
2277        }
2278    }
2279
2280    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2281        for DeviceProgramKeyResponse
2282    {
2283        #[inline(always)]
2284        fn new_empty() -> Self {
2285            Self {
2286                key_token: fidl::new_empty!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
2287            }
2288        }
2289
2290        #[inline]
2291        unsafe fn decode(
2292            &mut self,
2293            decoder: &mut fidl::encoding::Decoder<
2294                '_,
2295                fidl::encoding::DefaultFuchsiaResourceDialect,
2296            >,
2297            offset: usize,
2298            _depth: fidl::encoding::Depth,
2299        ) -> fidl::Result<()> {
2300            decoder.debug_check_bounds::<Self>(offset);
2301            // Verify that padding bytes are zero.
2302            fidl::decode!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.key_token, decoder, offset + 0, _depth)?;
2303            Ok(())
2304        }
2305    }
2306}