app_manager/
error.rs

1// SPDX-FileCopyrightText: 2025 Foundation Devices, Inc. <hello@foundation.xyz>
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4#[derive(
5    Debug,
6    Clone,
7    Copy,
8    thiserror::Error,
9    rkyv::Archive,
10    rkyv::Serialize,
11    rkyv::Deserialize,
12    num_derive::FromPrimitive,
13    num_derive::ToPrimitive,
14)]
15pub enum AppManagerError {
16    #[error("Unknown AppId")]
17    UnknownAppId = 0,
18
19    #[error("Verification Failed")]
20    VerificationFailed = 1,
21
22    #[error("Internal Error")]
23    InternalError = 2,
24
25    #[error("No Trusted Publisher Certificate")]
26    NoTrustedPublisherCertificate = 3,
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
30pub enum VerificationError {
31    Unverified,
32    MissingCosign2Header,
33    InternalError,
34}
35
36#[derive(Debug, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
37pub enum LaunchError {
38    UnknownAppId,
39    Verification(VerificationError),
40    NoTrustedPublisherCertificate,
41    OutOfMemory,
42    InternalError,
43}
44
45impl From<xous::Error> for LaunchError {
46    fn from(value: xous::Error) -> Self {
47        match value {
48            xous::Error::OutOfMemory => LaunchError::OutOfMemory,
49            _ => LaunchError::InternalError,
50        }
51    }
52}
53
54impl From<std::str::Utf8Error> for LaunchError {
55    fn from(_: std::str::Utf8Error) -> Self { LaunchError::InternalError }
56}
57
58impl From<LaunchError> for AppManagerError {
59    fn from(value: LaunchError) -> Self {
60        match value {
61            LaunchError::UnknownAppId => AppManagerError::UnknownAppId,
62            LaunchError::Verification(_) => AppManagerError::VerificationFailed,
63            LaunchError::NoTrustedPublisherCertificate => AppManagerError::NoTrustedPublisherCertificate,
64            _ => AppManagerError::InternalError,
65        }
66    }
67}
68
69#[cfg(not(keyos))]
70impl From<std::io::Error> for LaunchError {
71    fn from(_value: std::io::Error) -> Self { LaunchError::InternalError }
72}
73
74#[cfg(not(keyos))]
75impl From<serde_json::Error> for LaunchError {
76    fn from(_value: serde_json::Error) -> Self { LaunchError::InternalError }
77}