Skip to main content

wasefire_stub/
lib.rs

1// Copyright 2023 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
15//! This crate provides stubs for parts of the applet API.
16//!
17//! By default, when using the applet API with the `native` feature, all calls to the applet API
18//! will panic. This crate provides a working implementation for some parts of the API (like the
19//! crypto module).
20//!
21//! Note that this crate doesn't expose anything. To use it, you just need to link it:
22//!
23//! ```
24//! use wasefire_stub as _;
25//! ```
26
27#![feature(try_blocks)]
28#![deny(unsafe_op_in_unsafe_fn)]
29
30use wasefire_error::Error;
31
32mod crypto;
33mod debug;
34mod rng;
35mod scheduling;
36
37fn convert(x: Result<u32, Error>) -> isize {
38    Error::encode(x) as isize
39}
40
41fn convert_bool(x: Result<bool, Error>) -> isize {
42    convert(x.map(|x| x as u32))
43}
44
45fn convert_unit(x: Result<(), Error>) -> isize {
46    convert(x.map(|()| 0))
47}