Skip to main content

fidl_fuchsia_security_keymint/
fidl_fuchsia_security_keymint.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_security_keymint__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct AdminMarker;
16
17impl fidl::endpoints::ProtocolMarker for AdminMarker {
18    type Proxy = AdminProxy;
19    type RequestStream = AdminRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = AdminSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.security.keymint.Admin";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for AdminMarker {}
26pub type AdminDeleteAllKeysResult = Result<(), DeleteError>;
27
28pub trait AdminProxyInterface: Send + Sync {
29    type DeleteAllKeysResponseFut: std::future::Future<Output = Result<AdminDeleteAllKeysResult, fidl::Error>>
30        + Send;
31    fn r#delete_all_keys(&self) -> Self::DeleteAllKeysResponseFut;
32}
33#[derive(Debug)]
34#[cfg(target_os = "fuchsia")]
35pub struct AdminSynchronousProxy {
36    client: fidl::client::sync::Client,
37}
38
39#[cfg(target_os = "fuchsia")]
40impl fidl::endpoints::SynchronousProxy for AdminSynchronousProxy {
41    type Proxy = AdminProxy;
42    type Protocol = AdminMarker;
43
44    fn from_channel(inner: fidl::Channel) -> Self {
45        Self::new(inner)
46    }
47
48    fn into_channel(self) -> fidl::Channel {
49        self.client.into_channel()
50    }
51
52    fn as_channel(&self) -> &fidl::Channel {
53        self.client.as_channel()
54    }
55}
56
57#[cfg(target_os = "fuchsia")]
58impl AdminSynchronousProxy {
59    pub fn new(channel: fidl::Channel) -> Self {
60        Self { client: fidl::client::sync::Client::new(channel) }
61    }
62
63    pub fn into_channel(self) -> fidl::Channel {
64        self.client.into_channel()
65    }
66
67    /// Waits until an event arrives and returns it. It is safe for other
68    /// threads to make concurrent requests while waiting for an event.
69    pub fn wait_for_event(
70        &self,
71        deadline: zx::MonotonicInstant,
72    ) -> Result<AdminEvent, fidl::Error> {
73        AdminEvent::decode(self.client.wait_for_event::<AdminMarker>(deadline)?)
74    }
75
76    /// Deletes all keymint-managed keys that rely on TEE state. For example, keys tagged with
77    /// `Tag::ROLLBACK_RESISTANCE` may be rendered unusable due to bumping a securely managed
78    /// anti-rollback counter or keys tagged with `Tag::USER_SECURE_ID` may be rendered unusable
79    /// due to securely stored user ID bindings. The precise set of affected keys depends on the
80    /// TEE implementation supporting keymint.
81    pub fn r#delete_all_keys(
82        &self,
83        ___deadline: zx::MonotonicInstant,
84    ) -> Result<AdminDeleteAllKeysResult, fidl::Error> {
85        let _response = self.client.send_query::<
86            fidl::encoding::EmptyPayload,
87            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, DeleteError>,
88            AdminMarker,
89        >(
90            (),
91            0x7865f60b70087392,
92            fidl::encoding::DynamicFlags::empty(),
93            ___deadline,
94        )?;
95        Ok(_response.map(|x| x))
96    }
97}
98
99#[cfg(target_os = "fuchsia")]
100impl From<AdminSynchronousProxy> for zx::NullableHandle {
101    fn from(value: AdminSynchronousProxy) -> Self {
102        value.into_channel().into()
103    }
104}
105
106#[cfg(target_os = "fuchsia")]
107impl From<fidl::Channel> for AdminSynchronousProxy {
108    fn from(value: fidl::Channel) -> Self {
109        Self::new(value)
110    }
111}
112
113#[cfg(target_os = "fuchsia")]
114impl fidl::endpoints::FromClient for AdminSynchronousProxy {
115    type Protocol = AdminMarker;
116
117    fn from_client(value: fidl::endpoints::ClientEnd<AdminMarker>) -> Self {
118        Self::new(value.into_channel())
119    }
120}
121
122#[derive(Debug, Clone)]
123pub struct AdminProxy {
124    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
125}
126
127impl fidl::endpoints::Proxy for AdminProxy {
128    type Protocol = AdminMarker;
129
130    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
131        Self::new(inner)
132    }
133
134    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
135        self.client.into_channel().map_err(|client| Self { client })
136    }
137
138    fn as_channel(&self) -> &::fidl::AsyncChannel {
139        self.client.as_channel()
140    }
141}
142
143impl AdminProxy {
144    /// Create a new Proxy for fuchsia.security.keymint/Admin.
145    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
146        let protocol_name = <AdminMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
147        Self { client: fidl::client::Client::new(channel, protocol_name) }
148    }
149
150    /// Get a Stream of events from the remote end of the protocol.
151    ///
152    /// # Panics
153    ///
154    /// Panics if the event stream was already taken.
155    pub fn take_event_stream(&self) -> AdminEventStream {
156        AdminEventStream { event_receiver: self.client.take_event_receiver() }
157    }
158
159    /// Deletes all keymint-managed keys that rely on TEE state. For example, keys tagged with
160    /// `Tag::ROLLBACK_RESISTANCE` may be rendered unusable due to bumping a securely managed
161    /// anti-rollback counter or keys tagged with `Tag::USER_SECURE_ID` may be rendered unusable
162    /// due to securely stored user ID bindings. The precise set of affected keys depends on the
163    /// TEE implementation supporting keymint.
164    pub fn r#delete_all_keys(
165        &self,
166    ) -> fidl::client::QueryResponseFut<
167        AdminDeleteAllKeysResult,
168        fidl::encoding::DefaultFuchsiaResourceDialect,
169    > {
170        AdminProxyInterface::r#delete_all_keys(self)
171    }
172}
173
174impl AdminProxyInterface for AdminProxy {
175    type DeleteAllKeysResponseFut = fidl::client::QueryResponseFut<
176        AdminDeleteAllKeysResult,
177        fidl::encoding::DefaultFuchsiaResourceDialect,
178    >;
179    fn r#delete_all_keys(&self) -> Self::DeleteAllKeysResponseFut {
180        fn _decode(
181            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
182        ) -> Result<AdminDeleteAllKeysResult, fidl::Error> {
183            let _response = fidl::client::decode_transaction_body::<
184                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, DeleteError>,
185                fidl::encoding::DefaultFuchsiaResourceDialect,
186                0x7865f60b70087392,
187            >(_buf?)?;
188            Ok(_response.map(|x| x))
189        }
190        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, AdminDeleteAllKeysResult>(
191            (),
192            0x7865f60b70087392,
193            fidl::encoding::DynamicFlags::empty(),
194            _decode,
195        )
196    }
197}
198
199pub struct AdminEventStream {
200    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
201}
202
203impl std::marker::Unpin for AdminEventStream {}
204
205impl futures::stream::FusedStream for AdminEventStream {
206    fn is_terminated(&self) -> bool {
207        self.event_receiver.is_terminated()
208    }
209}
210
211impl futures::Stream for AdminEventStream {
212    type Item = Result<AdminEvent, fidl::Error>;
213
214    fn poll_next(
215        mut self: std::pin::Pin<&mut Self>,
216        cx: &mut std::task::Context<'_>,
217    ) -> std::task::Poll<Option<Self::Item>> {
218        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
219            &mut self.event_receiver,
220            cx
221        )?) {
222            Some(buf) => std::task::Poll::Ready(Some(AdminEvent::decode(buf))),
223            None => std::task::Poll::Ready(None),
224        }
225    }
226}
227
228#[derive(Debug)]
229pub enum AdminEvent {}
230
231impl AdminEvent {
232    /// Decodes a message buffer as a [`AdminEvent`].
233    fn decode(
234        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
235    ) -> Result<AdminEvent, fidl::Error> {
236        let (bytes, _handles) = buf.split_mut();
237        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
238        debug_assert_eq!(tx_header.tx_id, 0);
239        match tx_header.ordinal {
240            _ => Err(fidl::Error::UnknownOrdinal {
241                ordinal: tx_header.ordinal,
242                protocol_name: <AdminMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
243            }),
244        }
245    }
246}
247
248/// A Stream of incoming requests for fuchsia.security.keymint/Admin.
249pub struct AdminRequestStream {
250    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
251    is_terminated: bool,
252}
253
254impl std::marker::Unpin for AdminRequestStream {}
255
256impl futures::stream::FusedStream for AdminRequestStream {
257    fn is_terminated(&self) -> bool {
258        self.is_terminated
259    }
260}
261
262impl fidl::endpoints::RequestStream for AdminRequestStream {
263    type Protocol = AdminMarker;
264    type ControlHandle = AdminControlHandle;
265
266    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
267        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
268    }
269
270    fn control_handle(&self) -> Self::ControlHandle {
271        AdminControlHandle { inner: self.inner.clone() }
272    }
273
274    fn into_inner(
275        self,
276    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
277    {
278        (self.inner, self.is_terminated)
279    }
280
281    fn from_inner(
282        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
283        is_terminated: bool,
284    ) -> Self {
285        Self { inner, is_terminated }
286    }
287}
288
289impl futures::Stream for AdminRequestStream {
290    type Item = Result<AdminRequest, fidl::Error>;
291
292    fn poll_next(
293        mut self: std::pin::Pin<&mut Self>,
294        cx: &mut std::task::Context<'_>,
295    ) -> std::task::Poll<Option<Self::Item>> {
296        let this = &mut *self;
297        if this.inner.check_shutdown(cx) {
298            this.is_terminated = true;
299            return std::task::Poll::Ready(None);
300        }
301        if this.is_terminated {
302            panic!("polled AdminRequestStream after completion");
303        }
304        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
305            |bytes, handles| {
306                match this.inner.channel().read_etc(cx, bytes, handles) {
307                    std::task::Poll::Ready(Ok(())) => {}
308                    std::task::Poll::Pending => return std::task::Poll::Pending,
309                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
310                        this.is_terminated = true;
311                        return std::task::Poll::Ready(None);
312                    }
313                    std::task::Poll::Ready(Err(e)) => {
314                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
315                            e.into(),
316                        ))));
317                    }
318                }
319
320                // A message has been received from the channel
321                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
322
323                std::task::Poll::Ready(Some(match header.ordinal {
324                    0x7865f60b70087392 => {
325                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
326                        let mut req = fidl::new_empty!(
327                            fidl::encoding::EmptyPayload,
328                            fidl::encoding::DefaultFuchsiaResourceDialect
329                        );
330                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
331                        let control_handle = AdminControlHandle { inner: this.inner.clone() };
332                        Ok(AdminRequest::DeleteAllKeys {
333                            responder: AdminDeleteAllKeysResponder {
334                                control_handle: std::mem::ManuallyDrop::new(control_handle),
335                                tx_id: header.tx_id,
336                            },
337                        })
338                    }
339                    _ => Err(fidl::Error::UnknownOrdinal {
340                        ordinal: header.ordinal,
341                        protocol_name: <AdminMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
342                    }),
343                }))
344            },
345        )
346    }
347}
348
349/// Provides administrative operations for key management.
350#[derive(Debug)]
351pub enum AdminRequest {
352    /// Deletes all keymint-managed keys that rely on TEE state. For example, keys tagged with
353    /// `Tag::ROLLBACK_RESISTANCE` may be rendered unusable due to bumping a securely managed
354    /// anti-rollback counter or keys tagged with `Tag::USER_SECURE_ID` may be rendered unusable
355    /// due to securely stored user ID bindings. The precise set of affected keys depends on the
356    /// TEE implementation supporting keymint.
357    DeleteAllKeys { responder: AdminDeleteAllKeysResponder },
358}
359
360impl AdminRequest {
361    #[allow(irrefutable_let_patterns)]
362    pub fn into_delete_all_keys(self) -> Option<(AdminDeleteAllKeysResponder)> {
363        if let AdminRequest::DeleteAllKeys { responder } = self { Some((responder)) } else { None }
364    }
365
366    /// Name of the method defined in FIDL
367    pub fn method_name(&self) -> &'static str {
368        match *self {
369            AdminRequest::DeleteAllKeys { .. } => "delete_all_keys",
370        }
371    }
372}
373
374#[derive(Debug, Clone)]
375pub struct AdminControlHandle {
376    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
377}
378
379impl fidl::endpoints::ControlHandle for AdminControlHandle {
380    fn shutdown(&self) {
381        self.inner.shutdown()
382    }
383
384    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
385        self.inner.shutdown_with_epitaph(status)
386    }
387
388    fn is_closed(&self) -> bool {
389        self.inner.channel().is_closed()
390    }
391    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
392        self.inner.channel().on_closed()
393    }
394
395    #[cfg(target_os = "fuchsia")]
396    fn signal_peer(
397        &self,
398        clear_mask: zx::Signals,
399        set_mask: zx::Signals,
400    ) -> Result<(), zx_status::Status> {
401        use fidl::Peered;
402        self.inner.channel().signal_peer(clear_mask, set_mask)
403    }
404}
405
406impl AdminControlHandle {}
407
408#[must_use = "FIDL methods require a response to be sent"]
409#[derive(Debug)]
410pub struct AdminDeleteAllKeysResponder {
411    control_handle: std::mem::ManuallyDrop<AdminControlHandle>,
412    tx_id: u32,
413}
414
415/// Set the the channel to be shutdown (see [`AdminControlHandle::shutdown`])
416/// if the responder is dropped without sending a response, so that the client
417/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
418impl std::ops::Drop for AdminDeleteAllKeysResponder {
419    fn drop(&mut self) {
420        self.control_handle.shutdown();
421        // Safety: drops once, never accessed again
422        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
423    }
424}
425
426impl fidl::endpoints::Responder for AdminDeleteAllKeysResponder {
427    type ControlHandle = AdminControlHandle;
428
429    fn control_handle(&self) -> &AdminControlHandle {
430        &self.control_handle
431    }
432
433    fn drop_without_shutdown(mut self) {
434        // Safety: drops once, never accessed again due to mem::forget
435        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
436        // Prevent Drop from running (which would shut down the channel)
437        std::mem::forget(self);
438    }
439}
440
441impl AdminDeleteAllKeysResponder {
442    /// Sends a response to the FIDL transaction.
443    ///
444    /// Sets the channel to shutdown if an error occurs.
445    pub fn send(self, mut result: Result<(), DeleteError>) -> Result<(), fidl::Error> {
446        let _result = self.send_raw(result);
447        if _result.is_err() {
448            self.control_handle.shutdown();
449        }
450        self.drop_without_shutdown();
451        _result
452    }
453
454    /// Similar to "send" but does not shutdown the channel if an error occurs.
455    pub fn send_no_shutdown_on_err(
456        self,
457        mut result: Result<(), DeleteError>,
458    ) -> Result<(), fidl::Error> {
459        let _result = self.send_raw(result);
460        self.drop_without_shutdown();
461        _result
462    }
463
464    fn send_raw(&self, mut result: Result<(), DeleteError>) -> Result<(), fidl::Error> {
465        self.control_handle.inner.send::<fidl::encoding::ResultType<
466            fidl::encoding::EmptyStruct,
467            DeleteError,
468        >>(
469            result,
470            self.tx_id,
471            0x7865f60b70087392,
472            fidl::encoding::DynamicFlags::empty(),
473        )
474    }
475}
476
477#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
478pub struct SealingKeysMarker;
479
480impl fidl::endpoints::ProtocolMarker for SealingKeysMarker {
481    type Proxy = SealingKeysProxy;
482    type RequestStream = SealingKeysRequestStream;
483    #[cfg(target_os = "fuchsia")]
484    type SynchronousProxy = SealingKeysSynchronousProxy;
485
486    const DEBUG_NAME: &'static str = "fuchsia.security.keymint.SealingKeys";
487}
488impl fidl::endpoints::DiscoverableProtocolMarker for SealingKeysMarker {}
489pub type SealingKeysCreateSealingKeyResult = Result<Vec<u8>, CreateError>;
490pub type SealingKeysSealResult = Result<Vec<u8>, SealError>;
491pub type SealingKeysUnsealResult = Result<Vec<u8>, UnsealError>;
492pub type SealingKeysUpgradeSealingKeyResult = Result<Vec<u8>, UpgradeError>;
493pub type SealingKeysDeleteSealingKeyResult = Result<(), DeleteError>;
494
495pub trait SealingKeysProxyInterface: Send + Sync {
496    type CreateSealingKeyResponseFut: std::future::Future<Output = Result<SealingKeysCreateSealingKeyResult, fidl::Error>>
497        + Send;
498    fn r#create_sealing_key(&self, key_info: &[u8]) -> Self::CreateSealingKeyResponseFut;
499    type SealResponseFut: std::future::Future<Output = Result<SealingKeysSealResult, fidl::Error>>
500        + Send;
501    fn r#seal(&self, key_info: &[u8], key_blob: &[u8], secret: &[u8]) -> Self::SealResponseFut;
502    type UnsealResponseFut: std::future::Future<Output = Result<SealingKeysUnsealResult, fidl::Error>>
503        + Send;
504    fn r#unseal(
505        &self,
506        key_info: &[u8],
507        key_blob: &[u8],
508        sealed_secret: &[u8],
509    ) -> Self::UnsealResponseFut;
510    type UpgradeSealingKeyResponseFut: std::future::Future<Output = Result<SealingKeysUpgradeSealingKeyResult, fidl::Error>>
511        + Send;
512    fn r#upgrade_sealing_key(
513        &self,
514        key_info: &[u8],
515        key_blob: &[u8],
516    ) -> Self::UpgradeSealingKeyResponseFut;
517    type DeleteSealingKeyResponseFut: std::future::Future<Output = Result<SealingKeysDeleteSealingKeyResult, fidl::Error>>
518        + Send;
519    fn r#delete_sealing_key(&self, key_blob: &[u8]) -> Self::DeleteSealingKeyResponseFut;
520}
521#[derive(Debug)]
522#[cfg(target_os = "fuchsia")]
523pub struct SealingKeysSynchronousProxy {
524    client: fidl::client::sync::Client,
525}
526
527#[cfg(target_os = "fuchsia")]
528impl fidl::endpoints::SynchronousProxy for SealingKeysSynchronousProxy {
529    type Proxy = SealingKeysProxy;
530    type Protocol = SealingKeysMarker;
531
532    fn from_channel(inner: fidl::Channel) -> Self {
533        Self::new(inner)
534    }
535
536    fn into_channel(self) -> fidl::Channel {
537        self.client.into_channel()
538    }
539
540    fn as_channel(&self) -> &fidl::Channel {
541        self.client.as_channel()
542    }
543}
544
545#[cfg(target_os = "fuchsia")]
546impl SealingKeysSynchronousProxy {
547    pub fn new(channel: fidl::Channel) -> Self {
548        Self { client: fidl::client::sync::Client::new(channel) }
549    }
550
551    pub fn into_channel(self) -> fidl::Channel {
552        self.client.into_channel()
553    }
554
555    /// Waits until an event arrives and returns it. It is safe for other
556    /// threads to make concurrent requests while waiting for an event.
557    pub fn wait_for_event(
558        &self,
559        deadline: zx::MonotonicInstant,
560    ) -> Result<SealingKeysEvent, fidl::Error> {
561        SealingKeysEvent::decode(self.client.wait_for_event::<SealingKeysMarker>(deadline)?)
562    }
563
564    /// Generates a new sealing key to seal and unseal secrets.
565    ///
566    /// |key_info| is information to be cryptographically bound to the returned key.
567    ///   * The client will have to supply it in all uses (other than key deletion) of the returned
568    ///     key.
569    ///   * It serves two purposes: (1) internally by the key manager to identify the key owner and
570    ///     (2) as a password to mitigate potential attacks from the key manager and as well as
571    ///     other clients.
572    ///   * It is recommended to include sufficient entropy in it (using it as a password) to
573    ///     mitigage potential attacks from the secure world (the key manager's execution
574    ///     environment) or from other clients.
575    ///   * It is acceptible to pass a constant if deriving and persisting a password is too
576    ///     cumbersome and the client fully trust the secure world and there are not many other
577    ///     clients.
578    ///
579    /// The client is responsible for persisting both |key_info| and the returned |key_blob|.
580    /// The key blob is encrypted with a TEE-private key. It is guaranteed to be unique for each
581    /// call (even with the same key info). It can be stored in unsecure storage.
582    ///
583    /// Returns:
584    ///   * The sealing key if everything worked.
585    ///   * FAILED_CREATE if the key creation failed, e.g., the |key_info| was empty.
586    pub fn r#create_sealing_key(
587        &self,
588        mut key_info: &[u8],
589        ___deadline: zx::MonotonicInstant,
590    ) -> Result<SealingKeysCreateSealingKeyResult, fidl::Error> {
591        let _response = self.client.send_query::<
592            SealingKeysCreateSealingKeyRequest,
593            fidl::encoding::ResultType<SealingKeysCreateSealingKeyResponse, CreateError>,
594            SealingKeysMarker,
595        >(
596            (key_info,),
597            0x5a191cbb6a8081bc,
598            fidl::encoding::DynamicFlags::empty(),
599            ___deadline,
600        )?;
601        Ok(_response.map(|x| x.key_blob))
602    }
603
604    /// Seals a secret using a sealing key identified by its info and blob:
605    ///   * The key info has to match the one supplied when generating the sealing key.
606    ///
607    /// Note that the secret may be a key itself. It has no bearing on the seal operation.
608    ///
609    /// Returns:
610    ///   * The sealed secret if everything worked.
611    ///   * KEY_REQUIRES_UPGRADE if keymint indicates that the sealing key requires upgrade.
612    ///   * FAILED_SEAL if the sealing failed for another reason, e.g., sealing key info or blob
613    ///     mismatch.
614    pub fn r#seal(
615        &self,
616        mut key_info: &[u8],
617        mut key_blob: &[u8],
618        mut secret: &[u8],
619        ___deadline: zx::MonotonicInstant,
620    ) -> Result<SealingKeysSealResult, fidl::Error> {
621        let _response = self.client.send_query::<
622            SealingKeysSealRequest,
623            fidl::encoding::ResultType<SealingKeysSealResponse, SealError>,
624            SealingKeysMarker,
625        >(
626            (key_info, key_blob, secret,),
627            0x10d41255013918d1,
628            fidl::encoding::DynamicFlags::empty(),
629            ___deadline,
630        )?;
631        Ok(_response.map(|x| x.sealed_secret))
632    }
633
634    /// Unseals a sealed secret using a sealing key identified by its info and blob:
635    ///   * The key info has to match the one supplied when generating the sealing key.
636    ///   * The key blob has to match the one used to seal the secret.
637    ///
638    /// Note that the secret may be a key itself. It has no bearing on the unseal operation.
639    ///
640    /// Returns:
641    ///   * The unsealed secret if everything worked.
642    ///   * KEY_REQUIRES_UPGRADE if keymint indicates that the sealing key requires upgrade.
643    ///   * FAILED_UNSEAL if the unsealing failed for another reason, e.g., sealing key info or blob
644    ///     mismatch.
645    pub fn r#unseal(
646        &self,
647        mut key_info: &[u8],
648        mut key_blob: &[u8],
649        mut sealed_secret: &[u8],
650        ___deadline: zx::MonotonicInstant,
651    ) -> Result<SealingKeysUnsealResult, fidl::Error> {
652        let _response = self.client.send_query::<
653            SealingKeysUnsealRequest,
654            fidl::encoding::ResultType<SealingKeysUnsealResponse, UnsealError>,
655            SealingKeysMarker,
656        >(
657            (key_info, key_blob, sealed_secret,),
658            0x7037d75ecb579c83,
659            fidl::encoding::DynamicFlags::empty(),
660            ___deadline,
661        )?;
662        Ok(_response.map(|x| x.unsealed_secret))
663    }
664
665    /// Upgrades a sealing key that has been deemed out-of-date by keymint. The sealing key to
666    /// upgrade is identified by its info and blob:
667    ///   * The key info has to match the one supplied when generating the sealing key.
668    ///   * The key blob has to match the blob returned when generating the sealing key.
669    ///
670    /// Note that after upgrading a key, both the old key and new key will be occupying limited key
671    /// storage in keymint. This means that clients can unintentionally exhaust key storage in two
672    /// ways:
673    /// * Upgrading a key and failing to delete the old key after upgrade.
674    /// * Successfully upgrading a key, failing to persist the new key, and later (e.g., after a
675    ///   reboot) upgrading the key again.
676    ///
677    /// Both of the above missteps on the part of the client will "waste" one key slot in keymint,
678    /// and repeated missteps (e.g., a boot loop that upgrades a key, fails to persist the new key,
679    /// then reboots) can exhaust available key storage. Clients are responsible for old (upgraded)
680    /// keys and persisting new (result of a successful key upgrade) to ensure that key slots are
681    /// not wasted.
682    ///
683    ///  Returns
684    ///   * The upgraded key blob if everything worked.
685    ///   * FAILED_UPGRADE if the upgrade failed.
686    pub fn r#upgrade_sealing_key(
687        &self,
688        mut key_info: &[u8],
689        mut key_blob: &[u8],
690        ___deadline: zx::MonotonicInstant,
691    ) -> Result<SealingKeysUpgradeSealingKeyResult, fidl::Error> {
692        let _response = self.client.send_query::<
693            SealingKeysUpgradeSealingKeyRequest,
694            fidl::encoding::ResultType<SealingKeysUpgradeSealingKeyResponse, UpgradeError>,
695            SealingKeysMarker,
696        >(
697            (key_info, key_blob,),
698            0x68584c5a799181e7,
699            fidl::encoding::DynamicFlags::empty(),
700            ___deadline,
701        )?;
702        Ok(_response.map(|x| x.key_blob))
703    }
704
705    /// Deletes a sealing key from keymint.
706    ///
707    /// This operation should be used to delete old (upgraded) keys.
708    ///
709    /// Returns
710    ///  * Nothing if everything worked.
711    ///  * FAILED_DELETE if deletion failed.
712    pub fn r#delete_sealing_key(
713        &self,
714        mut key_blob: &[u8],
715        ___deadline: zx::MonotonicInstant,
716    ) -> Result<SealingKeysDeleteSealingKeyResult, fidl::Error> {
717        let _response = self.client.send_query::<
718            SealingKeysDeleteSealingKeyRequest,
719            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, DeleteError>,
720            SealingKeysMarker,
721        >(
722            (key_blob,),
723            0xad65bae761e8c3,
724            fidl::encoding::DynamicFlags::empty(),
725            ___deadline,
726        )?;
727        Ok(_response.map(|x| x))
728    }
729}
730
731#[cfg(target_os = "fuchsia")]
732impl From<SealingKeysSynchronousProxy> for zx::NullableHandle {
733    fn from(value: SealingKeysSynchronousProxy) -> Self {
734        value.into_channel().into()
735    }
736}
737
738#[cfg(target_os = "fuchsia")]
739impl From<fidl::Channel> for SealingKeysSynchronousProxy {
740    fn from(value: fidl::Channel) -> Self {
741        Self::new(value)
742    }
743}
744
745#[cfg(target_os = "fuchsia")]
746impl fidl::endpoints::FromClient for SealingKeysSynchronousProxy {
747    type Protocol = SealingKeysMarker;
748
749    fn from_client(value: fidl::endpoints::ClientEnd<SealingKeysMarker>) -> Self {
750        Self::new(value.into_channel())
751    }
752}
753
754#[derive(Debug, Clone)]
755pub struct SealingKeysProxy {
756    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
757}
758
759impl fidl::endpoints::Proxy for SealingKeysProxy {
760    type Protocol = SealingKeysMarker;
761
762    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
763        Self::new(inner)
764    }
765
766    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
767        self.client.into_channel().map_err(|client| Self { client })
768    }
769
770    fn as_channel(&self) -> &::fidl::AsyncChannel {
771        self.client.as_channel()
772    }
773}
774
775impl SealingKeysProxy {
776    /// Create a new Proxy for fuchsia.security.keymint/SealingKeys.
777    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
778        let protocol_name = <SealingKeysMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
779        Self { client: fidl::client::Client::new(channel, protocol_name) }
780    }
781
782    /// Get a Stream of events from the remote end of the protocol.
783    ///
784    /// # Panics
785    ///
786    /// Panics if the event stream was already taken.
787    pub fn take_event_stream(&self) -> SealingKeysEventStream {
788        SealingKeysEventStream { event_receiver: self.client.take_event_receiver() }
789    }
790
791    /// Generates a new sealing key to seal and unseal secrets.
792    ///
793    /// |key_info| is information to be cryptographically bound to the returned key.
794    ///   * The client will have to supply it in all uses (other than key deletion) of the returned
795    ///     key.
796    ///   * It serves two purposes: (1) internally by the key manager to identify the key owner and
797    ///     (2) as a password to mitigate potential attacks from the key manager and as well as
798    ///     other clients.
799    ///   * It is recommended to include sufficient entropy in it (using it as a password) to
800    ///     mitigage potential attacks from the secure world (the key manager's execution
801    ///     environment) or from other clients.
802    ///   * It is acceptible to pass a constant if deriving and persisting a password is too
803    ///     cumbersome and the client fully trust the secure world and there are not many other
804    ///     clients.
805    ///
806    /// The client is responsible for persisting both |key_info| and the returned |key_blob|.
807    /// The key blob is encrypted with a TEE-private key. It is guaranteed to be unique for each
808    /// call (even with the same key info). It can be stored in unsecure storage.
809    ///
810    /// Returns:
811    ///   * The sealing key if everything worked.
812    ///   * FAILED_CREATE if the key creation failed, e.g., the |key_info| was empty.
813    pub fn r#create_sealing_key(
814        &self,
815        mut key_info: &[u8],
816    ) -> fidl::client::QueryResponseFut<
817        SealingKeysCreateSealingKeyResult,
818        fidl::encoding::DefaultFuchsiaResourceDialect,
819    > {
820        SealingKeysProxyInterface::r#create_sealing_key(self, key_info)
821    }
822
823    /// Seals a secret using a sealing key identified by its info and blob:
824    ///   * The key info has to match the one supplied when generating the sealing key.
825    ///
826    /// Note that the secret may be a key itself. It has no bearing on the seal operation.
827    ///
828    /// Returns:
829    ///   * The sealed secret if everything worked.
830    ///   * KEY_REQUIRES_UPGRADE if keymint indicates that the sealing key requires upgrade.
831    ///   * FAILED_SEAL if the sealing failed for another reason, e.g., sealing key info or blob
832    ///     mismatch.
833    pub fn r#seal(
834        &self,
835        mut key_info: &[u8],
836        mut key_blob: &[u8],
837        mut secret: &[u8],
838    ) -> fidl::client::QueryResponseFut<
839        SealingKeysSealResult,
840        fidl::encoding::DefaultFuchsiaResourceDialect,
841    > {
842        SealingKeysProxyInterface::r#seal(self, key_info, key_blob, secret)
843    }
844
845    /// Unseals a sealed secret using a sealing key identified by its info and blob:
846    ///   * The key info has to match the one supplied when generating the sealing key.
847    ///   * The key blob has to match the one used to seal the secret.
848    ///
849    /// Note that the secret may be a key itself. It has no bearing on the unseal operation.
850    ///
851    /// Returns:
852    ///   * The unsealed secret if everything worked.
853    ///   * KEY_REQUIRES_UPGRADE if keymint indicates that the sealing key requires upgrade.
854    ///   * FAILED_UNSEAL if the unsealing failed for another reason, e.g., sealing key info or blob
855    ///     mismatch.
856    pub fn r#unseal(
857        &self,
858        mut key_info: &[u8],
859        mut key_blob: &[u8],
860        mut sealed_secret: &[u8],
861    ) -> fidl::client::QueryResponseFut<
862        SealingKeysUnsealResult,
863        fidl::encoding::DefaultFuchsiaResourceDialect,
864    > {
865        SealingKeysProxyInterface::r#unseal(self, key_info, key_blob, sealed_secret)
866    }
867
868    /// Upgrades a sealing key that has been deemed out-of-date by keymint. The sealing key to
869    /// upgrade is identified by its info and blob:
870    ///   * The key info has to match the one supplied when generating the sealing key.
871    ///   * The key blob has to match the blob returned when generating the sealing key.
872    ///
873    /// Note that after upgrading a key, both the old key and new key will be occupying limited key
874    /// storage in keymint. This means that clients can unintentionally exhaust key storage in two
875    /// ways:
876    /// * Upgrading a key and failing to delete the old key after upgrade.
877    /// * Successfully upgrading a key, failing to persist the new key, and later (e.g., after a
878    ///   reboot) upgrading the key again.
879    ///
880    /// Both of the above missteps on the part of the client will "waste" one key slot in keymint,
881    /// and repeated missteps (e.g., a boot loop that upgrades a key, fails to persist the new key,
882    /// then reboots) can exhaust available key storage. Clients are responsible for old (upgraded)
883    /// keys and persisting new (result of a successful key upgrade) to ensure that key slots are
884    /// not wasted.
885    ///
886    ///  Returns
887    ///   * The upgraded key blob if everything worked.
888    ///   * FAILED_UPGRADE if the upgrade failed.
889    pub fn r#upgrade_sealing_key(
890        &self,
891        mut key_info: &[u8],
892        mut key_blob: &[u8],
893    ) -> fidl::client::QueryResponseFut<
894        SealingKeysUpgradeSealingKeyResult,
895        fidl::encoding::DefaultFuchsiaResourceDialect,
896    > {
897        SealingKeysProxyInterface::r#upgrade_sealing_key(self, key_info, key_blob)
898    }
899
900    /// Deletes a sealing key from keymint.
901    ///
902    /// This operation should be used to delete old (upgraded) keys.
903    ///
904    /// Returns
905    ///  * Nothing if everything worked.
906    ///  * FAILED_DELETE if deletion failed.
907    pub fn r#delete_sealing_key(
908        &self,
909        mut key_blob: &[u8],
910    ) -> fidl::client::QueryResponseFut<
911        SealingKeysDeleteSealingKeyResult,
912        fidl::encoding::DefaultFuchsiaResourceDialect,
913    > {
914        SealingKeysProxyInterface::r#delete_sealing_key(self, key_blob)
915    }
916}
917
918impl SealingKeysProxyInterface for SealingKeysProxy {
919    type CreateSealingKeyResponseFut = fidl::client::QueryResponseFut<
920        SealingKeysCreateSealingKeyResult,
921        fidl::encoding::DefaultFuchsiaResourceDialect,
922    >;
923    fn r#create_sealing_key(&self, mut key_info: &[u8]) -> Self::CreateSealingKeyResponseFut {
924        fn _decode(
925            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
926        ) -> Result<SealingKeysCreateSealingKeyResult, fidl::Error> {
927            let _response = fidl::client::decode_transaction_body::<
928                fidl::encoding::ResultType<SealingKeysCreateSealingKeyResponse, CreateError>,
929                fidl::encoding::DefaultFuchsiaResourceDialect,
930                0x5a191cbb6a8081bc,
931            >(_buf?)?;
932            Ok(_response.map(|x| x.key_blob))
933        }
934        self.client.send_query_and_decode::<
935            SealingKeysCreateSealingKeyRequest,
936            SealingKeysCreateSealingKeyResult,
937        >(
938            (key_info,),
939            0x5a191cbb6a8081bc,
940            fidl::encoding::DynamicFlags::empty(),
941            _decode,
942        )
943    }
944
945    type SealResponseFut = fidl::client::QueryResponseFut<
946        SealingKeysSealResult,
947        fidl::encoding::DefaultFuchsiaResourceDialect,
948    >;
949    fn r#seal(
950        &self,
951        mut key_info: &[u8],
952        mut key_blob: &[u8],
953        mut secret: &[u8],
954    ) -> Self::SealResponseFut {
955        fn _decode(
956            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
957        ) -> Result<SealingKeysSealResult, fidl::Error> {
958            let _response = fidl::client::decode_transaction_body::<
959                fidl::encoding::ResultType<SealingKeysSealResponse, SealError>,
960                fidl::encoding::DefaultFuchsiaResourceDialect,
961                0x10d41255013918d1,
962            >(_buf?)?;
963            Ok(_response.map(|x| x.sealed_secret))
964        }
965        self.client.send_query_and_decode::<SealingKeysSealRequest, SealingKeysSealResult>(
966            (key_info, key_blob, secret),
967            0x10d41255013918d1,
968            fidl::encoding::DynamicFlags::empty(),
969            _decode,
970        )
971    }
972
973    type UnsealResponseFut = fidl::client::QueryResponseFut<
974        SealingKeysUnsealResult,
975        fidl::encoding::DefaultFuchsiaResourceDialect,
976    >;
977    fn r#unseal(
978        &self,
979        mut key_info: &[u8],
980        mut key_blob: &[u8],
981        mut sealed_secret: &[u8],
982    ) -> Self::UnsealResponseFut {
983        fn _decode(
984            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
985        ) -> Result<SealingKeysUnsealResult, fidl::Error> {
986            let _response = fidl::client::decode_transaction_body::<
987                fidl::encoding::ResultType<SealingKeysUnsealResponse, UnsealError>,
988                fidl::encoding::DefaultFuchsiaResourceDialect,
989                0x7037d75ecb579c83,
990            >(_buf?)?;
991            Ok(_response.map(|x| x.unsealed_secret))
992        }
993        self.client.send_query_and_decode::<SealingKeysUnsealRequest, SealingKeysUnsealResult>(
994            (key_info, key_blob, sealed_secret),
995            0x7037d75ecb579c83,
996            fidl::encoding::DynamicFlags::empty(),
997            _decode,
998        )
999    }
1000
1001    type UpgradeSealingKeyResponseFut = fidl::client::QueryResponseFut<
1002        SealingKeysUpgradeSealingKeyResult,
1003        fidl::encoding::DefaultFuchsiaResourceDialect,
1004    >;
1005    fn r#upgrade_sealing_key(
1006        &self,
1007        mut key_info: &[u8],
1008        mut key_blob: &[u8],
1009    ) -> Self::UpgradeSealingKeyResponseFut {
1010        fn _decode(
1011            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1012        ) -> Result<SealingKeysUpgradeSealingKeyResult, fidl::Error> {
1013            let _response = fidl::client::decode_transaction_body::<
1014                fidl::encoding::ResultType<SealingKeysUpgradeSealingKeyResponse, UpgradeError>,
1015                fidl::encoding::DefaultFuchsiaResourceDialect,
1016                0x68584c5a799181e7,
1017            >(_buf?)?;
1018            Ok(_response.map(|x| x.key_blob))
1019        }
1020        self.client.send_query_and_decode::<
1021            SealingKeysUpgradeSealingKeyRequest,
1022            SealingKeysUpgradeSealingKeyResult,
1023        >(
1024            (key_info, key_blob,),
1025            0x68584c5a799181e7,
1026            fidl::encoding::DynamicFlags::empty(),
1027            _decode,
1028        )
1029    }
1030
1031    type DeleteSealingKeyResponseFut = fidl::client::QueryResponseFut<
1032        SealingKeysDeleteSealingKeyResult,
1033        fidl::encoding::DefaultFuchsiaResourceDialect,
1034    >;
1035    fn r#delete_sealing_key(&self, mut key_blob: &[u8]) -> Self::DeleteSealingKeyResponseFut {
1036        fn _decode(
1037            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1038        ) -> Result<SealingKeysDeleteSealingKeyResult, fidl::Error> {
1039            let _response = fidl::client::decode_transaction_body::<
1040                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, DeleteError>,
1041                fidl::encoding::DefaultFuchsiaResourceDialect,
1042                0xad65bae761e8c3,
1043            >(_buf?)?;
1044            Ok(_response.map(|x| x))
1045        }
1046        self.client.send_query_and_decode::<
1047            SealingKeysDeleteSealingKeyRequest,
1048            SealingKeysDeleteSealingKeyResult,
1049        >(
1050            (key_blob,),
1051            0xad65bae761e8c3,
1052            fidl::encoding::DynamicFlags::empty(),
1053            _decode,
1054        )
1055    }
1056}
1057
1058pub struct SealingKeysEventStream {
1059    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1060}
1061
1062impl std::marker::Unpin for SealingKeysEventStream {}
1063
1064impl futures::stream::FusedStream for SealingKeysEventStream {
1065    fn is_terminated(&self) -> bool {
1066        self.event_receiver.is_terminated()
1067    }
1068}
1069
1070impl futures::Stream for SealingKeysEventStream {
1071    type Item = Result<SealingKeysEvent, fidl::Error>;
1072
1073    fn poll_next(
1074        mut self: std::pin::Pin<&mut Self>,
1075        cx: &mut std::task::Context<'_>,
1076    ) -> std::task::Poll<Option<Self::Item>> {
1077        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1078            &mut self.event_receiver,
1079            cx
1080        )?) {
1081            Some(buf) => std::task::Poll::Ready(Some(SealingKeysEvent::decode(buf))),
1082            None => std::task::Poll::Ready(None),
1083        }
1084    }
1085}
1086
1087#[derive(Debug)]
1088pub enum SealingKeysEvent {}
1089
1090impl SealingKeysEvent {
1091    /// Decodes a message buffer as a [`SealingKeysEvent`].
1092    fn decode(
1093        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1094    ) -> Result<SealingKeysEvent, fidl::Error> {
1095        let (bytes, _handles) = buf.split_mut();
1096        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1097        debug_assert_eq!(tx_header.tx_id, 0);
1098        match tx_header.ordinal {
1099            _ => Err(fidl::Error::UnknownOrdinal {
1100                ordinal: tx_header.ordinal,
1101                protocol_name: <SealingKeysMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1102            }),
1103        }
1104    }
1105}
1106
1107/// A Stream of incoming requests for fuchsia.security.keymint/SealingKeys.
1108pub struct SealingKeysRequestStream {
1109    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1110    is_terminated: bool,
1111}
1112
1113impl std::marker::Unpin for SealingKeysRequestStream {}
1114
1115impl futures::stream::FusedStream for SealingKeysRequestStream {
1116    fn is_terminated(&self) -> bool {
1117        self.is_terminated
1118    }
1119}
1120
1121impl fidl::endpoints::RequestStream for SealingKeysRequestStream {
1122    type Protocol = SealingKeysMarker;
1123    type ControlHandle = SealingKeysControlHandle;
1124
1125    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1126        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1127    }
1128
1129    fn control_handle(&self) -> Self::ControlHandle {
1130        SealingKeysControlHandle { inner: self.inner.clone() }
1131    }
1132
1133    fn into_inner(
1134        self,
1135    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1136    {
1137        (self.inner, self.is_terminated)
1138    }
1139
1140    fn from_inner(
1141        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1142        is_terminated: bool,
1143    ) -> Self {
1144        Self { inner, is_terminated }
1145    }
1146}
1147
1148impl futures::Stream for SealingKeysRequestStream {
1149    type Item = Result<SealingKeysRequest, fidl::Error>;
1150
1151    fn poll_next(
1152        mut self: std::pin::Pin<&mut Self>,
1153        cx: &mut std::task::Context<'_>,
1154    ) -> std::task::Poll<Option<Self::Item>> {
1155        let this = &mut *self;
1156        if this.inner.check_shutdown(cx) {
1157            this.is_terminated = true;
1158            return std::task::Poll::Ready(None);
1159        }
1160        if this.is_terminated {
1161            panic!("polled SealingKeysRequestStream after completion");
1162        }
1163        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1164            |bytes, handles| {
1165                match this.inner.channel().read_etc(cx, bytes, handles) {
1166                    std::task::Poll::Ready(Ok(())) => {}
1167                    std::task::Poll::Pending => return std::task::Poll::Pending,
1168                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1169                        this.is_terminated = true;
1170                        return std::task::Poll::Ready(None);
1171                    }
1172                    std::task::Poll::Ready(Err(e)) => {
1173                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1174                            e.into(),
1175                        ))));
1176                    }
1177                }
1178
1179                // A message has been received from the channel
1180                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1181
1182                std::task::Poll::Ready(Some(match header.ordinal {
1183                    0x5a191cbb6a8081bc => {
1184                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1185                        let mut req = fidl::new_empty!(
1186                            SealingKeysCreateSealingKeyRequest,
1187                            fidl::encoding::DefaultFuchsiaResourceDialect
1188                        );
1189                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SealingKeysCreateSealingKeyRequest>(&header, _body_bytes, handles, &mut req)?;
1190                        let control_handle = SealingKeysControlHandle { inner: this.inner.clone() };
1191                        Ok(SealingKeysRequest::CreateSealingKey {
1192                            key_info: req.key_info,
1193
1194                            responder: SealingKeysCreateSealingKeyResponder {
1195                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1196                                tx_id: header.tx_id,
1197                            },
1198                        })
1199                    }
1200                    0x10d41255013918d1 => {
1201                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1202                        let mut req = fidl::new_empty!(
1203                            SealingKeysSealRequest,
1204                            fidl::encoding::DefaultFuchsiaResourceDialect
1205                        );
1206                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SealingKeysSealRequest>(&header, _body_bytes, handles, &mut req)?;
1207                        let control_handle = SealingKeysControlHandle { inner: this.inner.clone() };
1208                        Ok(SealingKeysRequest::Seal {
1209                            key_info: req.key_info,
1210                            key_blob: req.key_blob,
1211                            secret: req.secret,
1212
1213                            responder: SealingKeysSealResponder {
1214                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1215                                tx_id: header.tx_id,
1216                            },
1217                        })
1218                    }
1219                    0x7037d75ecb579c83 => {
1220                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1221                        let mut req = fidl::new_empty!(
1222                            SealingKeysUnsealRequest,
1223                            fidl::encoding::DefaultFuchsiaResourceDialect
1224                        );
1225                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SealingKeysUnsealRequest>(&header, _body_bytes, handles, &mut req)?;
1226                        let control_handle = SealingKeysControlHandle { inner: this.inner.clone() };
1227                        Ok(SealingKeysRequest::Unseal {
1228                            key_info: req.key_info,
1229                            key_blob: req.key_blob,
1230                            sealed_secret: req.sealed_secret,
1231
1232                            responder: SealingKeysUnsealResponder {
1233                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1234                                tx_id: header.tx_id,
1235                            },
1236                        })
1237                    }
1238                    0x68584c5a799181e7 => {
1239                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1240                        let mut req = fidl::new_empty!(
1241                            SealingKeysUpgradeSealingKeyRequest,
1242                            fidl::encoding::DefaultFuchsiaResourceDialect
1243                        );
1244                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SealingKeysUpgradeSealingKeyRequest>(&header, _body_bytes, handles, &mut req)?;
1245                        let control_handle = SealingKeysControlHandle { inner: this.inner.clone() };
1246                        Ok(SealingKeysRequest::UpgradeSealingKey {
1247                            key_info: req.key_info,
1248                            key_blob: req.key_blob,
1249
1250                            responder: SealingKeysUpgradeSealingKeyResponder {
1251                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1252                                tx_id: header.tx_id,
1253                            },
1254                        })
1255                    }
1256                    0xad65bae761e8c3 => {
1257                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1258                        let mut req = fidl::new_empty!(
1259                            SealingKeysDeleteSealingKeyRequest,
1260                            fidl::encoding::DefaultFuchsiaResourceDialect
1261                        );
1262                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SealingKeysDeleteSealingKeyRequest>(&header, _body_bytes, handles, &mut req)?;
1263                        let control_handle = SealingKeysControlHandle { inner: this.inner.clone() };
1264                        Ok(SealingKeysRequest::DeleteSealingKey {
1265                            key_blob: req.key_blob,
1266
1267                            responder: SealingKeysDeleteSealingKeyResponder {
1268                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1269                                tx_id: header.tx_id,
1270                            },
1271                        })
1272                    }
1273                    _ => Err(fidl::Error::UnknownOrdinal {
1274                        ordinal: header.ordinal,
1275                        protocol_name:
1276                            <SealingKeysMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1277                    }),
1278                }))
1279            },
1280        )
1281    }
1282}
1283
1284/// Allows a client to generate sealing keys and then use these keys to seal and unseal secrets.
1285/// Sealed secrets are safe for offline storage.
1286///
1287/// Note that (un)seal is synonymous with (un)wrap, e.g., wrapping an encryption key is the same
1288/// as sealing an encryption key.
1289#[derive(Debug)]
1290pub enum SealingKeysRequest {
1291    /// Generates a new sealing key to seal and unseal secrets.
1292    ///
1293    /// |key_info| is information to be cryptographically bound to the returned key.
1294    ///   * The client will have to supply it in all uses (other than key deletion) of the returned
1295    ///     key.
1296    ///   * It serves two purposes: (1) internally by the key manager to identify the key owner and
1297    ///     (2) as a password to mitigate potential attacks from the key manager and as well as
1298    ///     other clients.
1299    ///   * It is recommended to include sufficient entropy in it (using it as a password) to
1300    ///     mitigage potential attacks from the secure world (the key manager's execution
1301    ///     environment) or from other clients.
1302    ///   * It is acceptible to pass a constant if deriving and persisting a password is too
1303    ///     cumbersome and the client fully trust the secure world and there are not many other
1304    ///     clients.
1305    ///
1306    /// The client is responsible for persisting both |key_info| and the returned |key_blob|.
1307    /// The key blob is encrypted with a TEE-private key. It is guaranteed to be unique for each
1308    /// call (even with the same key info). It can be stored in unsecure storage.
1309    ///
1310    /// Returns:
1311    ///   * The sealing key if everything worked.
1312    ///   * FAILED_CREATE if the key creation failed, e.g., the |key_info| was empty.
1313    CreateSealingKey { key_info: Vec<u8>, responder: SealingKeysCreateSealingKeyResponder },
1314    /// Seals a secret using a sealing key identified by its info and blob:
1315    ///   * The key info has to match the one supplied when generating the sealing key.
1316    ///
1317    /// Note that the secret may be a key itself. It has no bearing on the seal operation.
1318    ///
1319    /// Returns:
1320    ///   * The sealed secret if everything worked.
1321    ///   * KEY_REQUIRES_UPGRADE if keymint indicates that the sealing key requires upgrade.
1322    ///   * FAILED_SEAL if the sealing failed for another reason, e.g., sealing key info or blob
1323    ///     mismatch.
1324    Seal {
1325        key_info: Vec<u8>,
1326        key_blob: Vec<u8>,
1327        secret: Vec<u8>,
1328        responder: SealingKeysSealResponder,
1329    },
1330    /// Unseals a sealed secret using a sealing key identified by its info and blob:
1331    ///   * The key info has to match the one supplied when generating the sealing key.
1332    ///   * The key blob has to match the one used to seal the secret.
1333    ///
1334    /// Note that the secret may be a key itself. It has no bearing on the unseal operation.
1335    ///
1336    /// Returns:
1337    ///   * The unsealed secret if everything worked.
1338    ///   * KEY_REQUIRES_UPGRADE if keymint indicates that the sealing key requires upgrade.
1339    ///   * FAILED_UNSEAL if the unsealing failed for another reason, e.g., sealing key info or blob
1340    ///     mismatch.
1341    Unseal {
1342        key_info: Vec<u8>,
1343        key_blob: Vec<u8>,
1344        sealed_secret: Vec<u8>,
1345        responder: SealingKeysUnsealResponder,
1346    },
1347    /// Upgrades a sealing key that has been deemed out-of-date by keymint. The sealing key to
1348    /// upgrade is identified by its info and blob:
1349    ///   * The key info has to match the one supplied when generating the sealing key.
1350    ///   * The key blob has to match the blob returned when generating the sealing key.
1351    ///
1352    /// Note that after upgrading a key, both the old key and new key will be occupying limited key
1353    /// storage in keymint. This means that clients can unintentionally exhaust key storage in two
1354    /// ways:
1355    /// * Upgrading a key and failing to delete the old key after upgrade.
1356    /// * Successfully upgrading a key, failing to persist the new key, and later (e.g., after a
1357    ///   reboot) upgrading the key again.
1358    ///
1359    /// Both of the above missteps on the part of the client will "waste" one key slot in keymint,
1360    /// and repeated missteps (e.g., a boot loop that upgrades a key, fails to persist the new key,
1361    /// then reboots) can exhaust available key storage. Clients are responsible for old (upgraded)
1362    /// keys and persisting new (result of a successful key upgrade) to ensure that key slots are
1363    /// not wasted.
1364    ///
1365    ///  Returns
1366    ///   * The upgraded key blob if everything worked.
1367    ///   * FAILED_UPGRADE if the upgrade failed.
1368    UpgradeSealingKey {
1369        key_info: Vec<u8>,
1370        key_blob: Vec<u8>,
1371        responder: SealingKeysUpgradeSealingKeyResponder,
1372    },
1373    /// Deletes a sealing key from keymint.
1374    ///
1375    /// This operation should be used to delete old (upgraded) keys.
1376    ///
1377    /// Returns
1378    ///  * Nothing if everything worked.
1379    ///  * FAILED_DELETE if deletion failed.
1380    DeleteSealingKey { key_blob: Vec<u8>, responder: SealingKeysDeleteSealingKeyResponder },
1381}
1382
1383impl SealingKeysRequest {
1384    #[allow(irrefutable_let_patterns)]
1385    pub fn into_create_sealing_key(
1386        self,
1387    ) -> Option<(Vec<u8>, SealingKeysCreateSealingKeyResponder)> {
1388        if let SealingKeysRequest::CreateSealingKey { key_info, responder } = self {
1389            Some((key_info, responder))
1390        } else {
1391            None
1392        }
1393    }
1394
1395    #[allow(irrefutable_let_patterns)]
1396    pub fn into_seal(self) -> Option<(Vec<u8>, Vec<u8>, Vec<u8>, SealingKeysSealResponder)> {
1397        if let SealingKeysRequest::Seal { key_info, key_blob, secret, responder } = self {
1398            Some((key_info, key_blob, secret, responder))
1399        } else {
1400            None
1401        }
1402    }
1403
1404    #[allow(irrefutable_let_patterns)]
1405    pub fn into_unseal(self) -> Option<(Vec<u8>, Vec<u8>, Vec<u8>, SealingKeysUnsealResponder)> {
1406        if let SealingKeysRequest::Unseal { key_info, key_blob, sealed_secret, responder } = self {
1407            Some((key_info, key_blob, sealed_secret, responder))
1408        } else {
1409            None
1410        }
1411    }
1412
1413    #[allow(irrefutable_let_patterns)]
1414    pub fn into_upgrade_sealing_key(
1415        self,
1416    ) -> Option<(Vec<u8>, Vec<u8>, SealingKeysUpgradeSealingKeyResponder)> {
1417        if let SealingKeysRequest::UpgradeSealingKey { key_info, key_blob, responder } = self {
1418            Some((key_info, key_blob, responder))
1419        } else {
1420            None
1421        }
1422    }
1423
1424    #[allow(irrefutable_let_patterns)]
1425    pub fn into_delete_sealing_key(
1426        self,
1427    ) -> Option<(Vec<u8>, SealingKeysDeleteSealingKeyResponder)> {
1428        if let SealingKeysRequest::DeleteSealingKey { key_blob, responder } = self {
1429            Some((key_blob, responder))
1430        } else {
1431            None
1432        }
1433    }
1434
1435    /// Name of the method defined in FIDL
1436    pub fn method_name(&self) -> &'static str {
1437        match *self {
1438            SealingKeysRequest::CreateSealingKey { .. } => "create_sealing_key",
1439            SealingKeysRequest::Seal { .. } => "seal",
1440            SealingKeysRequest::Unseal { .. } => "unseal",
1441            SealingKeysRequest::UpgradeSealingKey { .. } => "upgrade_sealing_key",
1442            SealingKeysRequest::DeleteSealingKey { .. } => "delete_sealing_key",
1443        }
1444    }
1445}
1446
1447#[derive(Debug, Clone)]
1448pub struct SealingKeysControlHandle {
1449    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1450}
1451
1452impl fidl::endpoints::ControlHandle for SealingKeysControlHandle {
1453    fn shutdown(&self) {
1454        self.inner.shutdown()
1455    }
1456
1457    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1458        self.inner.shutdown_with_epitaph(status)
1459    }
1460
1461    fn is_closed(&self) -> bool {
1462        self.inner.channel().is_closed()
1463    }
1464    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1465        self.inner.channel().on_closed()
1466    }
1467
1468    #[cfg(target_os = "fuchsia")]
1469    fn signal_peer(
1470        &self,
1471        clear_mask: zx::Signals,
1472        set_mask: zx::Signals,
1473    ) -> Result<(), zx_status::Status> {
1474        use fidl::Peered;
1475        self.inner.channel().signal_peer(clear_mask, set_mask)
1476    }
1477}
1478
1479impl SealingKeysControlHandle {}
1480
1481#[must_use = "FIDL methods require a response to be sent"]
1482#[derive(Debug)]
1483pub struct SealingKeysCreateSealingKeyResponder {
1484    control_handle: std::mem::ManuallyDrop<SealingKeysControlHandle>,
1485    tx_id: u32,
1486}
1487
1488/// Set the the channel to be shutdown (see [`SealingKeysControlHandle::shutdown`])
1489/// if the responder is dropped without sending a response, so that the client
1490/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1491impl std::ops::Drop for SealingKeysCreateSealingKeyResponder {
1492    fn drop(&mut self) {
1493        self.control_handle.shutdown();
1494        // Safety: drops once, never accessed again
1495        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1496    }
1497}
1498
1499impl fidl::endpoints::Responder for SealingKeysCreateSealingKeyResponder {
1500    type ControlHandle = SealingKeysControlHandle;
1501
1502    fn control_handle(&self) -> &SealingKeysControlHandle {
1503        &self.control_handle
1504    }
1505
1506    fn drop_without_shutdown(mut self) {
1507        // Safety: drops once, never accessed again due to mem::forget
1508        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1509        // Prevent Drop from running (which would shut down the channel)
1510        std::mem::forget(self);
1511    }
1512}
1513
1514impl SealingKeysCreateSealingKeyResponder {
1515    /// Sends a response to the FIDL transaction.
1516    ///
1517    /// Sets the channel to shutdown if an error occurs.
1518    pub fn send(self, mut result: Result<&[u8], CreateError>) -> Result<(), fidl::Error> {
1519        let _result = self.send_raw(result);
1520        if _result.is_err() {
1521            self.control_handle.shutdown();
1522        }
1523        self.drop_without_shutdown();
1524        _result
1525    }
1526
1527    /// Similar to "send" but does not shutdown the channel if an error occurs.
1528    pub fn send_no_shutdown_on_err(
1529        self,
1530        mut result: Result<&[u8], CreateError>,
1531    ) -> Result<(), fidl::Error> {
1532        let _result = self.send_raw(result);
1533        self.drop_without_shutdown();
1534        _result
1535    }
1536
1537    fn send_raw(&self, mut result: Result<&[u8], CreateError>) -> Result<(), fidl::Error> {
1538        self.control_handle.inner.send::<fidl::encoding::ResultType<
1539            SealingKeysCreateSealingKeyResponse,
1540            CreateError,
1541        >>(
1542            result.map(|key_blob| (key_blob,)),
1543            self.tx_id,
1544            0x5a191cbb6a8081bc,
1545            fidl::encoding::DynamicFlags::empty(),
1546        )
1547    }
1548}
1549
1550#[must_use = "FIDL methods require a response to be sent"]
1551#[derive(Debug)]
1552pub struct SealingKeysSealResponder {
1553    control_handle: std::mem::ManuallyDrop<SealingKeysControlHandle>,
1554    tx_id: u32,
1555}
1556
1557/// Set the the channel to be shutdown (see [`SealingKeysControlHandle::shutdown`])
1558/// if the responder is dropped without sending a response, so that the client
1559/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1560impl std::ops::Drop for SealingKeysSealResponder {
1561    fn drop(&mut self) {
1562        self.control_handle.shutdown();
1563        // Safety: drops once, never accessed again
1564        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1565    }
1566}
1567
1568impl fidl::endpoints::Responder for SealingKeysSealResponder {
1569    type ControlHandle = SealingKeysControlHandle;
1570
1571    fn control_handle(&self) -> &SealingKeysControlHandle {
1572        &self.control_handle
1573    }
1574
1575    fn drop_without_shutdown(mut self) {
1576        // Safety: drops once, never accessed again due to mem::forget
1577        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1578        // Prevent Drop from running (which would shut down the channel)
1579        std::mem::forget(self);
1580    }
1581}
1582
1583impl SealingKeysSealResponder {
1584    /// Sends a response to the FIDL transaction.
1585    ///
1586    /// Sets the channel to shutdown if an error occurs.
1587    pub fn send(self, mut result: Result<&[u8], SealError>) -> Result<(), fidl::Error> {
1588        let _result = self.send_raw(result);
1589        if _result.is_err() {
1590            self.control_handle.shutdown();
1591        }
1592        self.drop_without_shutdown();
1593        _result
1594    }
1595
1596    /// Similar to "send" but does not shutdown the channel if an error occurs.
1597    pub fn send_no_shutdown_on_err(
1598        self,
1599        mut result: Result<&[u8], SealError>,
1600    ) -> Result<(), fidl::Error> {
1601        let _result = self.send_raw(result);
1602        self.drop_without_shutdown();
1603        _result
1604    }
1605
1606    fn send_raw(&self, mut result: Result<&[u8], SealError>) -> Result<(), fidl::Error> {
1607        self.control_handle
1608            .inner
1609            .send::<fidl::encoding::ResultType<SealingKeysSealResponse, SealError>>(
1610                result.map(|sealed_secret| (sealed_secret,)),
1611                self.tx_id,
1612                0x10d41255013918d1,
1613                fidl::encoding::DynamicFlags::empty(),
1614            )
1615    }
1616}
1617
1618#[must_use = "FIDL methods require a response to be sent"]
1619#[derive(Debug)]
1620pub struct SealingKeysUnsealResponder {
1621    control_handle: std::mem::ManuallyDrop<SealingKeysControlHandle>,
1622    tx_id: u32,
1623}
1624
1625/// Set the the channel to be shutdown (see [`SealingKeysControlHandle::shutdown`])
1626/// if the responder is dropped without sending a response, so that the client
1627/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1628impl std::ops::Drop for SealingKeysUnsealResponder {
1629    fn drop(&mut self) {
1630        self.control_handle.shutdown();
1631        // Safety: drops once, never accessed again
1632        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1633    }
1634}
1635
1636impl fidl::endpoints::Responder for SealingKeysUnsealResponder {
1637    type ControlHandle = SealingKeysControlHandle;
1638
1639    fn control_handle(&self) -> &SealingKeysControlHandle {
1640        &self.control_handle
1641    }
1642
1643    fn drop_without_shutdown(mut self) {
1644        // Safety: drops once, never accessed again due to mem::forget
1645        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1646        // Prevent Drop from running (which would shut down the channel)
1647        std::mem::forget(self);
1648    }
1649}
1650
1651impl SealingKeysUnsealResponder {
1652    /// Sends a response to the FIDL transaction.
1653    ///
1654    /// Sets the channel to shutdown if an error occurs.
1655    pub fn send(self, mut result: Result<&[u8], UnsealError>) -> Result<(), fidl::Error> {
1656        let _result = self.send_raw(result);
1657        if _result.is_err() {
1658            self.control_handle.shutdown();
1659        }
1660        self.drop_without_shutdown();
1661        _result
1662    }
1663
1664    /// Similar to "send" but does not shutdown the channel if an error occurs.
1665    pub fn send_no_shutdown_on_err(
1666        self,
1667        mut result: Result<&[u8], UnsealError>,
1668    ) -> Result<(), fidl::Error> {
1669        let _result = self.send_raw(result);
1670        self.drop_without_shutdown();
1671        _result
1672    }
1673
1674    fn send_raw(&self, mut result: Result<&[u8], UnsealError>) -> Result<(), fidl::Error> {
1675        self.control_handle
1676            .inner
1677            .send::<fidl::encoding::ResultType<SealingKeysUnsealResponse, UnsealError>>(
1678                result.map(|unsealed_secret| (unsealed_secret,)),
1679                self.tx_id,
1680                0x7037d75ecb579c83,
1681                fidl::encoding::DynamicFlags::empty(),
1682            )
1683    }
1684}
1685
1686#[must_use = "FIDL methods require a response to be sent"]
1687#[derive(Debug)]
1688pub struct SealingKeysUpgradeSealingKeyResponder {
1689    control_handle: std::mem::ManuallyDrop<SealingKeysControlHandle>,
1690    tx_id: u32,
1691}
1692
1693/// Set the the channel to be shutdown (see [`SealingKeysControlHandle::shutdown`])
1694/// if the responder is dropped without sending a response, so that the client
1695/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1696impl std::ops::Drop for SealingKeysUpgradeSealingKeyResponder {
1697    fn drop(&mut self) {
1698        self.control_handle.shutdown();
1699        // Safety: drops once, never accessed again
1700        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1701    }
1702}
1703
1704impl fidl::endpoints::Responder for SealingKeysUpgradeSealingKeyResponder {
1705    type ControlHandle = SealingKeysControlHandle;
1706
1707    fn control_handle(&self) -> &SealingKeysControlHandle {
1708        &self.control_handle
1709    }
1710
1711    fn drop_without_shutdown(mut self) {
1712        // Safety: drops once, never accessed again due to mem::forget
1713        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1714        // Prevent Drop from running (which would shut down the channel)
1715        std::mem::forget(self);
1716    }
1717}
1718
1719impl SealingKeysUpgradeSealingKeyResponder {
1720    /// Sends a response to the FIDL transaction.
1721    ///
1722    /// Sets the channel to shutdown if an error occurs.
1723    pub fn send(self, mut result: Result<&[u8], UpgradeError>) -> Result<(), fidl::Error> {
1724        let _result = self.send_raw(result);
1725        if _result.is_err() {
1726            self.control_handle.shutdown();
1727        }
1728        self.drop_without_shutdown();
1729        _result
1730    }
1731
1732    /// Similar to "send" but does not shutdown the channel if an error occurs.
1733    pub fn send_no_shutdown_on_err(
1734        self,
1735        mut result: Result<&[u8], UpgradeError>,
1736    ) -> Result<(), fidl::Error> {
1737        let _result = self.send_raw(result);
1738        self.drop_without_shutdown();
1739        _result
1740    }
1741
1742    fn send_raw(&self, mut result: Result<&[u8], UpgradeError>) -> Result<(), fidl::Error> {
1743        self.control_handle.inner.send::<fidl::encoding::ResultType<
1744            SealingKeysUpgradeSealingKeyResponse,
1745            UpgradeError,
1746        >>(
1747            result.map(|key_blob| (key_blob,)),
1748            self.tx_id,
1749            0x68584c5a799181e7,
1750            fidl::encoding::DynamicFlags::empty(),
1751        )
1752    }
1753}
1754
1755#[must_use = "FIDL methods require a response to be sent"]
1756#[derive(Debug)]
1757pub struct SealingKeysDeleteSealingKeyResponder {
1758    control_handle: std::mem::ManuallyDrop<SealingKeysControlHandle>,
1759    tx_id: u32,
1760}
1761
1762/// Set the the channel to be shutdown (see [`SealingKeysControlHandle::shutdown`])
1763/// if the responder is dropped without sending a response, so that the client
1764/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1765impl std::ops::Drop for SealingKeysDeleteSealingKeyResponder {
1766    fn drop(&mut self) {
1767        self.control_handle.shutdown();
1768        // Safety: drops once, never accessed again
1769        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1770    }
1771}
1772
1773impl fidl::endpoints::Responder for SealingKeysDeleteSealingKeyResponder {
1774    type ControlHandle = SealingKeysControlHandle;
1775
1776    fn control_handle(&self) -> &SealingKeysControlHandle {
1777        &self.control_handle
1778    }
1779
1780    fn drop_without_shutdown(mut self) {
1781        // Safety: drops once, never accessed again due to mem::forget
1782        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1783        // Prevent Drop from running (which would shut down the channel)
1784        std::mem::forget(self);
1785    }
1786}
1787
1788impl SealingKeysDeleteSealingKeyResponder {
1789    /// Sends a response to the FIDL transaction.
1790    ///
1791    /// Sets the channel to shutdown if an error occurs.
1792    pub fn send(self, mut result: Result<(), DeleteError>) -> Result<(), fidl::Error> {
1793        let _result = self.send_raw(result);
1794        if _result.is_err() {
1795            self.control_handle.shutdown();
1796        }
1797        self.drop_without_shutdown();
1798        _result
1799    }
1800
1801    /// Similar to "send" but does not shutdown the channel if an error occurs.
1802    pub fn send_no_shutdown_on_err(
1803        self,
1804        mut result: Result<(), DeleteError>,
1805    ) -> Result<(), fidl::Error> {
1806        let _result = self.send_raw(result);
1807        self.drop_without_shutdown();
1808        _result
1809    }
1810
1811    fn send_raw(&self, mut result: Result<(), DeleteError>) -> Result<(), fidl::Error> {
1812        self.control_handle.inner.send::<fidl::encoding::ResultType<
1813            fidl::encoding::EmptyStruct,
1814            DeleteError,
1815        >>(
1816            result,
1817            self.tx_id,
1818            0xad65bae761e8c3,
1819            fidl::encoding::DynamicFlags::empty(),
1820        )
1821    }
1822}
1823
1824mod internal {
1825    use super::*;
1826}