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 DeviceControlHandle {
562    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
563        self.inner.shutdown_with_epitaph(status.into())
564    }
565}
566
567impl fidl::endpoints::ControlHandle for DeviceControlHandle {
568    fn shutdown(&self) {
569        self.inner.shutdown()
570    }
571
572    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
573        self.inner.shutdown_with_epitaph(status)
574    }
575
576    fn is_closed(&self) -> bool {
577        self.inner.channel().is_closed()
578    }
579    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
580        self.inner.channel().on_closed()
581    }
582
583    #[cfg(target_os = "fuchsia")]
584    fn signal_peer(
585        &self,
586        clear_mask: zx::Signals,
587        set_mask: zx::Signals,
588    ) -> Result<(), zx_status::Status> {
589        use fidl::Peered;
590        self.inner.channel().signal_peer(clear_mask, set_mask)
591    }
592}
593
594impl DeviceControlHandle {}
595
596#[must_use = "FIDL methods require a response to be sent"]
597#[derive(Debug)]
598pub struct DeviceProgramKeyResponder {
599    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
600    tx_id: u32,
601}
602
603/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
604/// if the responder is dropped without sending a response, so that the client
605/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
606impl std::ops::Drop for DeviceProgramKeyResponder {
607    fn drop(&mut self) {
608        self.control_handle.shutdown();
609        // Safety: drops once, never accessed again
610        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
611    }
612}
613
614impl fidl::endpoints::Responder for DeviceProgramKeyResponder {
615    type ControlHandle = DeviceControlHandle;
616
617    fn control_handle(&self) -> &DeviceControlHandle {
618        &self.control_handle
619    }
620
621    fn drop_without_shutdown(mut self) {
622        // Safety: drops once, never accessed again due to mem::forget
623        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
624        // Prevent Drop from running (which would shut down the channel)
625        std::mem::forget(self);
626    }
627}
628
629impl DeviceProgramKeyResponder {
630    /// Sends a response to the FIDL transaction.
631    ///
632    /// Sets the channel to shutdown if an error occurs.
633    pub fn send(self, mut result: Result<u8, i32>) -> Result<(), fidl::Error> {
634        let _result = self.send_raw(result);
635        if _result.is_err() {
636            self.control_handle.shutdown();
637        }
638        self.drop_without_shutdown();
639        _result
640    }
641
642    /// Similar to "send" but does not shutdown the channel if an error occurs.
643    pub fn send_no_shutdown_on_err(self, mut result: Result<u8, i32>) -> Result<(), fidl::Error> {
644        let _result = self.send_raw(result);
645        self.drop_without_shutdown();
646        _result
647    }
648
649    fn send_raw(&self, mut result: Result<u8, i32>) -> Result<(), fidl::Error> {
650        self.control_handle.inner.send::<fidl::encoding::ResultType<DeviceProgramKeyResponse, i32>>(
651            result.map(|slot| (slot,)),
652            self.tx_id,
653            0x30401dc60fc47cd0,
654            fidl::encoding::DynamicFlags::empty(),
655        )
656    }
657}
658
659#[must_use = "FIDL methods require a response to be sent"]
660#[derive(Debug)]
661pub struct DeviceDeriveRawSecretResponder {
662    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
663    tx_id: u32,
664}
665
666/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
667/// if the responder is dropped without sending a response, so that the client
668/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
669impl std::ops::Drop for DeviceDeriveRawSecretResponder {
670    fn drop(&mut self) {
671        self.control_handle.shutdown();
672        // Safety: drops once, never accessed again
673        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
674    }
675}
676
677impl fidl::endpoints::Responder for DeviceDeriveRawSecretResponder {
678    type ControlHandle = DeviceControlHandle;
679
680    fn control_handle(&self) -> &DeviceControlHandle {
681        &self.control_handle
682    }
683
684    fn drop_without_shutdown(mut self) {
685        // Safety: drops once, never accessed again due to mem::forget
686        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
687        // Prevent Drop from running (which would shut down the channel)
688        std::mem::forget(self);
689    }
690}
691
692impl DeviceDeriveRawSecretResponder {
693    /// Sends a response to the FIDL transaction.
694    ///
695    /// Sets the channel to shutdown if an error occurs.
696    pub fn send(self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
697        let _result = self.send_raw(result);
698        if _result.is_err() {
699            self.control_handle.shutdown();
700        }
701        self.drop_without_shutdown();
702        _result
703    }
704
705    /// Similar to "send" but does not shutdown the channel if an error occurs.
706    pub fn send_no_shutdown_on_err(
707        self,
708        mut result: Result<&[u8], i32>,
709    ) -> Result<(), fidl::Error> {
710        let _result = self.send_raw(result);
711        self.drop_without_shutdown();
712        _result
713    }
714
715    fn send_raw(&self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
716        self.control_handle
717            .inner
718            .send::<fidl::encoding::ResultType<DeviceDeriveRawSecretResponse, i32>>(
719                result.map(|secret| (secret,)),
720                self.tx_id,
721                0x605392dccdef79d4,
722                fidl::encoding::DynamicFlags::empty(),
723            )
724    }
725}
726
727mod internal {
728    use super::*;
729
730    impl fidl::encoding::ResourceTypeMarker for DeviceDeriveRawSecretRequest {
731        type Borrowed<'a> = &'a mut Self;
732        fn take_or_borrow<'a>(
733            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
734        ) -> Self::Borrowed<'a> {
735            value
736        }
737    }
738
739    unsafe impl fidl::encoding::TypeMarker for DeviceDeriveRawSecretRequest {
740        type Owned = Self;
741
742        #[inline(always)]
743        fn inline_align(_context: fidl::encoding::Context) -> usize {
744            8
745        }
746
747        #[inline(always)]
748        fn inline_size(_context: fidl::encoding::Context) -> usize {
749            16
750        }
751    }
752
753    unsafe impl
754        fidl::encoding::Encode<
755            DeviceDeriveRawSecretRequest,
756            fidl::encoding::DefaultFuchsiaResourceDialect,
757        > for &mut DeviceDeriveRawSecretRequest
758    {
759        #[inline]
760        unsafe fn encode(
761            self,
762            encoder: &mut fidl::encoding::Encoder<
763                '_,
764                fidl::encoding::DefaultFuchsiaResourceDialect,
765            >,
766            offset: usize,
767            _depth: fidl::encoding::Depth,
768        ) -> fidl::Result<()> {
769            encoder.debug_check_bounds::<DeviceDeriveRawSecretRequest>(offset);
770            // Delegate to tuple encoding.
771            fidl::encoding::Encode::<
772                DeviceDeriveRawSecretRequest,
773                fidl::encoding::DefaultFuchsiaResourceDialect,
774            >::encode(
775                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
776                    &self.wrapped_key,
777                ),),
778                encoder,
779                offset,
780                _depth,
781            )
782        }
783    }
784    unsafe impl<
785        T0: fidl::encoding::Encode<
786                fidl::encoding::UnboundedVector<u8>,
787                fidl::encoding::DefaultFuchsiaResourceDialect,
788            >,
789    >
790        fidl::encoding::Encode<
791            DeviceDeriveRawSecretRequest,
792            fidl::encoding::DefaultFuchsiaResourceDialect,
793        > for (T0,)
794    {
795        #[inline]
796        unsafe fn encode(
797            self,
798            encoder: &mut fidl::encoding::Encoder<
799                '_,
800                fidl::encoding::DefaultFuchsiaResourceDialect,
801            >,
802            offset: usize,
803            depth: fidl::encoding::Depth,
804        ) -> fidl::Result<()> {
805            encoder.debug_check_bounds::<DeviceDeriveRawSecretRequest>(offset);
806            // Zero out padding regions. There's no need to apply masks
807            // because the unmasked parts will be overwritten by fields.
808            // Write the fields.
809            self.0.encode(encoder, offset + 0, depth)?;
810            Ok(())
811        }
812    }
813
814    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
815        for DeviceDeriveRawSecretRequest
816    {
817        #[inline(always)]
818        fn new_empty() -> Self {
819            Self {
820                wrapped_key: fidl::new_empty!(
821                    fidl::encoding::UnboundedVector<u8>,
822                    fidl::encoding::DefaultFuchsiaResourceDialect
823                ),
824            }
825        }
826
827        #[inline]
828        unsafe fn decode(
829            &mut self,
830            decoder: &mut fidl::encoding::Decoder<
831                '_,
832                fidl::encoding::DefaultFuchsiaResourceDialect,
833            >,
834            offset: usize,
835            _depth: fidl::encoding::Depth,
836        ) -> fidl::Result<()> {
837            decoder.debug_check_bounds::<Self>(offset);
838            // Verify that padding bytes are zero.
839            fidl::decode!(
840                fidl::encoding::UnboundedVector<u8>,
841                fidl::encoding::DefaultFuchsiaResourceDialect,
842                &mut self.wrapped_key,
843                decoder,
844                offset + 0,
845                _depth
846            )?;
847            Ok(())
848        }
849    }
850
851    impl fidl::encoding::ResourceTypeMarker for DeviceProgramKeyRequest {
852        type Borrowed<'a> = &'a mut Self;
853        fn take_or_borrow<'a>(
854            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
855        ) -> Self::Borrowed<'a> {
856            value
857        }
858    }
859
860    unsafe impl fidl::encoding::TypeMarker for DeviceProgramKeyRequest {
861        type Owned = Self;
862
863        #[inline(always)]
864        fn inline_align(_context: fidl::encoding::Context) -> usize {
865            8
866        }
867
868        #[inline(always)]
869        fn inline_size(_context: fidl::encoding::Context) -> usize {
870            24
871        }
872    }
873
874    unsafe impl
875        fidl::encoding::Encode<
876            DeviceProgramKeyRequest,
877            fidl::encoding::DefaultFuchsiaResourceDialect,
878        > for &mut DeviceProgramKeyRequest
879    {
880        #[inline]
881        unsafe fn encode(
882            self,
883            encoder: &mut fidl::encoding::Encoder<
884                '_,
885                fidl::encoding::DefaultFuchsiaResourceDialect,
886            >,
887            offset: usize,
888            _depth: fidl::encoding::Depth,
889        ) -> fidl::Result<()> {
890            encoder.debug_check_bounds::<DeviceProgramKeyRequest>(offset);
891            // Delegate to tuple encoding.
892            fidl::encoding::Encode::<DeviceProgramKeyRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
893                (
894                    <fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(&self.wrapped_key),
895                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.data_unit_size),
896                ),
897                encoder, offset, _depth
898            )
899        }
900    }
901    unsafe impl<
902        T0: fidl::encoding::Encode<
903                fidl::encoding::UnboundedVector<u8>,
904                fidl::encoding::DefaultFuchsiaResourceDialect,
905            >,
906        T1: fidl::encoding::Encode<u32, fidl::encoding::DefaultFuchsiaResourceDialect>,
907    >
908        fidl::encoding::Encode<
909            DeviceProgramKeyRequest,
910            fidl::encoding::DefaultFuchsiaResourceDialect,
911        > for (T0, T1)
912    {
913        #[inline]
914        unsafe fn encode(
915            self,
916            encoder: &mut fidl::encoding::Encoder<
917                '_,
918                fidl::encoding::DefaultFuchsiaResourceDialect,
919            >,
920            offset: usize,
921            depth: fidl::encoding::Depth,
922        ) -> fidl::Result<()> {
923            encoder.debug_check_bounds::<DeviceProgramKeyRequest>(offset);
924            // Zero out padding regions. There's no need to apply masks
925            // because the unmasked parts will be overwritten by fields.
926            unsafe {
927                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
928                (ptr as *mut u64).write_unaligned(0);
929            }
930            // Write the fields.
931            self.0.encode(encoder, offset + 0, depth)?;
932            self.1.encode(encoder, offset + 16, depth)?;
933            Ok(())
934        }
935    }
936
937    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
938        for DeviceProgramKeyRequest
939    {
940        #[inline(always)]
941        fn new_empty() -> Self {
942            Self {
943                wrapped_key: fidl::new_empty!(
944                    fidl::encoding::UnboundedVector<u8>,
945                    fidl::encoding::DefaultFuchsiaResourceDialect
946                ),
947                data_unit_size: fidl::new_empty!(
948                    u32,
949                    fidl::encoding::DefaultFuchsiaResourceDialect
950                ),
951            }
952        }
953
954        #[inline]
955        unsafe fn decode(
956            &mut self,
957            decoder: &mut fidl::encoding::Decoder<
958                '_,
959                fidl::encoding::DefaultFuchsiaResourceDialect,
960            >,
961            offset: usize,
962            _depth: fidl::encoding::Depth,
963        ) -> fidl::Result<()> {
964            decoder.debug_check_bounds::<Self>(offset);
965            // Verify that padding bytes are zero.
966            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
967            let padval = unsafe { (ptr as *const u64).read_unaligned() };
968            let mask = 0xffffffff00000000u64;
969            let maskedval = padval & mask;
970            if maskedval != 0 {
971                return Err(fidl::Error::NonZeroPadding {
972                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
973                });
974            }
975            fidl::decode!(
976                fidl::encoding::UnboundedVector<u8>,
977                fidl::encoding::DefaultFuchsiaResourceDialect,
978                &mut self.wrapped_key,
979                decoder,
980                offset + 0,
981                _depth
982            )?;
983            fidl::decode!(
984                u32,
985                fidl::encoding::DefaultFuchsiaResourceDialect,
986                &mut self.data_unit_size,
987                decoder,
988                offset + 16,
989                _depth
990            )?;
991            Ok(())
992        }
993    }
994
995    impl fidl::encoding::ResourceTypeMarker for DeviceDeriveRawSecretResponse {
996        type Borrowed<'a> = &'a mut Self;
997        fn take_or_borrow<'a>(
998            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
999        ) -> Self::Borrowed<'a> {
1000            value
1001        }
1002    }
1003
1004    unsafe impl fidl::encoding::TypeMarker for DeviceDeriveRawSecretResponse {
1005        type Owned = Self;
1006
1007        #[inline(always)]
1008        fn inline_align(_context: fidl::encoding::Context) -> usize {
1009            8
1010        }
1011
1012        #[inline(always)]
1013        fn inline_size(_context: fidl::encoding::Context) -> usize {
1014            16
1015        }
1016    }
1017
1018    unsafe impl
1019        fidl::encoding::Encode<
1020            DeviceDeriveRawSecretResponse,
1021            fidl::encoding::DefaultFuchsiaResourceDialect,
1022        > for &mut DeviceDeriveRawSecretResponse
1023    {
1024        #[inline]
1025        unsafe fn encode(
1026            self,
1027            encoder: &mut fidl::encoding::Encoder<
1028                '_,
1029                fidl::encoding::DefaultFuchsiaResourceDialect,
1030            >,
1031            offset: usize,
1032            _depth: fidl::encoding::Depth,
1033        ) -> fidl::Result<()> {
1034            encoder.debug_check_bounds::<DeviceDeriveRawSecretResponse>(offset);
1035            // Delegate to tuple encoding.
1036            fidl::encoding::Encode::<
1037                DeviceDeriveRawSecretResponse,
1038                fidl::encoding::DefaultFuchsiaResourceDialect,
1039            >::encode(
1040                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
1041                    &self.secret,
1042                ),),
1043                encoder,
1044                offset,
1045                _depth,
1046            )
1047        }
1048    }
1049    unsafe impl<
1050        T0: fidl::encoding::Encode<
1051                fidl::encoding::UnboundedVector<u8>,
1052                fidl::encoding::DefaultFuchsiaResourceDialect,
1053            >,
1054    >
1055        fidl::encoding::Encode<
1056            DeviceDeriveRawSecretResponse,
1057            fidl::encoding::DefaultFuchsiaResourceDialect,
1058        > for (T0,)
1059    {
1060        #[inline]
1061        unsafe fn encode(
1062            self,
1063            encoder: &mut fidl::encoding::Encoder<
1064                '_,
1065                fidl::encoding::DefaultFuchsiaResourceDialect,
1066            >,
1067            offset: usize,
1068            depth: fidl::encoding::Depth,
1069        ) -> fidl::Result<()> {
1070            encoder.debug_check_bounds::<DeviceDeriveRawSecretResponse>(offset);
1071            // Zero out padding regions. There's no need to apply masks
1072            // because the unmasked parts will be overwritten by fields.
1073            // Write the fields.
1074            self.0.encode(encoder, offset + 0, depth)?;
1075            Ok(())
1076        }
1077    }
1078
1079    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1080        for DeviceDeriveRawSecretResponse
1081    {
1082        #[inline(always)]
1083        fn new_empty() -> Self {
1084            Self {
1085                secret: fidl::new_empty!(
1086                    fidl::encoding::UnboundedVector<u8>,
1087                    fidl::encoding::DefaultFuchsiaResourceDialect
1088                ),
1089            }
1090        }
1091
1092        #[inline]
1093        unsafe fn decode(
1094            &mut self,
1095            decoder: &mut fidl::encoding::Decoder<
1096                '_,
1097                fidl::encoding::DefaultFuchsiaResourceDialect,
1098            >,
1099            offset: usize,
1100            _depth: fidl::encoding::Depth,
1101        ) -> fidl::Result<()> {
1102            decoder.debug_check_bounds::<Self>(offset);
1103            // Verify that padding bytes are zero.
1104            fidl::decode!(
1105                fidl::encoding::UnboundedVector<u8>,
1106                fidl::encoding::DefaultFuchsiaResourceDialect,
1107                &mut self.secret,
1108                decoder,
1109                offset + 0,
1110                _depth
1111            )?;
1112            Ok(())
1113        }
1114    }
1115}