wasefire_applet_api/
wasm.rs

1// Copyright 2022 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#[cfg(feature = "native")]
16pub(crate) mod native;
17
18#[cfg(feature = "api-led")]
19impl core::ops::Not for crate::led::Status {
20    type Output = Self;
21    fn not(self) -> Self {
22        use crate::led::Status;
23        match self {
24            Status::Off => Status::On,
25            Status::On => Status::Off,
26        }
27    }
28}
29
30#[cfg(feature = "internal-api-crypto-hash")]
31impl crate::crypto::hash::Algorithm {
32    /// Returns the length in bytes of the algorithm digest.
33    pub const fn digest_len(self) -> usize {
34        match self {
35            crate::crypto::hash::Algorithm::Sha256 => 32,
36            crate::crypto::hash::Algorithm::Sha384 => 48,
37        }
38    }
39}
40
41#[cfg(feature = "api-crypto-ec")]
42impl crate::crypto::ec::Curve {
43    /// Returns the length in bytes of an integer.
44    pub const fn int_len(self) -> usize {
45        match self {
46            crate::crypto::ec::Curve::P256 => 32,
47            crate::crypto::ec::Curve::P384 => 48,
48        }
49    }
50}
51
52impl core::ops::Sub for crate::debug::Perf {
53    type Output = crate::debug::Perf;
54
55    fn sub(self, rhs: Self) -> Self::Output {
56        Self {
57            platform: self.platform - rhs.platform,
58            applets: self.applets - rhs.applets,
59            waiting: self.waiting - rhs.waiting,
60        }
61    }
62}
63
64impl core::ops::SubAssign for crate::debug::Perf {
65    fn sub_assign(&mut self, rhs: Self) {
66        self.platform -= rhs.platform;
67        self.applets -= rhs.applets;
68        self.waiting -= rhs.waiting;
69    }
70}