wasefire_protocol/
applet.rs

1// Copyright 2024 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use core::fmt::Display;
16
17use wasefire_wire::Wire;
18
19#[derive(Debug, Wire)]
20pub struct Request<'a> {
21    pub applet_id: AppletId,
22    pub request: &'a [u8],
23}
24
25#[derive(Debug, Copy, Clone, Wire)]
26pub struct AppletId;
27
28#[derive(Debug, Wire)]
29pub struct Tunnel<'a> {
30    pub applet_id: AppletId,
31    pub delimiter: &'a [u8],
32}
33
34#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Wire)]
35#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
36pub enum ExitStatus {
37    /// The applet exited successfully.
38    Exit,
39
40    /// The applet aborted (e.g. it panicked).
41    Abort,
42
43    /// The applet trapped (e.g. bad memory access).
44    Trap,
45
46    /// The applet was killed (e.g. it was uninstalled).
47    Kill,
48}
49
50impl Display for ExitStatus {
51    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
52        match self {
53            ExitStatus::Exit => write!(f, "The applet exited"),
54            ExitStatus::Abort => write!(f, "The applet aborted"),
55            ExitStatus::Trap => write!(f, "The applet trapped"),
56            ExitStatus::Kill => write!(f, "The applet was killed"),
57        }
58    }
59}