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
721mod internal {
722    use super::*;
723
724    impl fidl::encoding::ResourceTypeMarker for DeviceDeriveRawSecretRequest {
725        type Borrowed<'a> = &'a mut Self;
726        fn take_or_borrow<'a>(
727            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
728        ) -> Self::Borrowed<'a> {
729            value
730        }
731    }
732
733    unsafe impl fidl::encoding::TypeMarker for DeviceDeriveRawSecretRequest {
734        type Owned = Self;
735
736        #[inline(always)]
737        fn inline_align(_context: fidl::encoding::Context) -> usize {
738            8
739        }
740
741        #[inline(always)]
742        fn inline_size(_context: fidl::encoding::Context) -> usize {
743            16
744        }
745    }
746
747    unsafe impl
748        fidl::encoding::Encode<
749            DeviceDeriveRawSecretRequest,
750            fidl::encoding::DefaultFuchsiaResourceDialect,
751        > for &mut DeviceDeriveRawSecretRequest
752    {
753        #[inline]
754        unsafe fn encode(
755            self,
756            encoder: &mut fidl::encoding::Encoder<
757                '_,
758                fidl::encoding::DefaultFuchsiaResourceDialect,
759            >,
760            offset: usize,
761            _depth: fidl::encoding::Depth,
762        ) -> fidl::Result<()> {
763            encoder.debug_check_bounds::<DeviceDeriveRawSecretRequest>(offset);
764            // Delegate to tuple encoding.
765            fidl::encoding::Encode::<
766                DeviceDeriveRawSecretRequest,
767                fidl::encoding::DefaultFuchsiaResourceDialect,
768            >::encode(
769                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
770                    &self.wrapped_key,
771                ),),
772                encoder,
773                offset,
774                _depth,
775            )
776        }
777    }
778    unsafe impl<
779        T0: fidl::encoding::Encode<
780                fidl::encoding::UnboundedVector<u8>,
781                fidl::encoding::DefaultFuchsiaResourceDialect,
782            >,
783    >
784        fidl::encoding::Encode<
785            DeviceDeriveRawSecretRequest,
786            fidl::encoding::DefaultFuchsiaResourceDialect,
787        > for (T0,)
788    {
789        #[inline]
790        unsafe fn encode(
791            self,
792            encoder: &mut fidl::encoding::Encoder<
793                '_,
794                fidl::encoding::DefaultFuchsiaResourceDialect,
795            >,
796            offset: usize,
797            depth: fidl::encoding::Depth,
798        ) -> fidl::Result<()> {
799            encoder.debug_check_bounds::<DeviceDeriveRawSecretRequest>(offset);
800            // Zero out padding regions. There's no need to apply masks
801            // because the unmasked parts will be overwritten by fields.
802            // Write the fields.
803            self.0.encode(encoder, offset + 0, depth)?;
804            Ok(())
805        }
806    }
807
808    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
809        for DeviceDeriveRawSecretRequest
810    {
811        #[inline(always)]
812        fn new_empty() -> Self {
813            Self {
814                wrapped_key: fidl::new_empty!(
815                    fidl::encoding::UnboundedVector<u8>,
816                    fidl::encoding::DefaultFuchsiaResourceDialect
817                ),
818            }
819        }
820
821        #[inline]
822        unsafe fn decode(
823            &mut self,
824            decoder: &mut fidl::encoding::Decoder<
825                '_,
826                fidl::encoding::DefaultFuchsiaResourceDialect,
827            >,
828            offset: usize,
829            _depth: fidl::encoding::Depth,
830        ) -> fidl::Result<()> {
831            decoder.debug_check_bounds::<Self>(offset);
832            // Verify that padding bytes are zero.
833            fidl::decode!(
834                fidl::encoding::UnboundedVector<u8>,
835                fidl::encoding::DefaultFuchsiaResourceDialect,
836                &mut self.wrapped_key,
837                decoder,
838                offset + 0,
839                _depth
840            )?;
841            Ok(())
842        }
843    }
844
845    impl fidl::encoding::ResourceTypeMarker for DeviceProgramKeyRequest {
846        type Borrowed<'a> = &'a mut Self;
847        fn take_or_borrow<'a>(
848            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
849        ) -> Self::Borrowed<'a> {
850            value
851        }
852    }
853
854    unsafe impl fidl::encoding::TypeMarker for DeviceProgramKeyRequest {
855        type Owned = Self;
856
857        #[inline(always)]
858        fn inline_align(_context: fidl::encoding::Context) -> usize {
859            8
860        }
861
862        #[inline(always)]
863        fn inline_size(_context: fidl::encoding::Context) -> usize {
864            24
865        }
866    }
867
868    unsafe impl
869        fidl::encoding::Encode<
870            DeviceProgramKeyRequest,
871            fidl::encoding::DefaultFuchsiaResourceDialect,
872        > for &mut DeviceProgramKeyRequest
873    {
874        #[inline]
875        unsafe fn encode(
876            self,
877            encoder: &mut fidl::encoding::Encoder<
878                '_,
879                fidl::encoding::DefaultFuchsiaResourceDialect,
880            >,
881            offset: usize,
882            _depth: fidl::encoding::Depth,
883        ) -> fidl::Result<()> {
884            encoder.debug_check_bounds::<DeviceProgramKeyRequest>(offset);
885            // Delegate to tuple encoding.
886            fidl::encoding::Encode::<DeviceProgramKeyRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
887                (
888                    <fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(&self.wrapped_key),
889                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.data_unit_size),
890                ),
891                encoder, offset, _depth
892            )
893        }
894    }
895    unsafe impl<
896        T0: fidl::encoding::Encode<
897                fidl::encoding::UnboundedVector<u8>,
898                fidl::encoding::DefaultFuchsiaResourceDialect,
899            >,
900        T1: fidl::encoding::Encode<u32, fidl::encoding::DefaultFuchsiaResourceDialect>,
901    >
902        fidl::encoding::Encode<
903            DeviceProgramKeyRequest,
904            fidl::encoding::DefaultFuchsiaResourceDialect,
905        > for (T0, T1)
906    {
907        #[inline]
908        unsafe fn encode(
909            self,
910            encoder: &mut fidl::encoding::Encoder<
911                '_,
912                fidl::encoding::DefaultFuchsiaResourceDialect,
913            >,
914            offset: usize,
915            depth: fidl::encoding::Depth,
916        ) -> fidl::Result<()> {
917            encoder.debug_check_bounds::<DeviceProgramKeyRequest>(offset);
918            // Zero out padding regions. There's no need to apply masks
919            // because the unmasked parts will be overwritten by fields.
920            unsafe {
921                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
922                (ptr as *mut u64).write_unaligned(0);
923            }
924            // Write the fields.
925            self.0.encode(encoder, offset + 0, depth)?;
926            self.1.encode(encoder, offset + 16, depth)?;
927            Ok(())
928        }
929    }
930
931    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
932        for DeviceProgramKeyRequest
933    {
934        #[inline(always)]
935        fn new_empty() -> Self {
936            Self {
937                wrapped_key: fidl::new_empty!(
938                    fidl::encoding::UnboundedVector<u8>,
939                    fidl::encoding::DefaultFuchsiaResourceDialect
940                ),
941                data_unit_size: fidl::new_empty!(
942                    u32,
943                    fidl::encoding::DefaultFuchsiaResourceDialect
944                ),
945            }
946        }
947
948        #[inline]
949        unsafe fn decode(
950            &mut self,
951            decoder: &mut fidl::encoding::Decoder<
952                '_,
953                fidl::encoding::DefaultFuchsiaResourceDialect,
954            >,
955            offset: usize,
956            _depth: fidl::encoding::Depth,
957        ) -> fidl::Result<()> {
958            decoder.debug_check_bounds::<Self>(offset);
959            // Verify that padding bytes are zero.
960            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
961            let padval = unsafe { (ptr as *const u64).read_unaligned() };
962            let mask = 0xffffffff00000000u64;
963            let maskedval = padval & mask;
964            if maskedval != 0 {
965                return Err(fidl::Error::NonZeroPadding {
966                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
967                });
968            }
969            fidl::decode!(
970                fidl::encoding::UnboundedVector<u8>,
971                fidl::encoding::DefaultFuchsiaResourceDialect,
972                &mut self.wrapped_key,
973                decoder,
974                offset + 0,
975                _depth
976            )?;
977            fidl::decode!(
978                u32,
979                fidl::encoding::DefaultFuchsiaResourceDialect,
980                &mut self.data_unit_size,
981                decoder,
982                offset + 16,
983                _depth
984            )?;
985            Ok(())
986        }
987    }
988
989    impl fidl::encoding::ResourceTypeMarker for DeviceDeriveRawSecretResponse {
990        type Borrowed<'a> = &'a mut Self;
991        fn take_or_borrow<'a>(
992            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
993        ) -> Self::Borrowed<'a> {
994            value
995        }
996    }
997
998    unsafe impl fidl::encoding::TypeMarker for DeviceDeriveRawSecretResponse {
999        type Owned = Self;
1000
1001        #[inline(always)]
1002        fn inline_align(_context: fidl::encoding::Context) -> usize {
1003            8
1004        }
1005
1006        #[inline(always)]
1007        fn inline_size(_context: fidl::encoding::Context) -> usize {
1008            16
1009        }
1010    }
1011
1012    unsafe impl
1013        fidl::encoding::Encode<
1014            DeviceDeriveRawSecretResponse,
1015            fidl::encoding::DefaultFuchsiaResourceDialect,
1016        > for &mut DeviceDeriveRawSecretResponse
1017    {
1018        #[inline]
1019        unsafe fn encode(
1020            self,
1021            encoder: &mut fidl::encoding::Encoder<
1022                '_,
1023                fidl::encoding::DefaultFuchsiaResourceDialect,
1024            >,
1025            offset: usize,
1026            _depth: fidl::encoding::Depth,
1027        ) -> fidl::Result<()> {
1028            encoder.debug_check_bounds::<DeviceDeriveRawSecretResponse>(offset);
1029            // Delegate to tuple encoding.
1030            fidl::encoding::Encode::<
1031                DeviceDeriveRawSecretResponse,
1032                fidl::encoding::DefaultFuchsiaResourceDialect,
1033            >::encode(
1034                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
1035                    &self.secret,
1036                ),),
1037                encoder,
1038                offset,
1039                _depth,
1040            )
1041        }
1042    }
1043    unsafe impl<
1044        T0: fidl::encoding::Encode<
1045                fidl::encoding::UnboundedVector<u8>,
1046                fidl::encoding::DefaultFuchsiaResourceDialect,
1047            >,
1048    >
1049        fidl::encoding::Encode<
1050            DeviceDeriveRawSecretResponse,
1051            fidl::encoding::DefaultFuchsiaResourceDialect,
1052        > for (T0,)
1053    {
1054        #[inline]
1055        unsafe fn encode(
1056            self,
1057            encoder: &mut fidl::encoding::Encoder<
1058                '_,
1059                fidl::encoding::DefaultFuchsiaResourceDialect,
1060            >,
1061            offset: usize,
1062            depth: fidl::encoding::Depth,
1063        ) -> fidl::Result<()> {
1064            encoder.debug_check_bounds::<DeviceDeriveRawSecretResponse>(offset);
1065            // Zero out padding regions. There's no need to apply masks
1066            // because the unmasked parts will be overwritten by fields.
1067            // Write the fields.
1068            self.0.encode(encoder, offset + 0, depth)?;
1069            Ok(())
1070        }
1071    }
1072
1073    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1074        for DeviceDeriveRawSecretResponse
1075    {
1076        #[inline(always)]
1077        fn new_empty() -> Self {
1078            Self {
1079                secret: fidl::new_empty!(
1080                    fidl::encoding::UnboundedVector<u8>,
1081                    fidl::encoding::DefaultFuchsiaResourceDialect
1082                ),
1083            }
1084        }
1085
1086        #[inline]
1087        unsafe fn decode(
1088            &mut self,
1089            decoder: &mut fidl::encoding::Decoder<
1090                '_,
1091                fidl::encoding::DefaultFuchsiaResourceDialect,
1092            >,
1093            offset: usize,
1094            _depth: fidl::encoding::Depth,
1095        ) -> fidl::Result<()> {
1096            decoder.debug_check_bounds::<Self>(offset);
1097            // Verify that padding bytes are zero.
1098            fidl::decode!(
1099                fidl::encoding::UnboundedVector<u8>,
1100                fidl::encoding::DefaultFuchsiaResourceDialect,
1101                &mut self.secret,
1102                decoder,
1103                offset + 0,
1104                _depth
1105            )?;
1106            Ok(())
1107        }
1108    }
1109}