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 DeviceDeriveRawSecretRequest {
16    pub wrapped_key: Vec<u8>,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for DeviceDeriveRawSecretRequest
21{
22}
23
24#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
25pub struct DeviceProgramKeyRequest {
26    pub wrapped_key: Vec<u8>,
27    pub data_unit_size: u32,
28}
29
30impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for DeviceProgramKeyRequest {}
31
32#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
33pub struct DeviceDeriveRawSecretResponse {
34    pub secret: Vec<u8>,
35}
36
37impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
38    for DeviceDeriveRawSecretResponse
39{
40}
41
42#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
43pub struct DeviceMarker;
44
45impl fidl::endpoints::ProtocolMarker for DeviceMarker {
46    type Proxy = DeviceProxy;
47    type RequestStream = DeviceRequestStream;
48    #[cfg(target_os = "fuchsia")]
49    type SynchronousProxy = DeviceSynchronousProxy;
50
51    const DEBUG_NAME: &'static str = "fuchsia.hardware.inlineencryption.Device";
52}
53impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
54pub type DeviceProgramKeyResult = Result<u8, i32>;
55pub type DeviceDeriveRawSecretResult = Result<Vec<u8>, i32>;
56
57pub trait DeviceProxyInterface: Send + Sync {
58    type ProgramKeyResponseFut: std::future::Future<Output = Result<DeviceProgramKeyResult, fidl::Error>>
59        + Send;
60    fn r#program_key(&self, wrapped_key: &[u8], data_unit_size: u32)
61    -> Self::ProgramKeyResponseFut;
62    type DeriveRawSecretResponseFut: std::future::Future<Output = Result<DeviceDeriveRawSecretResult, fidl::Error>>
63        + Send;
64    fn r#derive_raw_secret(&self, wrapped_key: &[u8]) -> Self::DeriveRawSecretResponseFut;
65}
66#[derive(Debug)]
67#[cfg(target_os = "fuchsia")]
68pub struct DeviceSynchronousProxy {
69    client: fidl::client::sync::Client,
70}
71
72#[cfg(target_os = "fuchsia")]
73impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
74    type Proxy = DeviceProxy;
75    type Protocol = DeviceMarker;
76
77    fn from_channel(inner: fidl::Channel) -> Self {
78        Self::new(inner)
79    }
80
81    fn into_channel(self) -> fidl::Channel {
82        self.client.into_channel()
83    }
84
85    fn as_channel(&self) -> &fidl::Channel {
86        self.client.as_channel()
87    }
88}
89
90#[cfg(target_os = "fuchsia")]
91impl DeviceSynchronousProxy {
92    pub fn new(channel: fidl::Channel) -> Self {
93        Self { client: fidl::client::sync::Client::new(channel) }
94    }
95
96    pub fn into_channel(self) -> fidl::Channel {
97        self.client.into_channel()
98    }
99
100    /// Waits until an event arrives and returns it. It is safe for other
101    /// threads to make concurrent requests while waiting for an event.
102    pub fn wait_for_event(
103        &self,
104        deadline: zx::MonotonicInstant,
105    ) -> Result<DeviceEvent, fidl::Error> {
106        DeviceEvent::decode(self.client.wait_for_event::<DeviceMarker>(deadline)?)
107    }
108
109    /// Programs the ephemerally wrapped `wrapped_key` into the inline encryption hardware in the
110    /// next available `slot`. All slots programmed via the connection this method is called on
111    /// will be evicted once the connection is dropped. It is not possible to evict individual keys
112    /// (not for any technical reasons; a need for this has not yet arisen). `wrapped_key` must be
113    /// a key wrapped by the inline encryption hardware (in the same session/boot) via a separate
114    /// mechanism to this protocol.
115    ///
116    /// Returns
117    /// - ZX_ERR_NO_RESOURCES if there are no available key slots.
118    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
119    ///   fails authentication (e.g. wrapped_key is from a previous boot).
120    /// - ZX_ERR_TIMED_OUT if the operation times out.
121    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
122    pub fn r#program_key(
123        &self,
124        mut wrapped_key: &[u8],
125        mut data_unit_size: u32,
126        ___deadline: zx::MonotonicInstant,
127    ) -> Result<DeviceProgramKeyResult, fidl::Error> {
128        let _response = self.client.send_query::<
129            DeviceProgramKeyRequest,
130            fidl::encoding::ResultType<DeviceProgramKeyResponse, i32>,
131            DeviceMarker,
132        >(
133            (wrapped_key, data_unit_size,),
134            0x30401dc60fc47cd0,
135            fidl::encoding::DynamicFlags::empty(),
136            ___deadline,
137        )?;
138        Ok(_response.map(|x| x.slot))
139    }
140
141    /// Derives a raw software secret from the ephemerally wrapped `wrapped_key`. `wrapped_key`
142    /// must be a key wrapped by the inline encryption hardware (in the same session/boot) via a
143    /// separate mechanism to this protocol. The returned secret can be used for non-inline
144    /// cryptographic operations e.g. it can be used for encrypting filesystem metadata not covered
145    /// by inline encryption.
146    /// Returns
147    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
148    ///   fails authentication (e.g. wrapped_key is from a previous boot).
149    /// - ZX_ERR_TIMED_OUT if the operation times out.
150    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
151    pub fn r#derive_raw_secret(
152        &self,
153        mut wrapped_key: &[u8],
154        ___deadline: zx::MonotonicInstant,
155    ) -> Result<DeviceDeriveRawSecretResult, fidl::Error> {
156        let _response = self.client.send_query::<
157            DeviceDeriveRawSecretRequest,
158            fidl::encoding::ResultType<DeviceDeriveRawSecretResponse, i32>,
159            DeviceMarker,
160        >(
161            (wrapped_key,),
162            0x605392dccdef79d4,
163            fidl::encoding::DynamicFlags::empty(),
164            ___deadline,
165        )?;
166        Ok(_response.map(|x| x.secret))
167    }
168}
169
170#[cfg(target_os = "fuchsia")]
171impl From<DeviceSynchronousProxy> for zx::NullableHandle {
172    fn from(value: DeviceSynchronousProxy) -> Self {
173        value.into_channel().into()
174    }
175}
176
177#[cfg(target_os = "fuchsia")]
178impl From<fidl::Channel> for DeviceSynchronousProxy {
179    fn from(value: fidl::Channel) -> Self {
180        Self::new(value)
181    }
182}
183
184#[cfg(target_os = "fuchsia")]
185impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
186    type Protocol = DeviceMarker;
187
188    fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
189        Self::new(value.into_channel())
190    }
191}
192
193#[derive(Debug, Clone)]
194pub struct DeviceProxy {
195    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
196}
197
198impl fidl::endpoints::Proxy for DeviceProxy {
199    type Protocol = DeviceMarker;
200
201    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
202        Self::new(inner)
203    }
204
205    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
206        self.client.into_channel().map_err(|client| Self { client })
207    }
208
209    fn as_channel(&self) -> &::fidl::AsyncChannel {
210        self.client.as_channel()
211    }
212}
213
214impl DeviceProxy {
215    /// Create a new Proxy for fuchsia.hardware.inlineencryption/Device.
216    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
217        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
218        Self { client: fidl::client::Client::new(channel, protocol_name) }
219    }
220
221    /// Get a Stream of events from the remote end of the protocol.
222    ///
223    /// # Panics
224    ///
225    /// Panics if the event stream was already taken.
226    pub fn take_event_stream(&self) -> DeviceEventStream {
227        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
228    }
229
230    /// Programs the ephemerally wrapped `wrapped_key` into the inline encryption hardware in the
231    /// next available `slot`. All slots programmed via the connection this method is called on
232    /// will be evicted once the connection is dropped. It is not possible to evict individual keys
233    /// (not for any technical reasons; a need for this has not yet arisen). `wrapped_key` must be
234    /// a key wrapped by the inline encryption hardware (in the same session/boot) via a separate
235    /// mechanism to this protocol.
236    ///
237    /// Returns
238    /// - ZX_ERR_NO_RESOURCES if there are no available key slots.
239    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
240    ///   fails authentication (e.g. wrapped_key is from a previous boot).
241    /// - ZX_ERR_TIMED_OUT if the operation times out.
242    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
243    pub fn r#program_key(
244        &self,
245        mut wrapped_key: &[u8],
246        mut data_unit_size: u32,
247    ) -> fidl::client::QueryResponseFut<
248        DeviceProgramKeyResult,
249        fidl::encoding::DefaultFuchsiaResourceDialect,
250    > {
251        DeviceProxyInterface::r#program_key(self, wrapped_key, data_unit_size)
252    }
253
254    /// Derives a raw software secret from the ephemerally wrapped `wrapped_key`. `wrapped_key`
255    /// must be a key wrapped by the inline encryption hardware (in the same session/boot) via a
256    /// separate mechanism to this protocol. The returned secret can be used for non-inline
257    /// cryptographic operations e.g. it can be used for encrypting filesystem metadata not covered
258    /// by inline encryption.
259    /// Returns
260    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
261    ///   fails authentication (e.g. wrapped_key is from a previous boot).
262    /// - ZX_ERR_TIMED_OUT if the operation times out.
263    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
264    pub fn r#derive_raw_secret(
265        &self,
266        mut wrapped_key: &[u8],
267    ) -> fidl::client::QueryResponseFut<
268        DeviceDeriveRawSecretResult,
269        fidl::encoding::DefaultFuchsiaResourceDialect,
270    > {
271        DeviceProxyInterface::r#derive_raw_secret(self, wrapped_key)
272    }
273}
274
275impl DeviceProxyInterface for DeviceProxy {
276    type ProgramKeyResponseFut = fidl::client::QueryResponseFut<
277        DeviceProgramKeyResult,
278        fidl::encoding::DefaultFuchsiaResourceDialect,
279    >;
280    fn r#program_key(
281        &self,
282        mut wrapped_key: &[u8],
283        mut data_unit_size: u32,
284    ) -> Self::ProgramKeyResponseFut {
285        fn _decode(
286            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
287        ) -> Result<DeviceProgramKeyResult, fidl::Error> {
288            let _response = fidl::client::decode_transaction_body::<
289                fidl::encoding::ResultType<DeviceProgramKeyResponse, i32>,
290                fidl::encoding::DefaultFuchsiaResourceDialect,
291                0x30401dc60fc47cd0,
292            >(_buf?)?;
293            Ok(_response.map(|x| x.slot))
294        }
295        self.client.send_query_and_decode::<DeviceProgramKeyRequest, DeviceProgramKeyResult>(
296            (wrapped_key, data_unit_size),
297            0x30401dc60fc47cd0,
298            fidl::encoding::DynamicFlags::empty(),
299            _decode,
300        )
301    }
302
303    type DeriveRawSecretResponseFut = fidl::client::QueryResponseFut<
304        DeviceDeriveRawSecretResult,
305        fidl::encoding::DefaultFuchsiaResourceDialect,
306    >;
307    fn r#derive_raw_secret(&self, mut wrapped_key: &[u8]) -> Self::DeriveRawSecretResponseFut {
308        fn _decode(
309            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
310        ) -> Result<DeviceDeriveRawSecretResult, fidl::Error> {
311            let _response = fidl::client::decode_transaction_body::<
312                fidl::encoding::ResultType<DeviceDeriveRawSecretResponse, i32>,
313                fidl::encoding::DefaultFuchsiaResourceDialect,
314                0x605392dccdef79d4,
315            >(_buf?)?;
316            Ok(_response.map(|x| x.secret))
317        }
318        self.client
319            .send_query_and_decode::<DeviceDeriveRawSecretRequest, DeviceDeriveRawSecretResult>(
320                (wrapped_key,),
321                0x605392dccdef79d4,
322                fidl::encoding::DynamicFlags::empty(),
323                _decode,
324            )
325    }
326}
327
328pub struct DeviceEventStream {
329    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
330}
331
332impl std::marker::Unpin for DeviceEventStream {}
333
334impl futures::stream::FusedStream for DeviceEventStream {
335    fn is_terminated(&self) -> bool {
336        self.event_receiver.is_terminated()
337    }
338}
339
340impl futures::Stream for DeviceEventStream {
341    type Item = Result<DeviceEvent, 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(DeviceEvent::decode(buf))),
352            None => std::task::Poll::Ready(None),
353        }
354    }
355}
356
357#[derive(Debug)]
358pub enum DeviceEvent {}
359
360impl DeviceEvent {
361    /// Decodes a message buffer as a [`DeviceEvent`].
362    fn decode(
363        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
364    ) -> Result<DeviceEvent, 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: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
372            }),
373        }
374    }
375}
376
377/// A Stream of incoming requests for fuchsia.hardware.inlineencryption/Device.
378pub struct DeviceRequestStream {
379    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
380    is_terminated: bool,
381}
382
383impl std::marker::Unpin for DeviceRequestStream {}
384
385impl futures::stream::FusedStream for DeviceRequestStream {
386    fn is_terminated(&self) -> bool {
387        self.is_terminated
388    }
389}
390
391impl fidl::endpoints::RequestStream for DeviceRequestStream {
392    type Protocol = DeviceMarker;
393    type ControlHandle = DeviceControlHandle;
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        DeviceControlHandle { 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 DeviceRequestStream {
419    type Item = Result<DeviceRequest, 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 DeviceRequestStream 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                    0x30401dc60fc47cd0 => {
454                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
455                        let mut req = fidl::new_empty!(
456                            DeviceProgramKeyRequest,
457                            fidl::encoding::DefaultFuchsiaResourceDialect
458                        );
459                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceProgramKeyRequest>(&header, _body_bytes, handles, &mut req)?;
460                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
461                        Ok(DeviceRequest::ProgramKey {
462                            wrapped_key: req.wrapped_key,
463                            data_unit_size: req.data_unit_size,
464
465                            responder: DeviceProgramKeyResponder {
466                                control_handle: std::mem::ManuallyDrop::new(control_handle),
467                                tx_id: header.tx_id,
468                            },
469                        })
470                    }
471                    0x605392dccdef79d4 => {
472                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
473                        let mut req = fidl::new_empty!(
474                            DeviceDeriveRawSecretRequest,
475                            fidl::encoding::DefaultFuchsiaResourceDialect
476                        );
477                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceDeriveRawSecretRequest>(&header, _body_bytes, handles, &mut req)?;
478                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
479                        Ok(DeviceRequest::DeriveRawSecret {
480                            wrapped_key: req.wrapped_key,
481
482                            responder: DeviceDeriveRawSecretResponder {
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                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
492                    }),
493                }))
494            },
495        )
496    }
497}
498
499#[derive(Debug)]
500pub enum DeviceRequest {
501    /// Programs the ephemerally wrapped `wrapped_key` into the inline encryption hardware in the
502    /// next available `slot`. All slots programmed via the connection this method is called on
503    /// will be evicted once the connection is dropped. It is not possible to evict individual keys
504    /// (not for any technical reasons; a need for this has not yet arisen). `wrapped_key` must be
505    /// a key wrapped by the inline encryption hardware (in the same session/boot) via a separate
506    /// mechanism to this protocol.
507    ///
508    /// Returns
509    /// - ZX_ERR_NO_RESOURCES if there are no available key slots.
510    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
511    ///   fails authentication (e.g. wrapped_key is from a previous boot).
512    /// - ZX_ERR_TIMED_OUT if the operation times out.
513    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
514    ProgramKey { wrapped_key: Vec<u8>, data_unit_size: u32, responder: DeviceProgramKeyResponder },
515    /// Derives a raw software secret from the ephemerally wrapped `wrapped_key`. `wrapped_key`
516    /// must be a key wrapped by the inline encryption hardware (in the same session/boot) via a
517    /// separate mechanism to this protocol. The returned secret can be used for non-inline
518    /// cryptographic operations e.g. it can be used for encrypting filesystem metadata not covered
519    /// by inline encryption.
520    /// Returns
521    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
522    ///   fails authentication (e.g. wrapped_key is from a previous boot).
523    /// - ZX_ERR_TIMED_OUT if the operation times out.
524    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
525    DeriveRawSecret { wrapped_key: Vec<u8>, responder: DeviceDeriveRawSecretResponder },
526}
527
528impl DeviceRequest {
529    #[allow(irrefutable_let_patterns)]
530    pub fn into_program_key(self) -> Option<(Vec<u8>, u32, DeviceProgramKeyResponder)> {
531        if let DeviceRequest::ProgramKey { wrapped_key, data_unit_size, responder } = self {
532            Some((wrapped_key, data_unit_size, responder))
533        } else {
534            None
535        }
536    }
537
538    #[allow(irrefutable_let_patterns)]
539    pub fn into_derive_raw_secret(self) -> Option<(Vec<u8>, DeviceDeriveRawSecretResponder)> {
540        if let DeviceRequest::DeriveRawSecret { wrapped_key, responder } = self {
541            Some((wrapped_key, responder))
542        } else {
543            None
544        }
545    }
546
547    /// Name of the method defined in FIDL
548    pub fn method_name(&self) -> &'static str {
549        match *self {
550            DeviceRequest::ProgramKey { .. } => "program_key",
551            DeviceRequest::DeriveRawSecret { .. } => "derive_raw_secret",
552        }
553    }
554}
555
556#[derive(Debug, Clone)]
557pub struct DeviceControlHandle {
558    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
559}
560
561impl fidl::endpoints::ControlHandle for DeviceControlHandle {
562    fn shutdown(&self) {
563        self.inner.shutdown()
564    }
565
566    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
567        self.inner.shutdown_with_epitaph(status)
568    }
569
570    fn is_closed(&self) -> bool {
571        self.inner.channel().is_closed()
572    }
573    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
574        self.inner.channel().on_closed()
575    }
576
577    #[cfg(target_os = "fuchsia")]
578    fn signal_peer(
579        &self,
580        clear_mask: zx::Signals,
581        set_mask: zx::Signals,
582    ) -> Result<(), zx_status::Status> {
583        use fidl::Peered;
584        self.inner.channel().signal_peer(clear_mask, set_mask)
585    }
586}
587
588impl DeviceControlHandle {}
589
590#[must_use = "FIDL methods require a response to be sent"]
591#[derive(Debug)]
592pub struct DeviceProgramKeyResponder {
593    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
594    tx_id: u32,
595}
596
597/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
598/// if the responder is dropped without sending a response, so that the client
599/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
600impl std::ops::Drop for DeviceProgramKeyResponder {
601    fn drop(&mut self) {
602        self.control_handle.shutdown();
603        // Safety: drops once, never accessed again
604        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
605    }
606}
607
608impl fidl::endpoints::Responder for DeviceProgramKeyResponder {
609    type ControlHandle = DeviceControlHandle;
610
611    fn control_handle(&self) -> &DeviceControlHandle {
612        &self.control_handle
613    }
614
615    fn drop_without_shutdown(mut self) {
616        // Safety: drops once, never accessed again due to mem::forget
617        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
618        // Prevent Drop from running (which would shut down the channel)
619        std::mem::forget(self);
620    }
621}
622
623impl DeviceProgramKeyResponder {
624    /// Sends a response to the FIDL transaction.
625    ///
626    /// Sets the channel to shutdown if an error occurs.
627    pub fn send(self, mut result: Result<u8, i32>) -> Result<(), fidl::Error> {
628        let _result = self.send_raw(result);
629        if _result.is_err() {
630            self.control_handle.shutdown();
631        }
632        self.drop_without_shutdown();
633        _result
634    }
635
636    /// Similar to "send" but does not shutdown the channel if an error occurs.
637    pub fn send_no_shutdown_on_err(self, mut result: Result<u8, i32>) -> Result<(), fidl::Error> {
638        let _result = self.send_raw(result);
639        self.drop_without_shutdown();
640        _result
641    }
642
643    fn send_raw(&self, mut result: Result<u8, i32>) -> Result<(), fidl::Error> {
644        self.control_handle.inner.send::<fidl::encoding::ResultType<DeviceProgramKeyResponse, i32>>(
645            result.map(|slot| (slot,)),
646            self.tx_id,
647            0x30401dc60fc47cd0,
648            fidl::encoding::DynamicFlags::empty(),
649        )
650    }
651}
652
653#[must_use = "FIDL methods require a response to be sent"]
654#[derive(Debug)]
655pub struct DeviceDeriveRawSecretResponder {
656    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
657    tx_id: u32,
658}
659
660/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
661/// if the responder is dropped without sending a response, so that the client
662/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
663impl std::ops::Drop for DeviceDeriveRawSecretResponder {
664    fn drop(&mut self) {
665        self.control_handle.shutdown();
666        // Safety: drops once, never accessed again
667        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
668    }
669}
670
671impl fidl::endpoints::Responder for DeviceDeriveRawSecretResponder {
672    type ControlHandle = DeviceControlHandle;
673
674    fn control_handle(&self) -> &DeviceControlHandle {
675        &self.control_handle
676    }
677
678    fn drop_without_shutdown(mut self) {
679        // Safety: drops once, never accessed again due to mem::forget
680        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
681        // Prevent Drop from running (which would shut down the channel)
682        std::mem::forget(self);
683    }
684}
685
686impl DeviceDeriveRawSecretResponder {
687    /// Sends a response to the FIDL transaction.
688    ///
689    /// Sets the channel to shutdown if an error occurs.
690    pub fn send(self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
691        let _result = self.send_raw(result);
692        if _result.is_err() {
693            self.control_handle.shutdown();
694        }
695        self.drop_without_shutdown();
696        _result
697    }
698
699    /// Similar to "send" but does not shutdown the channel if an error occurs.
700    pub fn send_no_shutdown_on_err(
701        self,
702        mut result: Result<&[u8], i32>,
703    ) -> Result<(), fidl::Error> {
704        let _result = self.send_raw(result);
705        self.drop_without_shutdown();
706        _result
707    }
708
709    fn send_raw(&self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
710        self.control_handle
711            .inner
712            .send::<fidl::encoding::ResultType<DeviceDeriveRawSecretResponse, i32>>(
713                result.map(|secret| (secret,)),
714                self.tx_id,
715                0x605392dccdef79d4,
716                fidl::encoding::DynamicFlags::empty(),
717            )
718    }
719}
720
721#[cfg(feature = "driver")]
722#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
723pub struct DriverDeviceMarker;
724
725#[cfg(feature = "driver")]
726impl fidl_driver::endpoints::DriverProtocolMarker for DriverDeviceMarker {
727    const DEBUG_NAME: &'static str = "fuchsia.hardware.inlineencryption.DriverDevice";
728}
729
730/// A driver transport variant of the `Device` protocol.
731
732#[cfg(feature = "driver")]
733#[derive(Debug)]
734pub enum DriverDeviceRequest {
735    /// Programs the ephemerally wrapped `wrapped_key` into the inline encryption hardware in the
736    /// next available `slot`. All slots programmed via the connection this method is called on
737    /// will be evicted once the connection is dropped. It is not possible to evict individual keys
738    /// (not for any technical reasons; a need for this has not yet arisen). `wrapped_key` must be
739    /// a key wrapped by the inline encryption hardware (in the same session/boot) via a separate
740    /// mechanism to this protocol.
741    ///
742    /// Returns
743    /// - ZX_ERR_NO_RESOURCES if there are no available key slots.
744    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
745    ///   fails authentication (e.g. wrapped_key is from a previous boot).
746    /// - ZX_ERR_TIMED_OUT if the operation times out.
747    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
748    ProgramKey {
749        wrapped_key: Vec<u8>,
750        data_unit_size: u32,
751        responder: DriverDeviceProgramKeyResponder,
752    },
753    /// Derives a raw software secret from the ephemerally wrapped `wrapped_key`. `wrapped_key`
754    /// must be a key wrapped by the inline encryption hardware (in the same session/boot) via a
755    /// separate mechanism to this protocol. The returned secret can be used for non-inline
756    /// cryptographic operations e.g. it can be used for encrypting filesystem metadata not covered
757    /// by inline encryption.
758    /// Returns
759    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
760    ///   fails authentication (e.g. wrapped_key is from a previous boot).
761    /// - ZX_ERR_TIMED_OUT if the operation times out.
762    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
763    DeriveRawSecret { wrapped_key: Vec<u8>, responder: DriverDeviceDeriveRawSecretResponder },
764}
765
766#[cfg(feature = "driver")]
767impl DriverDeviceRequest {
768    #[allow(irrefutable_let_patterns)]
769    pub fn into_program_key(self) -> Option<(Vec<u8>, u32, DriverDeviceProgramKeyResponder)> {
770        if let DriverDeviceRequest::ProgramKey { wrapped_key, data_unit_size, responder } = self {
771            Some((wrapped_key, data_unit_size, responder))
772        } else {
773            None
774        }
775    }
776
777    #[allow(irrefutable_let_patterns)]
778    pub fn into_derive_raw_secret(self) -> Option<(Vec<u8>, DriverDeviceDeriveRawSecretResponder)> {
779        if let DriverDeviceRequest::DeriveRawSecret { wrapped_key, responder } = self {
780            Some((wrapped_key, responder))
781        } else {
782            None
783        }
784    }
785
786    pub fn new_program_key(self, wrapped_key: Vec<u8>, data_unit_size: u32, tx_id: u32) -> Self {
787        Self::ProgramKey {
788            wrapped_key,
789            data_unit_size,
790            responder: DriverDeviceProgramKeyResponder { tx_id },
791        }
792    }
793
794    pub fn new_derive_raw_secret(self, wrapped_key: Vec<u8>, tx_id: u32) -> Self {
795        Self::DeriveRawSecret {
796            wrapped_key,
797            responder: DriverDeviceDeriveRawSecretResponder { tx_id },
798        }
799    }
800
801    pub fn r#program_key_as_message(
802        arena: fdf::Arena,
803        mut wrapped_key: &[u8],
804        mut data_unit_size: u32,
805        tx_id: u32,
806    ) -> Result<fdf::Message<[u8]>, fidl::Error> {
807        let ordinal = 0x30401dc60fc47cd0;
808        let dynamic_flags = fidl::encoding::DynamicFlags::empty();
809        let body = (wrapped_key, data_unit_size);
810        let msg = fidl::encoding::TransactionMessage {
811            header: fidl::encoding::TransactionHeader::new(tx_id, ordinal, dynamic_flags),
812            body,
813        };
814        fidl::encoding::with_tls_encoded::<
815            fidl::encoding::TransactionMessageType<DeviceProgramKeyRequest>,
816            fidl::encoding::DefaultFuchsiaResourceDialect,
817            fdf::Message<[u8]>,
818        >(msg, |bytes, mut handles| {
819            let handles = arena.insert_from_iter(
820                std::mem::take(handles)
821                    .into_iter()
822                    .map(fidl_driver::encoding::mixed_from_handle_disposition),
823            );
824            Ok(fdf::Message::new(&arena, Some(arena.insert_slice(bytes)), Some(handles)))
825        })
826    }
827
828    pub fn r#derive_raw_secret_as_message(
829        arena: fdf::Arena,
830        mut wrapped_key: &[u8],
831        tx_id: u32,
832    ) -> Result<fdf::Message<[u8]>, fidl::Error> {
833        let ordinal = 0x605392dccdef79d4;
834        let dynamic_flags = fidl::encoding::DynamicFlags::empty();
835        let body = (wrapped_key,);
836        let msg = fidl::encoding::TransactionMessage {
837            header: fidl::encoding::TransactionHeader::new(tx_id, ordinal, dynamic_flags),
838            body,
839        };
840        fidl::encoding::with_tls_encoded::<
841            fidl::encoding::TransactionMessageType<DeviceDeriveRawSecretRequest>,
842            fidl::encoding::DefaultFuchsiaResourceDialect,
843            fdf::Message<[u8]>,
844        >(msg, |bytes, mut handles| {
845            let handles = arena.insert_from_iter(
846                std::mem::take(handles)
847                    .into_iter()
848                    .map(fidl_driver::encoding::mixed_from_handle_disposition),
849            );
850            Ok(fdf::Message::new(&arena, Some(arena.insert_slice(bytes)), Some(handles)))
851        })
852    }
853
854    #[allow(irrefutable_let_patterns)]
855    pub fn read_from(bytes: &[u8], _handles: &mut [zx::HandleInfo]) -> Result<Self, fidl::Error> {
856        let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
857
858        match header.ordinal {
859            0x30401dc60fc47cd0 => {
860                header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
861                let mut req = fidl::new_empty!(
862                    DeviceProgramKeyRequest,
863                    fidl::encoding::DefaultFuchsiaResourceDialect
864                );
865                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceProgramKeyRequest>(&header, _body_bytes, _handles, &mut req)?;
866                Ok(DriverDeviceRequest::ProgramKey {
867                    wrapped_key: req.wrapped_key,
868                    data_unit_size: req.data_unit_size,
869
870                    responder: DriverDeviceProgramKeyResponder { tx_id: header.tx_id },
871                })
872            }
873            0x605392dccdef79d4 => {
874                header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
875                let mut req = fidl::new_empty!(
876                    DeviceDeriveRawSecretRequest,
877                    fidl::encoding::DefaultFuchsiaResourceDialect
878                );
879                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceDeriveRawSecretRequest>(&header, _body_bytes, _handles, &mut req)?;
880                Ok(DriverDeviceRequest::DeriveRawSecret {
881                    wrapped_key: req.wrapped_key,
882
883                    responder: DriverDeviceDeriveRawSecretResponder { tx_id: header.tx_id },
884                })
885            }
886            _ => Err(fidl::Error::UnknownOrdinal {
887                ordinal: header.ordinal,
888                protocol_name:
889                    <DriverDeviceMarker as fidl_driver::endpoints::DriverProtocolMarker>::DEBUG_NAME,
890            }),
891        }
892    }
893
894    pub fn read_from_message(
895        mut message: fdf::Message<[u8]>,
896    ) -> Result<(fdf::Arena, Self), fidl::Error> {
897        let (arena, Some(body), handles) = message.take_arena_boxes() else {
898            return Err(fidl::Error::Invalid);
899        };
900        let mut handles =
901            handles
902                .map(|handles| {
903                    arena.try_insert_from_iter(handles.into_iter().map(|handle| unsafe {
904                        fidl_driver::encoding::mixed_into_handle_info(handle)
905                    }))
906                })
907                .transpose();
908        let res = match handles {
909            Ok(ref mut handles) => {
910                Self::read_from(&*body, handles.as_deref_mut().unwrap_or(&mut []))?
911            }
912            Err(_) => return Err(fidl::Error::Invalid),
913        };
914        std::mem::drop((body, handles));
915        Ok((message.take_arena(), res))
916    }
917
918    /// Name of the method defined in FIDL
919    pub fn method_name(&self) -> &'static str {
920        match *self {
921            DriverDeviceRequest::ProgramKey { .. } => "program_key",
922            DriverDeviceRequest::DeriveRawSecret { .. } => "derive_raw_secret",
923        }
924    }
925}
926
927/// Like [`DriverDeviceRequest::read_from_message`] except it drops the [`Arena`].
928#[cfg(feature = "driver")]
929impl std::convert::TryFrom<fdf::Message<[u8]>> for DriverDeviceRequest {
930    type Error = fidl::Error;
931    fn try_from(msg: fdf::Message<[u8]>) -> Result<DriverDeviceRequest, fidl::Error> {
932        Ok(DriverDeviceRequest::read_from_message(msg)?.1)
933    }
934}
935
936#[must_use = "FIDL methods require a response to be sent"]
937#[cfg(feature = "driver")]
938#[derive(Debug)]
939pub struct DriverDeviceProgramKeyResponder {
940    tx_id: u32,
941}
942
943#[cfg(feature = "driver")]
944impl DriverDeviceProgramKeyResponder {
945    pub fn send_response(
946        &self,
947        server_handle: &fdf::Channel<[u8]>,
948        mut result: Result<u8, i32>,
949    ) -> Result<(), fidl::Error> {
950        let msg = fidl::encoding::TransactionMessage {
951            header: fidl::encoding::TransactionHeader::new(
952                self.tx_id,
953                0x30401dc60fc47cd0,
954                fidl::encoding::DynamicFlags::empty(),
955            ),
956            body: result.map(|slot| (slot,)),
957        };
958        fidl::encoding::with_tls_encoded::<
959            fidl::encoding::TransactionMessageType<
960                fidl::encoding::ResultType<DeviceProgramKeyResponse, i32>,
961            >,
962            fidl::encoding::DefaultFuchsiaResourceDialect,
963            (),
964        >(msg, |body, _handles| {
965            server_handle
966                .write_with_data(fdf::Arena::new(), |arena| arena.insert_slice(&body))
967                .unwrap();
968            Ok(())
969        })
970    }
971}
972
973#[must_use = "FIDL methods require a response to be sent"]
974#[cfg(feature = "driver")]
975#[derive(Debug)]
976pub struct DriverDeviceDeriveRawSecretResponder {
977    tx_id: u32,
978}
979
980#[cfg(feature = "driver")]
981impl DriverDeviceDeriveRawSecretResponder {
982    pub fn send_response(
983        &self,
984        server_handle: &fdf::Channel<[u8]>,
985        mut result: Result<&[u8], i32>,
986    ) -> Result<(), fidl::Error> {
987        let msg = fidl::encoding::TransactionMessage {
988            header: fidl::encoding::TransactionHeader::new(
989                self.tx_id,
990                0x605392dccdef79d4,
991                fidl::encoding::DynamicFlags::empty(),
992            ),
993            body: result.map(|secret| (secret,)),
994        };
995        fidl::encoding::with_tls_encoded::<
996            fidl::encoding::TransactionMessageType<
997                fidl::encoding::ResultType<DeviceDeriveRawSecretResponse, i32>,
998            >,
999            fidl::encoding::DefaultFuchsiaResourceDialect,
1000            (),
1001        >(msg, |body, _handles| {
1002            server_handle
1003                .write_with_data(fdf::Arena::new(), |arena| arena.insert_slice(&body))
1004                .unwrap();
1005            Ok(())
1006        })
1007    }
1008}
1009
1010mod internal {
1011    use super::*;
1012
1013    impl fidl::encoding::ResourceTypeMarker for DeviceDeriveRawSecretRequest {
1014        type Borrowed<'a> = &'a mut Self;
1015        fn take_or_borrow<'a>(
1016            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1017        ) -> Self::Borrowed<'a> {
1018            value
1019        }
1020    }
1021
1022    unsafe impl fidl::encoding::TypeMarker for DeviceDeriveRawSecretRequest {
1023        type Owned = Self;
1024
1025        #[inline(always)]
1026        fn inline_align(_context: fidl::encoding::Context) -> usize {
1027            8
1028        }
1029
1030        #[inline(always)]
1031        fn inline_size(_context: fidl::encoding::Context) -> usize {
1032            16
1033        }
1034    }
1035
1036    unsafe impl
1037        fidl::encoding::Encode<
1038            DeviceDeriveRawSecretRequest,
1039            fidl::encoding::DefaultFuchsiaResourceDialect,
1040        > for &mut DeviceDeriveRawSecretRequest
1041    {
1042        #[inline]
1043        unsafe fn encode(
1044            self,
1045            encoder: &mut fidl::encoding::Encoder<
1046                '_,
1047                fidl::encoding::DefaultFuchsiaResourceDialect,
1048            >,
1049            offset: usize,
1050            _depth: fidl::encoding::Depth,
1051        ) -> fidl::Result<()> {
1052            encoder.debug_check_bounds::<DeviceDeriveRawSecretRequest>(offset);
1053            // Delegate to tuple encoding.
1054            fidl::encoding::Encode::<
1055                DeviceDeriveRawSecretRequest,
1056                fidl::encoding::DefaultFuchsiaResourceDialect,
1057            >::encode(
1058                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
1059                    &self.wrapped_key,
1060                ),),
1061                encoder,
1062                offset,
1063                _depth,
1064            )
1065        }
1066    }
1067    unsafe impl<
1068        T0: fidl::encoding::Encode<
1069                fidl::encoding::UnboundedVector<u8>,
1070                fidl::encoding::DefaultFuchsiaResourceDialect,
1071            >,
1072    >
1073        fidl::encoding::Encode<
1074            DeviceDeriveRawSecretRequest,
1075            fidl::encoding::DefaultFuchsiaResourceDialect,
1076        > for (T0,)
1077    {
1078        #[inline]
1079        unsafe fn encode(
1080            self,
1081            encoder: &mut fidl::encoding::Encoder<
1082                '_,
1083                fidl::encoding::DefaultFuchsiaResourceDialect,
1084            >,
1085            offset: usize,
1086            depth: fidl::encoding::Depth,
1087        ) -> fidl::Result<()> {
1088            encoder.debug_check_bounds::<DeviceDeriveRawSecretRequest>(offset);
1089            // Zero out padding regions. There's no need to apply masks
1090            // because the unmasked parts will be overwritten by fields.
1091            // Write the fields.
1092            self.0.encode(encoder, offset + 0, depth)?;
1093            Ok(())
1094        }
1095    }
1096
1097    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1098        for DeviceDeriveRawSecretRequest
1099    {
1100        #[inline(always)]
1101        fn new_empty() -> Self {
1102            Self {
1103                wrapped_key: fidl::new_empty!(
1104                    fidl::encoding::UnboundedVector<u8>,
1105                    fidl::encoding::DefaultFuchsiaResourceDialect
1106                ),
1107            }
1108        }
1109
1110        #[inline]
1111        unsafe fn decode(
1112            &mut self,
1113            decoder: &mut fidl::encoding::Decoder<
1114                '_,
1115                fidl::encoding::DefaultFuchsiaResourceDialect,
1116            >,
1117            offset: usize,
1118            _depth: fidl::encoding::Depth,
1119        ) -> fidl::Result<()> {
1120            decoder.debug_check_bounds::<Self>(offset);
1121            // Verify that padding bytes are zero.
1122            fidl::decode!(
1123                fidl::encoding::UnboundedVector<u8>,
1124                fidl::encoding::DefaultFuchsiaResourceDialect,
1125                &mut self.wrapped_key,
1126                decoder,
1127                offset + 0,
1128                _depth
1129            )?;
1130            Ok(())
1131        }
1132    }
1133
1134    impl fidl::encoding::ResourceTypeMarker for DeviceProgramKeyRequest {
1135        type Borrowed<'a> = &'a mut Self;
1136        fn take_or_borrow<'a>(
1137            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1138        ) -> Self::Borrowed<'a> {
1139            value
1140        }
1141    }
1142
1143    unsafe impl fidl::encoding::TypeMarker for DeviceProgramKeyRequest {
1144        type Owned = Self;
1145
1146        #[inline(always)]
1147        fn inline_align(_context: fidl::encoding::Context) -> usize {
1148            8
1149        }
1150
1151        #[inline(always)]
1152        fn inline_size(_context: fidl::encoding::Context) -> usize {
1153            24
1154        }
1155    }
1156
1157    unsafe impl
1158        fidl::encoding::Encode<
1159            DeviceProgramKeyRequest,
1160            fidl::encoding::DefaultFuchsiaResourceDialect,
1161        > for &mut DeviceProgramKeyRequest
1162    {
1163        #[inline]
1164        unsafe fn encode(
1165            self,
1166            encoder: &mut fidl::encoding::Encoder<
1167                '_,
1168                fidl::encoding::DefaultFuchsiaResourceDialect,
1169            >,
1170            offset: usize,
1171            _depth: fidl::encoding::Depth,
1172        ) -> fidl::Result<()> {
1173            encoder.debug_check_bounds::<DeviceProgramKeyRequest>(offset);
1174            // Delegate to tuple encoding.
1175            fidl::encoding::Encode::<DeviceProgramKeyRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1176                (
1177                    <fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(&self.wrapped_key),
1178                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.data_unit_size),
1179                ),
1180                encoder, offset, _depth
1181            )
1182        }
1183    }
1184    unsafe impl<
1185        T0: fidl::encoding::Encode<
1186                fidl::encoding::UnboundedVector<u8>,
1187                fidl::encoding::DefaultFuchsiaResourceDialect,
1188            >,
1189        T1: fidl::encoding::Encode<u32, fidl::encoding::DefaultFuchsiaResourceDialect>,
1190    >
1191        fidl::encoding::Encode<
1192            DeviceProgramKeyRequest,
1193            fidl::encoding::DefaultFuchsiaResourceDialect,
1194        > for (T0, T1)
1195    {
1196        #[inline]
1197        unsafe fn encode(
1198            self,
1199            encoder: &mut fidl::encoding::Encoder<
1200                '_,
1201                fidl::encoding::DefaultFuchsiaResourceDialect,
1202            >,
1203            offset: usize,
1204            depth: fidl::encoding::Depth,
1205        ) -> fidl::Result<()> {
1206            encoder.debug_check_bounds::<DeviceProgramKeyRequest>(offset);
1207            // Zero out padding regions. There's no need to apply masks
1208            // because the unmasked parts will be overwritten by fields.
1209            unsafe {
1210                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1211                (ptr as *mut u64).write_unaligned(0);
1212            }
1213            // Write the fields.
1214            self.0.encode(encoder, offset + 0, depth)?;
1215            self.1.encode(encoder, offset + 16, depth)?;
1216            Ok(())
1217        }
1218    }
1219
1220    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1221        for DeviceProgramKeyRequest
1222    {
1223        #[inline(always)]
1224        fn new_empty() -> Self {
1225            Self {
1226                wrapped_key: fidl::new_empty!(
1227                    fidl::encoding::UnboundedVector<u8>,
1228                    fidl::encoding::DefaultFuchsiaResourceDialect
1229                ),
1230                data_unit_size: fidl::new_empty!(
1231                    u32,
1232                    fidl::encoding::DefaultFuchsiaResourceDialect
1233                ),
1234            }
1235        }
1236
1237        #[inline]
1238        unsafe fn decode(
1239            &mut self,
1240            decoder: &mut fidl::encoding::Decoder<
1241                '_,
1242                fidl::encoding::DefaultFuchsiaResourceDialect,
1243            >,
1244            offset: usize,
1245            _depth: fidl::encoding::Depth,
1246        ) -> fidl::Result<()> {
1247            decoder.debug_check_bounds::<Self>(offset);
1248            // Verify that padding bytes are zero.
1249            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1250            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1251            let mask = 0xffffffff00000000u64;
1252            let maskedval = padval & mask;
1253            if maskedval != 0 {
1254                return Err(fidl::Error::NonZeroPadding {
1255                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1256                });
1257            }
1258            fidl::decode!(
1259                fidl::encoding::UnboundedVector<u8>,
1260                fidl::encoding::DefaultFuchsiaResourceDialect,
1261                &mut self.wrapped_key,
1262                decoder,
1263                offset + 0,
1264                _depth
1265            )?;
1266            fidl::decode!(
1267                u32,
1268                fidl::encoding::DefaultFuchsiaResourceDialect,
1269                &mut self.data_unit_size,
1270                decoder,
1271                offset + 16,
1272                _depth
1273            )?;
1274            Ok(())
1275        }
1276    }
1277
1278    impl fidl::encoding::ResourceTypeMarker for DeviceDeriveRawSecretResponse {
1279        type Borrowed<'a> = &'a mut Self;
1280        fn take_or_borrow<'a>(
1281            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1282        ) -> Self::Borrowed<'a> {
1283            value
1284        }
1285    }
1286
1287    unsafe impl fidl::encoding::TypeMarker for DeviceDeriveRawSecretResponse {
1288        type Owned = Self;
1289
1290        #[inline(always)]
1291        fn inline_align(_context: fidl::encoding::Context) -> usize {
1292            8
1293        }
1294
1295        #[inline(always)]
1296        fn inline_size(_context: fidl::encoding::Context) -> usize {
1297            16
1298        }
1299    }
1300
1301    unsafe impl
1302        fidl::encoding::Encode<
1303            DeviceDeriveRawSecretResponse,
1304            fidl::encoding::DefaultFuchsiaResourceDialect,
1305        > for &mut DeviceDeriveRawSecretResponse
1306    {
1307        #[inline]
1308        unsafe fn encode(
1309            self,
1310            encoder: &mut fidl::encoding::Encoder<
1311                '_,
1312                fidl::encoding::DefaultFuchsiaResourceDialect,
1313            >,
1314            offset: usize,
1315            _depth: fidl::encoding::Depth,
1316        ) -> fidl::Result<()> {
1317            encoder.debug_check_bounds::<DeviceDeriveRawSecretResponse>(offset);
1318            // Delegate to tuple encoding.
1319            fidl::encoding::Encode::<
1320                DeviceDeriveRawSecretResponse,
1321                fidl::encoding::DefaultFuchsiaResourceDialect,
1322            >::encode(
1323                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
1324                    &self.secret,
1325                ),),
1326                encoder,
1327                offset,
1328                _depth,
1329            )
1330        }
1331    }
1332    unsafe impl<
1333        T0: fidl::encoding::Encode<
1334                fidl::encoding::UnboundedVector<u8>,
1335                fidl::encoding::DefaultFuchsiaResourceDialect,
1336            >,
1337    >
1338        fidl::encoding::Encode<
1339            DeviceDeriveRawSecretResponse,
1340            fidl::encoding::DefaultFuchsiaResourceDialect,
1341        > for (T0,)
1342    {
1343        #[inline]
1344        unsafe fn encode(
1345            self,
1346            encoder: &mut fidl::encoding::Encoder<
1347                '_,
1348                fidl::encoding::DefaultFuchsiaResourceDialect,
1349            >,
1350            offset: usize,
1351            depth: fidl::encoding::Depth,
1352        ) -> fidl::Result<()> {
1353            encoder.debug_check_bounds::<DeviceDeriveRawSecretResponse>(offset);
1354            // Zero out padding regions. There's no need to apply masks
1355            // because the unmasked parts will be overwritten by fields.
1356            // Write the fields.
1357            self.0.encode(encoder, offset + 0, depth)?;
1358            Ok(())
1359        }
1360    }
1361
1362    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1363        for DeviceDeriveRawSecretResponse
1364    {
1365        #[inline(always)]
1366        fn new_empty() -> Self {
1367            Self {
1368                secret: fidl::new_empty!(
1369                    fidl::encoding::UnboundedVector<u8>,
1370                    fidl::encoding::DefaultFuchsiaResourceDialect
1371                ),
1372            }
1373        }
1374
1375        #[inline]
1376        unsafe fn decode(
1377            &mut self,
1378            decoder: &mut fidl::encoding::Decoder<
1379                '_,
1380                fidl::encoding::DefaultFuchsiaResourceDialect,
1381            >,
1382            offset: usize,
1383            _depth: fidl::encoding::Depth,
1384        ) -> fidl::Result<()> {
1385            decoder.debug_check_bounds::<Self>(offset);
1386            // Verify that padding bytes are zero.
1387            fidl::decode!(
1388                fidl::encoding::UnboundedVector<u8>,
1389                fidl::encoding::DefaultFuchsiaResourceDialect,
1390                &mut self.secret,
1391                decoder,
1392                offset + 0,
1393                _depth
1394            )?;
1395            Ok(())
1396        }
1397    }
1398}