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