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        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
94        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
95    }
96
97    pub fn into_channel(self) -> fidl::Channel {
98        self.client.into_channel()
99    }
100
101    /// Waits until an event arrives and returns it. It is safe for other
102    /// threads to make concurrent requests while waiting for an event.
103    pub fn wait_for_event(
104        &self,
105        deadline: zx::MonotonicInstant,
106    ) -> Result<DeviceEvent, fidl::Error> {
107        DeviceEvent::decode(self.client.wait_for_event(deadline)?)
108    }
109
110    /// Programs the ephemerally wrapped `wrapped_key` into the inline encryption hardware in the
111    /// next available `slot`. All slots programmed via the connection this method is called on
112    /// will be evicted once the connection is dropped. It is not possible to evict individual keys
113    /// (not for any technical reasons; a need for this has not yet arisen). `wrapped_key` must be
114    /// a key wrapped by the inline encryption hardware (in the same session/boot) via a separate
115    /// mechanism to this protocol.
116    ///
117    /// Returns
118    /// - ZX_ERR_NO_RESOURCES if there are no available key slots.
119    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
120    ///   fails authentication (e.g. wrapped_key is from a previous boot).
121    /// - ZX_ERR_TIMED_OUT if the operation times out.
122    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
123    pub fn r#program_key(
124        &self,
125        mut wrapped_key: &[u8],
126        mut data_unit_size: u32,
127        ___deadline: zx::MonotonicInstant,
128    ) -> Result<DeviceProgramKeyResult, fidl::Error> {
129        let _response = self.client.send_query::<
130            DeviceProgramKeyRequest,
131            fidl::encoding::ResultType<DeviceProgramKeyResponse, i32>,
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        >(
160            (wrapped_key,),
161            0x605392dccdef79d4,
162            fidl::encoding::DynamicFlags::empty(),
163            ___deadline,
164        )?;
165        Ok(_response.map(|x| x.secret))
166    }
167}
168
169#[cfg(target_os = "fuchsia")]
170impl From<DeviceSynchronousProxy> for zx::NullableHandle {
171    fn from(value: DeviceSynchronousProxy) -> Self {
172        value.into_channel().into()
173    }
174}
175
176#[cfg(target_os = "fuchsia")]
177impl From<fidl::Channel> for DeviceSynchronousProxy {
178    fn from(value: fidl::Channel) -> Self {
179        Self::new(value)
180    }
181}
182
183#[cfg(target_os = "fuchsia")]
184impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
185    type Protocol = DeviceMarker;
186
187    fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
188        Self::new(value.into_channel())
189    }
190}
191
192#[derive(Debug, Clone)]
193pub struct DeviceProxy {
194    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
195}
196
197impl fidl::endpoints::Proxy for DeviceProxy {
198    type Protocol = DeviceMarker;
199
200    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
201        Self::new(inner)
202    }
203
204    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
205        self.client.into_channel().map_err(|client| Self { client })
206    }
207
208    fn as_channel(&self) -> &::fidl::AsyncChannel {
209        self.client.as_channel()
210    }
211}
212
213impl DeviceProxy {
214    /// Create a new Proxy for fuchsia.hardware.inlineencryption/Device.
215    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
216        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
217        Self { client: fidl::client::Client::new(channel, protocol_name) }
218    }
219
220    /// Get a Stream of events from the remote end of the protocol.
221    ///
222    /// # Panics
223    ///
224    /// Panics if the event stream was already taken.
225    pub fn take_event_stream(&self) -> DeviceEventStream {
226        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
227    }
228
229    /// Programs the ephemerally wrapped `wrapped_key` into the inline encryption hardware in the
230    /// next available `slot`. All slots programmed via the connection this method is called on
231    /// will be evicted once the connection is dropped. It is not possible to evict individual keys
232    /// (not for any technical reasons; a need for this has not yet arisen). `wrapped_key` must be
233    /// a key wrapped by the inline encryption hardware (in the same session/boot) via a separate
234    /// mechanism to this protocol.
235    ///
236    /// Returns
237    /// - ZX_ERR_NO_RESOURCES if there are no available key slots.
238    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
239    ///   fails authentication (e.g. wrapped_key is from a previous boot).
240    /// - ZX_ERR_TIMED_OUT if the operation times out.
241    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
242    pub fn r#program_key(
243        &self,
244        mut wrapped_key: &[u8],
245        mut data_unit_size: u32,
246    ) -> fidl::client::QueryResponseFut<
247        DeviceProgramKeyResult,
248        fidl::encoding::DefaultFuchsiaResourceDialect,
249    > {
250        DeviceProxyInterface::r#program_key(self, wrapped_key, data_unit_size)
251    }
252
253    /// Derives a raw software secret from the ephemerally wrapped `wrapped_key`. `wrapped_key`
254    /// must be a key wrapped by the inline encryption hardware (in the same session/boot) via a
255    /// separate mechanism to this protocol. The returned secret can be used for non-inline
256    /// cryptographic operations e.g. it can be used for encrypting filesystem metadata not covered
257    /// by inline encryption.
258    /// Returns
259    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
260    ///   fails authentication (e.g. wrapped_key is from a previous boot).
261    /// - ZX_ERR_TIMED_OUT if the operation times out.
262    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
263    pub fn r#derive_raw_secret(
264        &self,
265        mut wrapped_key: &[u8],
266    ) -> fidl::client::QueryResponseFut<
267        DeviceDeriveRawSecretResult,
268        fidl::encoding::DefaultFuchsiaResourceDialect,
269    > {
270        DeviceProxyInterface::r#derive_raw_secret(self, wrapped_key)
271    }
272}
273
274impl DeviceProxyInterface for DeviceProxy {
275    type ProgramKeyResponseFut = fidl::client::QueryResponseFut<
276        DeviceProgramKeyResult,
277        fidl::encoding::DefaultFuchsiaResourceDialect,
278    >;
279    fn r#program_key(
280        &self,
281        mut wrapped_key: &[u8],
282        mut data_unit_size: u32,
283    ) -> Self::ProgramKeyResponseFut {
284        fn _decode(
285            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
286        ) -> Result<DeviceProgramKeyResult, fidl::Error> {
287            let _response = fidl::client::decode_transaction_body::<
288                fidl::encoding::ResultType<DeviceProgramKeyResponse, i32>,
289                fidl::encoding::DefaultFuchsiaResourceDialect,
290                0x30401dc60fc47cd0,
291            >(_buf?)?;
292            Ok(_response.map(|x| x.slot))
293        }
294        self.client.send_query_and_decode::<DeviceProgramKeyRequest, DeviceProgramKeyResult>(
295            (wrapped_key, data_unit_size),
296            0x30401dc60fc47cd0,
297            fidl::encoding::DynamicFlags::empty(),
298            _decode,
299        )
300    }
301
302    type DeriveRawSecretResponseFut = fidl::client::QueryResponseFut<
303        DeviceDeriveRawSecretResult,
304        fidl::encoding::DefaultFuchsiaResourceDialect,
305    >;
306    fn r#derive_raw_secret(&self, mut wrapped_key: &[u8]) -> Self::DeriveRawSecretResponseFut {
307        fn _decode(
308            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
309        ) -> Result<DeviceDeriveRawSecretResult, fidl::Error> {
310            let _response = fidl::client::decode_transaction_body::<
311                fidl::encoding::ResultType<DeviceDeriveRawSecretResponse, i32>,
312                fidl::encoding::DefaultFuchsiaResourceDialect,
313                0x605392dccdef79d4,
314            >(_buf?)?;
315            Ok(_response.map(|x| x.secret))
316        }
317        self.client
318            .send_query_and_decode::<DeviceDeriveRawSecretRequest, DeviceDeriveRawSecretResult>(
319                (wrapped_key,),
320                0x605392dccdef79d4,
321                fidl::encoding::DynamicFlags::empty(),
322                _decode,
323            )
324    }
325}
326
327pub struct DeviceEventStream {
328    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
329}
330
331impl std::marker::Unpin for DeviceEventStream {}
332
333impl futures::stream::FusedStream for DeviceEventStream {
334    fn is_terminated(&self) -> bool {
335        self.event_receiver.is_terminated()
336    }
337}
338
339impl futures::Stream for DeviceEventStream {
340    type Item = Result<DeviceEvent, fidl::Error>;
341
342    fn poll_next(
343        mut self: std::pin::Pin<&mut Self>,
344        cx: &mut std::task::Context<'_>,
345    ) -> std::task::Poll<Option<Self::Item>> {
346        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
347            &mut self.event_receiver,
348            cx
349        )?) {
350            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
351            None => std::task::Poll::Ready(None),
352        }
353    }
354}
355
356#[derive(Debug)]
357pub enum DeviceEvent {}
358
359impl DeviceEvent {
360    /// Decodes a message buffer as a [`DeviceEvent`].
361    fn decode(
362        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
363    ) -> Result<DeviceEvent, fidl::Error> {
364        let (bytes, _handles) = buf.split_mut();
365        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
366        debug_assert_eq!(tx_header.tx_id, 0);
367        match tx_header.ordinal {
368            _ => Err(fidl::Error::UnknownOrdinal {
369                ordinal: tx_header.ordinal,
370                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
371            }),
372        }
373    }
374}
375
376/// A Stream of incoming requests for fuchsia.hardware.inlineencryption/Device.
377pub struct DeviceRequestStream {
378    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
379    is_terminated: bool,
380}
381
382impl std::marker::Unpin for DeviceRequestStream {}
383
384impl futures::stream::FusedStream for DeviceRequestStream {
385    fn is_terminated(&self) -> bool {
386        self.is_terminated
387    }
388}
389
390impl fidl::endpoints::RequestStream for DeviceRequestStream {
391    type Protocol = DeviceMarker;
392    type ControlHandle = DeviceControlHandle;
393
394    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
395        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
396    }
397
398    fn control_handle(&self) -> Self::ControlHandle {
399        DeviceControlHandle { inner: self.inner.clone() }
400    }
401
402    fn into_inner(
403        self,
404    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
405    {
406        (self.inner, self.is_terminated)
407    }
408
409    fn from_inner(
410        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
411        is_terminated: bool,
412    ) -> Self {
413        Self { inner, is_terminated }
414    }
415}
416
417impl futures::Stream for DeviceRequestStream {
418    type Item = Result<DeviceRequest, fidl::Error>;
419
420    fn poll_next(
421        mut self: std::pin::Pin<&mut Self>,
422        cx: &mut std::task::Context<'_>,
423    ) -> std::task::Poll<Option<Self::Item>> {
424        let this = &mut *self;
425        if this.inner.check_shutdown(cx) {
426            this.is_terminated = true;
427            return std::task::Poll::Ready(None);
428        }
429        if this.is_terminated {
430            panic!("polled DeviceRequestStream after completion");
431        }
432        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
433            |bytes, handles| {
434                match this.inner.channel().read_etc(cx, bytes, handles) {
435                    std::task::Poll::Ready(Ok(())) => {}
436                    std::task::Poll::Pending => return std::task::Poll::Pending,
437                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
438                        this.is_terminated = true;
439                        return std::task::Poll::Ready(None);
440                    }
441                    std::task::Poll::Ready(Err(e)) => {
442                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
443                            e.into(),
444                        ))));
445                    }
446                }
447
448                // A message has been received from the channel
449                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
450
451                std::task::Poll::Ready(Some(match header.ordinal {
452                    0x30401dc60fc47cd0 => {
453                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
454                        let mut req = fidl::new_empty!(
455                            DeviceProgramKeyRequest,
456                            fidl::encoding::DefaultFuchsiaResourceDialect
457                        );
458                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceProgramKeyRequest>(&header, _body_bytes, handles, &mut req)?;
459                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
460                        Ok(DeviceRequest::ProgramKey {
461                            wrapped_key: req.wrapped_key,
462                            data_unit_size: req.data_unit_size,
463
464                            responder: DeviceProgramKeyResponder {
465                                control_handle: std::mem::ManuallyDrop::new(control_handle),
466                                tx_id: header.tx_id,
467                            },
468                        })
469                    }
470                    0x605392dccdef79d4 => {
471                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
472                        let mut req = fidl::new_empty!(
473                            DeviceDeriveRawSecretRequest,
474                            fidl::encoding::DefaultFuchsiaResourceDialect
475                        );
476                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceDeriveRawSecretRequest>(&header, _body_bytes, handles, &mut req)?;
477                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
478                        Ok(DeviceRequest::DeriveRawSecret {
479                            wrapped_key: req.wrapped_key,
480
481                            responder: DeviceDeriveRawSecretResponder {
482                                control_handle: std::mem::ManuallyDrop::new(control_handle),
483                                tx_id: header.tx_id,
484                            },
485                        })
486                    }
487                    _ => Err(fidl::Error::UnknownOrdinal {
488                        ordinal: header.ordinal,
489                        protocol_name:
490                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
491                    }),
492                }))
493            },
494        )
495    }
496}
497
498#[derive(Debug)]
499pub enum DeviceRequest {
500    /// Programs the ephemerally wrapped `wrapped_key` into the inline encryption hardware in the
501    /// next available `slot`. All slots programmed via the connection this method is called on
502    /// will be evicted once the connection is dropped. It is not possible to evict individual keys
503    /// (not for any technical reasons; a need for this has not yet arisen). `wrapped_key` must be
504    /// a key wrapped by the inline encryption hardware (in the same session/boot) via a separate
505    /// mechanism to this protocol.
506    ///
507    /// Returns
508    /// - ZX_ERR_NO_RESOURCES if there are no available key slots.
509    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
510    ///   fails authentication (e.g. wrapped_key is from a previous boot).
511    /// - ZX_ERR_TIMED_OUT if the operation times out.
512    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
513    ProgramKey { wrapped_key: Vec<u8>, data_unit_size: u32, responder: DeviceProgramKeyResponder },
514    /// Derives a raw software secret from the ephemerally wrapped `wrapped_key`. `wrapped_key`
515    /// must be a key wrapped by the inline encryption hardware (in the same session/boot) via a
516    /// separate mechanism to this protocol. The returned secret can be used for non-inline
517    /// cryptographic operations e.g. it can be used for encrypting filesystem metadata not covered
518    /// by inline encryption.
519    /// Returns
520    /// - ZX_ERR_INVALID_ARGS if `wrapped_key` is not the expected size or if the `wrapped_key`
521    ///   fails authentication (e.g. wrapped_key is from a previous boot).
522    /// - ZX_ERR_TIMED_OUT if the operation times out.
523    /// - ZX_ERR_INTERNAL if the operation failed for any other reason.
524    DeriveRawSecret { wrapped_key: Vec<u8>, responder: DeviceDeriveRawSecretResponder },
525}
526
527impl DeviceRequest {
528    #[allow(irrefutable_let_patterns)]
529    pub fn into_program_key(self) -> Option<(Vec<u8>, u32, DeviceProgramKeyResponder)> {
530        if let DeviceRequest::ProgramKey { wrapped_key, data_unit_size, responder } = self {
531            Some((wrapped_key, data_unit_size, responder))
532        } else {
533            None
534        }
535    }
536
537    #[allow(irrefutable_let_patterns)]
538    pub fn into_derive_raw_secret(self) -> Option<(Vec<u8>, DeviceDeriveRawSecretResponder)> {
539        if let DeviceRequest::DeriveRawSecret { wrapped_key, responder } = self {
540            Some((wrapped_key, responder))
541        } else {
542            None
543        }
544    }
545
546    /// Name of the method defined in FIDL
547    pub fn method_name(&self) -> &'static str {
548        match *self {
549            DeviceRequest::ProgramKey { .. } => "program_key",
550            DeviceRequest::DeriveRawSecret { .. } => "derive_raw_secret",
551        }
552    }
553}
554
555#[derive(Debug, Clone)]
556pub struct DeviceControlHandle {
557    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
558}
559
560impl fidl::endpoints::ControlHandle for DeviceControlHandle {
561    fn shutdown(&self) {
562        self.inner.shutdown()
563    }
564
565    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
566        self.inner.shutdown_with_epitaph(status)
567    }
568
569    fn is_closed(&self) -> bool {
570        self.inner.channel().is_closed()
571    }
572    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
573        self.inner.channel().on_closed()
574    }
575
576    #[cfg(target_os = "fuchsia")]
577    fn signal_peer(
578        &self,
579        clear_mask: zx::Signals,
580        set_mask: zx::Signals,
581    ) -> Result<(), zx_status::Status> {
582        use fidl::Peered;
583        self.inner.channel().signal_peer(clear_mask, set_mask)
584    }
585}
586
587impl DeviceControlHandle {}
588
589#[must_use = "FIDL methods require a response to be sent"]
590#[derive(Debug)]
591pub struct DeviceProgramKeyResponder {
592    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
593    tx_id: u32,
594}
595
596/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
597/// if the responder is dropped without sending a response, so that the client
598/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
599impl std::ops::Drop for DeviceProgramKeyResponder {
600    fn drop(&mut self) {
601        self.control_handle.shutdown();
602        // Safety: drops once, never accessed again
603        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
604    }
605}
606
607impl fidl::endpoints::Responder for DeviceProgramKeyResponder {
608    type ControlHandle = DeviceControlHandle;
609
610    fn control_handle(&self) -> &DeviceControlHandle {
611        &self.control_handle
612    }
613
614    fn drop_without_shutdown(mut self) {
615        // Safety: drops once, never accessed again due to mem::forget
616        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
617        // Prevent Drop from running (which would shut down the channel)
618        std::mem::forget(self);
619    }
620}
621
622impl DeviceProgramKeyResponder {
623    /// Sends a response to the FIDL transaction.
624    ///
625    /// Sets the channel to shutdown if an error occurs.
626    pub fn send(self, mut result: Result<u8, i32>) -> Result<(), fidl::Error> {
627        let _result = self.send_raw(result);
628        if _result.is_err() {
629            self.control_handle.shutdown();
630        }
631        self.drop_without_shutdown();
632        _result
633    }
634
635    /// Similar to "send" but does not shutdown the channel if an error occurs.
636    pub fn send_no_shutdown_on_err(self, mut result: Result<u8, i32>) -> Result<(), fidl::Error> {
637        let _result = self.send_raw(result);
638        self.drop_without_shutdown();
639        _result
640    }
641
642    fn send_raw(&self, mut result: Result<u8, i32>) -> Result<(), fidl::Error> {
643        self.control_handle.inner.send::<fidl::encoding::ResultType<DeviceProgramKeyResponse, i32>>(
644            result.map(|slot| (slot,)),
645            self.tx_id,
646            0x30401dc60fc47cd0,
647            fidl::encoding::DynamicFlags::empty(),
648        )
649    }
650}
651
652#[must_use = "FIDL methods require a response to be sent"]
653#[derive(Debug)]
654pub struct DeviceDeriveRawSecretResponder {
655    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
656    tx_id: u32,
657}
658
659/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
660/// if the responder is dropped without sending a response, so that the client
661/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
662impl std::ops::Drop for DeviceDeriveRawSecretResponder {
663    fn drop(&mut self) {
664        self.control_handle.shutdown();
665        // Safety: drops once, never accessed again
666        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
667    }
668}
669
670impl fidl::endpoints::Responder for DeviceDeriveRawSecretResponder {
671    type ControlHandle = DeviceControlHandle;
672
673    fn control_handle(&self) -> &DeviceControlHandle {
674        &self.control_handle
675    }
676
677    fn drop_without_shutdown(mut self) {
678        // Safety: drops once, never accessed again due to mem::forget
679        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
680        // Prevent Drop from running (which would shut down the channel)
681        std::mem::forget(self);
682    }
683}
684
685impl DeviceDeriveRawSecretResponder {
686    /// Sends a response to the FIDL transaction.
687    ///
688    /// Sets the channel to shutdown if an error occurs.
689    pub fn send(self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
690        let _result = self.send_raw(result);
691        if _result.is_err() {
692            self.control_handle.shutdown();
693        }
694        self.drop_without_shutdown();
695        _result
696    }
697
698    /// Similar to "send" but does not shutdown the channel if an error occurs.
699    pub fn send_no_shutdown_on_err(
700        self,
701        mut result: Result<&[u8], i32>,
702    ) -> Result<(), fidl::Error> {
703        let _result = self.send_raw(result);
704        self.drop_without_shutdown();
705        _result
706    }
707
708    fn send_raw(&self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
709        self.control_handle
710            .inner
711            .send::<fidl::encoding::ResultType<DeviceDeriveRawSecretResponse, i32>>(
712                result.map(|secret| (secret,)),
713                self.tx_id,
714                0x605392dccdef79d4,
715                fidl::encoding::DynamicFlags::empty(),
716            )
717    }
718}
719
720mod internal {
721    use super::*;
722
723    impl fidl::encoding::ResourceTypeMarker for DeviceDeriveRawSecretRequest {
724        type Borrowed<'a> = &'a mut Self;
725        fn take_or_borrow<'a>(
726            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
727        ) -> Self::Borrowed<'a> {
728            value
729        }
730    }
731
732    unsafe impl fidl::encoding::TypeMarker for DeviceDeriveRawSecretRequest {
733        type Owned = Self;
734
735        #[inline(always)]
736        fn inline_align(_context: fidl::encoding::Context) -> usize {
737            8
738        }
739
740        #[inline(always)]
741        fn inline_size(_context: fidl::encoding::Context) -> usize {
742            16
743        }
744    }
745
746    unsafe impl
747        fidl::encoding::Encode<
748            DeviceDeriveRawSecretRequest,
749            fidl::encoding::DefaultFuchsiaResourceDialect,
750        > for &mut DeviceDeriveRawSecretRequest
751    {
752        #[inline]
753        unsafe fn encode(
754            self,
755            encoder: &mut fidl::encoding::Encoder<
756                '_,
757                fidl::encoding::DefaultFuchsiaResourceDialect,
758            >,
759            offset: usize,
760            _depth: fidl::encoding::Depth,
761        ) -> fidl::Result<()> {
762            encoder.debug_check_bounds::<DeviceDeriveRawSecretRequest>(offset);
763            // Delegate to tuple encoding.
764            fidl::encoding::Encode::<
765                DeviceDeriveRawSecretRequest,
766                fidl::encoding::DefaultFuchsiaResourceDialect,
767            >::encode(
768                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
769                    &self.wrapped_key,
770                ),),
771                encoder,
772                offset,
773                _depth,
774            )
775        }
776    }
777    unsafe impl<
778        T0: fidl::encoding::Encode<
779                fidl::encoding::UnboundedVector<u8>,
780                fidl::encoding::DefaultFuchsiaResourceDialect,
781            >,
782    >
783        fidl::encoding::Encode<
784            DeviceDeriveRawSecretRequest,
785            fidl::encoding::DefaultFuchsiaResourceDialect,
786        > for (T0,)
787    {
788        #[inline]
789        unsafe fn encode(
790            self,
791            encoder: &mut fidl::encoding::Encoder<
792                '_,
793                fidl::encoding::DefaultFuchsiaResourceDialect,
794            >,
795            offset: usize,
796            depth: fidl::encoding::Depth,
797        ) -> fidl::Result<()> {
798            encoder.debug_check_bounds::<DeviceDeriveRawSecretRequest>(offset);
799            // Zero out padding regions. There's no need to apply masks
800            // because the unmasked parts will be overwritten by fields.
801            // Write the fields.
802            self.0.encode(encoder, offset + 0, depth)?;
803            Ok(())
804        }
805    }
806
807    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
808        for DeviceDeriveRawSecretRequest
809    {
810        #[inline(always)]
811        fn new_empty() -> Self {
812            Self {
813                wrapped_key: fidl::new_empty!(
814                    fidl::encoding::UnboundedVector<u8>,
815                    fidl::encoding::DefaultFuchsiaResourceDialect
816                ),
817            }
818        }
819
820        #[inline]
821        unsafe fn decode(
822            &mut self,
823            decoder: &mut fidl::encoding::Decoder<
824                '_,
825                fidl::encoding::DefaultFuchsiaResourceDialect,
826            >,
827            offset: usize,
828            _depth: fidl::encoding::Depth,
829        ) -> fidl::Result<()> {
830            decoder.debug_check_bounds::<Self>(offset);
831            // Verify that padding bytes are zero.
832            fidl::decode!(
833                fidl::encoding::UnboundedVector<u8>,
834                fidl::encoding::DefaultFuchsiaResourceDialect,
835                &mut self.wrapped_key,
836                decoder,
837                offset + 0,
838                _depth
839            )?;
840            Ok(())
841        }
842    }
843
844    impl fidl::encoding::ResourceTypeMarker for DeviceProgramKeyRequest {
845        type Borrowed<'a> = &'a mut Self;
846        fn take_or_borrow<'a>(
847            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
848        ) -> Self::Borrowed<'a> {
849            value
850        }
851    }
852
853    unsafe impl fidl::encoding::TypeMarker for DeviceProgramKeyRequest {
854        type Owned = Self;
855
856        #[inline(always)]
857        fn inline_align(_context: fidl::encoding::Context) -> usize {
858            8
859        }
860
861        #[inline(always)]
862        fn inline_size(_context: fidl::encoding::Context) -> usize {
863            24
864        }
865    }
866
867    unsafe impl
868        fidl::encoding::Encode<
869            DeviceProgramKeyRequest,
870            fidl::encoding::DefaultFuchsiaResourceDialect,
871        > for &mut DeviceProgramKeyRequest
872    {
873        #[inline]
874        unsafe fn encode(
875            self,
876            encoder: &mut fidl::encoding::Encoder<
877                '_,
878                fidl::encoding::DefaultFuchsiaResourceDialect,
879            >,
880            offset: usize,
881            _depth: fidl::encoding::Depth,
882        ) -> fidl::Result<()> {
883            encoder.debug_check_bounds::<DeviceProgramKeyRequest>(offset);
884            // Delegate to tuple encoding.
885            fidl::encoding::Encode::<DeviceProgramKeyRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
886                (
887                    <fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(&self.wrapped_key),
888                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.data_unit_size),
889                ),
890                encoder, offset, _depth
891            )
892        }
893    }
894    unsafe impl<
895        T0: fidl::encoding::Encode<
896                fidl::encoding::UnboundedVector<u8>,
897                fidl::encoding::DefaultFuchsiaResourceDialect,
898            >,
899        T1: fidl::encoding::Encode<u32, fidl::encoding::DefaultFuchsiaResourceDialect>,
900    >
901        fidl::encoding::Encode<
902            DeviceProgramKeyRequest,
903            fidl::encoding::DefaultFuchsiaResourceDialect,
904        > for (T0, T1)
905    {
906        #[inline]
907        unsafe fn encode(
908            self,
909            encoder: &mut fidl::encoding::Encoder<
910                '_,
911                fidl::encoding::DefaultFuchsiaResourceDialect,
912            >,
913            offset: usize,
914            depth: fidl::encoding::Depth,
915        ) -> fidl::Result<()> {
916            encoder.debug_check_bounds::<DeviceProgramKeyRequest>(offset);
917            // Zero out padding regions. There's no need to apply masks
918            // because the unmasked parts will be overwritten by fields.
919            unsafe {
920                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
921                (ptr as *mut u64).write_unaligned(0);
922            }
923            // Write the fields.
924            self.0.encode(encoder, offset + 0, depth)?;
925            self.1.encode(encoder, offset + 16, depth)?;
926            Ok(())
927        }
928    }
929
930    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
931        for DeviceProgramKeyRequest
932    {
933        #[inline(always)]
934        fn new_empty() -> Self {
935            Self {
936                wrapped_key: fidl::new_empty!(
937                    fidl::encoding::UnboundedVector<u8>,
938                    fidl::encoding::DefaultFuchsiaResourceDialect
939                ),
940                data_unit_size: fidl::new_empty!(
941                    u32,
942                    fidl::encoding::DefaultFuchsiaResourceDialect
943                ),
944            }
945        }
946
947        #[inline]
948        unsafe fn decode(
949            &mut self,
950            decoder: &mut fidl::encoding::Decoder<
951                '_,
952                fidl::encoding::DefaultFuchsiaResourceDialect,
953            >,
954            offset: usize,
955            _depth: fidl::encoding::Depth,
956        ) -> fidl::Result<()> {
957            decoder.debug_check_bounds::<Self>(offset);
958            // Verify that padding bytes are zero.
959            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
960            let padval = unsafe { (ptr as *const u64).read_unaligned() };
961            let mask = 0xffffffff00000000u64;
962            let maskedval = padval & mask;
963            if maskedval != 0 {
964                return Err(fidl::Error::NonZeroPadding {
965                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
966                });
967            }
968            fidl::decode!(
969                fidl::encoding::UnboundedVector<u8>,
970                fidl::encoding::DefaultFuchsiaResourceDialect,
971                &mut self.wrapped_key,
972                decoder,
973                offset + 0,
974                _depth
975            )?;
976            fidl::decode!(
977                u32,
978                fidl::encoding::DefaultFuchsiaResourceDialect,
979                &mut self.data_unit_size,
980                decoder,
981                offset + 16,
982                _depth
983            )?;
984            Ok(())
985        }
986    }
987
988    impl fidl::encoding::ResourceTypeMarker for DeviceDeriveRawSecretResponse {
989        type Borrowed<'a> = &'a mut Self;
990        fn take_or_borrow<'a>(
991            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
992        ) -> Self::Borrowed<'a> {
993            value
994        }
995    }
996
997    unsafe impl fidl::encoding::TypeMarker for DeviceDeriveRawSecretResponse {
998        type Owned = Self;
999
1000        #[inline(always)]
1001        fn inline_align(_context: fidl::encoding::Context) -> usize {
1002            8
1003        }
1004
1005        #[inline(always)]
1006        fn inline_size(_context: fidl::encoding::Context) -> usize {
1007            16
1008        }
1009    }
1010
1011    unsafe impl
1012        fidl::encoding::Encode<
1013            DeviceDeriveRawSecretResponse,
1014            fidl::encoding::DefaultFuchsiaResourceDialect,
1015        > for &mut DeviceDeriveRawSecretResponse
1016    {
1017        #[inline]
1018        unsafe fn encode(
1019            self,
1020            encoder: &mut fidl::encoding::Encoder<
1021                '_,
1022                fidl::encoding::DefaultFuchsiaResourceDialect,
1023            >,
1024            offset: usize,
1025            _depth: fidl::encoding::Depth,
1026        ) -> fidl::Result<()> {
1027            encoder.debug_check_bounds::<DeviceDeriveRawSecretResponse>(offset);
1028            // Delegate to tuple encoding.
1029            fidl::encoding::Encode::<
1030                DeviceDeriveRawSecretResponse,
1031                fidl::encoding::DefaultFuchsiaResourceDialect,
1032            >::encode(
1033                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
1034                    &self.secret,
1035                ),),
1036                encoder,
1037                offset,
1038                _depth,
1039            )
1040        }
1041    }
1042    unsafe impl<
1043        T0: fidl::encoding::Encode<
1044                fidl::encoding::UnboundedVector<u8>,
1045                fidl::encoding::DefaultFuchsiaResourceDialect,
1046            >,
1047    >
1048        fidl::encoding::Encode<
1049            DeviceDeriveRawSecretResponse,
1050            fidl::encoding::DefaultFuchsiaResourceDialect,
1051        > for (T0,)
1052    {
1053        #[inline]
1054        unsafe fn encode(
1055            self,
1056            encoder: &mut fidl::encoding::Encoder<
1057                '_,
1058                fidl::encoding::DefaultFuchsiaResourceDialect,
1059            >,
1060            offset: usize,
1061            depth: fidl::encoding::Depth,
1062        ) -> fidl::Result<()> {
1063            encoder.debug_check_bounds::<DeviceDeriveRawSecretResponse>(offset);
1064            // Zero out padding regions. There's no need to apply masks
1065            // because the unmasked parts will be overwritten by fields.
1066            // Write the fields.
1067            self.0.encode(encoder, offset + 0, depth)?;
1068            Ok(())
1069        }
1070    }
1071
1072    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1073        for DeviceDeriveRawSecretResponse
1074    {
1075        #[inline(always)]
1076        fn new_empty() -> Self {
1077            Self {
1078                secret: fidl::new_empty!(
1079                    fidl::encoding::UnboundedVector<u8>,
1080                    fidl::encoding::DefaultFuchsiaResourceDialect
1081                ),
1082            }
1083        }
1084
1085        #[inline]
1086        unsafe fn decode(
1087            &mut self,
1088            decoder: &mut fidl::encoding::Decoder<
1089                '_,
1090                fidl::encoding::DefaultFuchsiaResourceDialect,
1091            >,
1092            offset: usize,
1093            _depth: fidl::encoding::Depth,
1094        ) -> fidl::Result<()> {
1095            decoder.debug_check_bounds::<Self>(offset);
1096            // Verify that padding bytes are zero.
1097            fidl::decode!(
1098                fidl::encoding::UnboundedVector<u8>,
1099                fidl::encoding::DefaultFuchsiaResourceDialect,
1100                &mut self.secret,
1101                decoder,
1102                offset + 0,
1103                _depth
1104            )?;
1105            Ok(())
1106        }
1107    }
1108}