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