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
720#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
721pub struct ServiceMarker;
722
723#[cfg(target_os = "fuchsia")]
724impl fidl::endpoints::ServiceMarker for ServiceMarker {
725    type Proxy = ServiceProxy;
726    type Request = ServiceRequest;
727    const SERVICE_NAME: &'static str = "fuchsia.hardware.inlineencryption.Service";
728}
729
730/// A request for one of the member protocols of Service.
731///
732#[cfg(target_os = "fuchsia")]
733pub enum ServiceRequest {
734    Device(DeviceRequestStream),
735}
736
737#[cfg(target_os = "fuchsia")]
738impl fidl::endpoints::ServiceRequest for ServiceRequest {
739    type Service = ServiceMarker;
740
741    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
742        match name {
743            "device" => Self::Device(
744                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
745            ),
746            _ => panic!("no such member protocol name for service Service"),
747        }
748    }
749
750    fn member_names() -> &'static [&'static str] {
751        &["device"]
752    }
753}
754#[cfg(target_os = "fuchsia")]
755pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
756
757#[cfg(target_os = "fuchsia")]
758impl fidl::endpoints::ServiceProxy for ServiceProxy {
759    type Service = ServiceMarker;
760
761    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
762        Self(opener)
763    }
764}
765
766#[cfg(target_os = "fuchsia")]
767impl ServiceProxy {
768    pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
769        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
770        self.connect_channel_to_device(server_end)?;
771        Ok(proxy)
772    }
773
774    /// Like `connect_to_device`, but returns a sync proxy.
775    /// See [`Self::connect_to_device`] for more details.
776    pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
777        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
778        self.connect_channel_to_device(server_end)?;
779        Ok(proxy)
780    }
781
782    /// Like `connect_to_device`, but accepts a server end.
783    /// See [`Self::connect_to_device`] for more details.
784    pub fn connect_channel_to_device(
785        &self,
786        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
787    ) -> Result<(), fidl::Error> {
788        self.0.open_member("device", server_end.into_channel())
789    }
790
791    pub fn instance_name(&self) -> &str {
792        self.0.instance_name()
793    }
794}
795
796mod internal {
797    use super::*;
798
799    impl fidl::encoding::ResourceTypeMarker for DeviceDeriveRawSecretRequest {
800        type Borrowed<'a> = &'a mut Self;
801        fn take_or_borrow<'a>(
802            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
803        ) -> Self::Borrowed<'a> {
804            value
805        }
806    }
807
808    unsafe impl fidl::encoding::TypeMarker for DeviceDeriveRawSecretRequest {
809        type Owned = Self;
810
811        #[inline(always)]
812        fn inline_align(_context: fidl::encoding::Context) -> usize {
813            8
814        }
815
816        #[inline(always)]
817        fn inline_size(_context: fidl::encoding::Context) -> usize {
818            16
819        }
820    }
821
822    unsafe impl
823        fidl::encoding::Encode<
824            DeviceDeriveRawSecretRequest,
825            fidl::encoding::DefaultFuchsiaResourceDialect,
826        > for &mut DeviceDeriveRawSecretRequest
827    {
828        #[inline]
829        unsafe fn encode(
830            self,
831            encoder: &mut fidl::encoding::Encoder<
832                '_,
833                fidl::encoding::DefaultFuchsiaResourceDialect,
834            >,
835            offset: usize,
836            _depth: fidl::encoding::Depth,
837        ) -> fidl::Result<()> {
838            encoder.debug_check_bounds::<DeviceDeriveRawSecretRequest>(offset);
839            // Delegate to tuple encoding.
840            fidl::encoding::Encode::<
841                DeviceDeriveRawSecretRequest,
842                fidl::encoding::DefaultFuchsiaResourceDialect,
843            >::encode(
844                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
845                    &self.wrapped_key,
846                ),),
847                encoder,
848                offset,
849                _depth,
850            )
851        }
852    }
853    unsafe impl<
854        T0: fidl::encoding::Encode<
855                fidl::encoding::UnboundedVector<u8>,
856                fidl::encoding::DefaultFuchsiaResourceDialect,
857            >,
858    >
859        fidl::encoding::Encode<
860            DeviceDeriveRawSecretRequest,
861            fidl::encoding::DefaultFuchsiaResourceDialect,
862        > for (T0,)
863    {
864        #[inline]
865        unsafe fn encode(
866            self,
867            encoder: &mut fidl::encoding::Encoder<
868                '_,
869                fidl::encoding::DefaultFuchsiaResourceDialect,
870            >,
871            offset: usize,
872            depth: fidl::encoding::Depth,
873        ) -> fidl::Result<()> {
874            encoder.debug_check_bounds::<DeviceDeriveRawSecretRequest>(offset);
875            // Zero out padding regions. There's no need to apply masks
876            // because the unmasked parts will be overwritten by fields.
877            // Write the fields.
878            self.0.encode(encoder, offset + 0, depth)?;
879            Ok(())
880        }
881    }
882
883    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
884        for DeviceDeriveRawSecretRequest
885    {
886        #[inline(always)]
887        fn new_empty() -> Self {
888            Self {
889                wrapped_key: fidl::new_empty!(
890                    fidl::encoding::UnboundedVector<u8>,
891                    fidl::encoding::DefaultFuchsiaResourceDialect
892                ),
893            }
894        }
895
896        #[inline]
897        unsafe fn decode(
898            &mut self,
899            decoder: &mut fidl::encoding::Decoder<
900                '_,
901                fidl::encoding::DefaultFuchsiaResourceDialect,
902            >,
903            offset: usize,
904            _depth: fidl::encoding::Depth,
905        ) -> fidl::Result<()> {
906            decoder.debug_check_bounds::<Self>(offset);
907            // Verify that padding bytes are zero.
908            fidl::decode!(
909                fidl::encoding::UnboundedVector<u8>,
910                fidl::encoding::DefaultFuchsiaResourceDialect,
911                &mut self.wrapped_key,
912                decoder,
913                offset + 0,
914                _depth
915            )?;
916            Ok(())
917        }
918    }
919
920    impl fidl::encoding::ResourceTypeMarker for DeviceProgramKeyRequest {
921        type Borrowed<'a> = &'a mut Self;
922        fn take_or_borrow<'a>(
923            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
924        ) -> Self::Borrowed<'a> {
925            value
926        }
927    }
928
929    unsafe impl fidl::encoding::TypeMarker for DeviceProgramKeyRequest {
930        type Owned = Self;
931
932        #[inline(always)]
933        fn inline_align(_context: fidl::encoding::Context) -> usize {
934            8
935        }
936
937        #[inline(always)]
938        fn inline_size(_context: fidl::encoding::Context) -> usize {
939            24
940        }
941    }
942
943    unsafe impl
944        fidl::encoding::Encode<
945            DeviceProgramKeyRequest,
946            fidl::encoding::DefaultFuchsiaResourceDialect,
947        > for &mut DeviceProgramKeyRequest
948    {
949        #[inline]
950        unsafe fn encode(
951            self,
952            encoder: &mut fidl::encoding::Encoder<
953                '_,
954                fidl::encoding::DefaultFuchsiaResourceDialect,
955            >,
956            offset: usize,
957            _depth: fidl::encoding::Depth,
958        ) -> fidl::Result<()> {
959            encoder.debug_check_bounds::<DeviceProgramKeyRequest>(offset);
960            // Delegate to tuple encoding.
961            fidl::encoding::Encode::<DeviceProgramKeyRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
962                (
963                    <fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(&self.wrapped_key),
964                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.data_unit_size),
965                ),
966                encoder, offset, _depth
967            )
968        }
969    }
970    unsafe impl<
971        T0: fidl::encoding::Encode<
972                fidl::encoding::UnboundedVector<u8>,
973                fidl::encoding::DefaultFuchsiaResourceDialect,
974            >,
975        T1: fidl::encoding::Encode<u32, fidl::encoding::DefaultFuchsiaResourceDialect>,
976    >
977        fidl::encoding::Encode<
978            DeviceProgramKeyRequest,
979            fidl::encoding::DefaultFuchsiaResourceDialect,
980        > for (T0, T1)
981    {
982        #[inline]
983        unsafe fn encode(
984            self,
985            encoder: &mut fidl::encoding::Encoder<
986                '_,
987                fidl::encoding::DefaultFuchsiaResourceDialect,
988            >,
989            offset: usize,
990            depth: fidl::encoding::Depth,
991        ) -> fidl::Result<()> {
992            encoder.debug_check_bounds::<DeviceProgramKeyRequest>(offset);
993            // Zero out padding regions. There's no need to apply masks
994            // because the unmasked parts will be overwritten by fields.
995            unsafe {
996                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
997                (ptr as *mut u64).write_unaligned(0);
998            }
999            // Write the fields.
1000            self.0.encode(encoder, offset + 0, depth)?;
1001            self.1.encode(encoder, offset + 16, depth)?;
1002            Ok(())
1003        }
1004    }
1005
1006    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1007        for DeviceProgramKeyRequest
1008    {
1009        #[inline(always)]
1010        fn new_empty() -> Self {
1011            Self {
1012                wrapped_key: fidl::new_empty!(
1013                    fidl::encoding::UnboundedVector<u8>,
1014                    fidl::encoding::DefaultFuchsiaResourceDialect
1015                ),
1016                data_unit_size: fidl::new_empty!(
1017                    u32,
1018                    fidl::encoding::DefaultFuchsiaResourceDialect
1019                ),
1020            }
1021        }
1022
1023        #[inline]
1024        unsafe fn decode(
1025            &mut self,
1026            decoder: &mut fidl::encoding::Decoder<
1027                '_,
1028                fidl::encoding::DefaultFuchsiaResourceDialect,
1029            >,
1030            offset: usize,
1031            _depth: fidl::encoding::Depth,
1032        ) -> fidl::Result<()> {
1033            decoder.debug_check_bounds::<Self>(offset);
1034            // Verify that padding bytes are zero.
1035            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1036            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1037            let mask = 0xffffffff00000000u64;
1038            let maskedval = padval & mask;
1039            if maskedval != 0 {
1040                return Err(fidl::Error::NonZeroPadding {
1041                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1042                });
1043            }
1044            fidl::decode!(
1045                fidl::encoding::UnboundedVector<u8>,
1046                fidl::encoding::DefaultFuchsiaResourceDialect,
1047                &mut self.wrapped_key,
1048                decoder,
1049                offset + 0,
1050                _depth
1051            )?;
1052            fidl::decode!(
1053                u32,
1054                fidl::encoding::DefaultFuchsiaResourceDialect,
1055                &mut self.data_unit_size,
1056                decoder,
1057                offset + 16,
1058                _depth
1059            )?;
1060            Ok(())
1061        }
1062    }
1063
1064    impl fidl::encoding::ResourceTypeMarker for DeviceDeriveRawSecretResponse {
1065        type Borrowed<'a> = &'a mut Self;
1066        fn take_or_borrow<'a>(
1067            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1068        ) -> Self::Borrowed<'a> {
1069            value
1070        }
1071    }
1072
1073    unsafe impl fidl::encoding::TypeMarker for DeviceDeriveRawSecretResponse {
1074        type Owned = Self;
1075
1076        #[inline(always)]
1077        fn inline_align(_context: fidl::encoding::Context) -> usize {
1078            8
1079        }
1080
1081        #[inline(always)]
1082        fn inline_size(_context: fidl::encoding::Context) -> usize {
1083            16
1084        }
1085    }
1086
1087    unsafe impl
1088        fidl::encoding::Encode<
1089            DeviceDeriveRawSecretResponse,
1090            fidl::encoding::DefaultFuchsiaResourceDialect,
1091        > for &mut DeviceDeriveRawSecretResponse
1092    {
1093        #[inline]
1094        unsafe fn encode(
1095            self,
1096            encoder: &mut fidl::encoding::Encoder<
1097                '_,
1098                fidl::encoding::DefaultFuchsiaResourceDialect,
1099            >,
1100            offset: usize,
1101            _depth: fidl::encoding::Depth,
1102        ) -> fidl::Result<()> {
1103            encoder.debug_check_bounds::<DeviceDeriveRawSecretResponse>(offset);
1104            // Delegate to tuple encoding.
1105            fidl::encoding::Encode::<
1106                DeviceDeriveRawSecretResponse,
1107                fidl::encoding::DefaultFuchsiaResourceDialect,
1108            >::encode(
1109                (<fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(
1110                    &self.secret,
1111                ),),
1112                encoder,
1113                offset,
1114                _depth,
1115            )
1116        }
1117    }
1118    unsafe impl<
1119        T0: fidl::encoding::Encode<
1120                fidl::encoding::UnboundedVector<u8>,
1121                fidl::encoding::DefaultFuchsiaResourceDialect,
1122            >,
1123    >
1124        fidl::encoding::Encode<
1125            DeviceDeriveRawSecretResponse,
1126            fidl::encoding::DefaultFuchsiaResourceDialect,
1127        > for (T0,)
1128    {
1129        #[inline]
1130        unsafe fn encode(
1131            self,
1132            encoder: &mut fidl::encoding::Encoder<
1133                '_,
1134                fidl::encoding::DefaultFuchsiaResourceDialect,
1135            >,
1136            offset: usize,
1137            depth: fidl::encoding::Depth,
1138        ) -> fidl::Result<()> {
1139            encoder.debug_check_bounds::<DeviceDeriveRawSecretResponse>(offset);
1140            // Zero out padding regions. There's no need to apply masks
1141            // because the unmasked parts will be overwritten by fields.
1142            // Write the fields.
1143            self.0.encode(encoder, offset + 0, depth)?;
1144            Ok(())
1145        }
1146    }
1147
1148    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1149        for DeviceDeriveRawSecretResponse
1150    {
1151        #[inline(always)]
1152        fn new_empty() -> Self {
1153            Self {
1154                secret: fidl::new_empty!(
1155                    fidl::encoding::UnboundedVector<u8>,
1156                    fidl::encoding::DefaultFuchsiaResourceDialect
1157                ),
1158            }
1159        }
1160
1161        #[inline]
1162        unsafe fn decode(
1163            &mut self,
1164            decoder: &mut fidl::encoding::Decoder<
1165                '_,
1166                fidl::encoding::DefaultFuchsiaResourceDialect,
1167            >,
1168            offset: usize,
1169            _depth: fidl::encoding::Depth,
1170        ) -> fidl::Result<()> {
1171            decoder.debug_check_bounds::<Self>(offset);
1172            // Verify that padding bytes are zero.
1173            fidl::decode!(
1174                fidl::encoding::UnboundedVector<u8>,
1175                fidl::encoding::DefaultFuchsiaResourceDialect,
1176                &mut self.secret,
1177                decoder,
1178                offset + 0,
1179                _depth
1180            )?;
1181            Ok(())
1182        }
1183    }
1184}