em_app/
error.rs

1/* Copyright (c) Fortanix, Inc.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6use std::{error, fmt};
7
8type RemoteError = Box<dyn error::Error>;
9
10#[derive(Debug)]
11pub enum Error {
12    // Errors returned by ExternalKey trait functions.
13    ExternalKey(RemoteError),
14
15    // Errors returned by ExternalKey trait functions.
16    ExternalKeyString(String),
17
18    // Errors establishing connection to node agent.
19    NodeAgentClient(RemoteError),
20
21    // Errors returned by remote calls when fetching target-info
22    TargetReport(RemoteError),
23
24    // Error creating a hash over target report.
25    TargetReportHash(RemoteError),
26
27    // Internal errors specific to parsing remote data or code issues when fetching target-info
28    TargetReportInternal(String),
29
30    // Errors when fetching attestation certificate.
31    AttestationCert(RemoteError),
32
33    // Errors when hashing data during attestation certificate processing.
34    AttestationCertHash(RemoteError),
35
36    // Internal errors specific to parsing remote data or code issues when fetching attestation certificates
37    AttestationCertInternal(String),
38
39    // Validation failed for data returned by Node Agent. (possibly tampered or protocol issues)
40    AttestationCertValidation(String),
41
42    // Error replies from Node Agent for certificate issue
43    CertIssue(RemoteError),
44
45    // Error using provided application config id.
46    ConfigIdIssue(String),
47
48    // Error generating nonce
49    NonceGeneration(RemoteError),
50
51    // Errors for nitro when accessing driver
52    NsmDriver(String),
53
54    // Unexpected response from NSM driver
55    UnexpectedNsmResponse(String),
56}
57
58impl fmt::Display for crate::Error {
59    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60        match &*self {
61            Error::ExternalKey(e)               => write!(f, "External key returned error: {}", e),
62            Error::ExternalKeyString(e)         => write!(f, "External key returned error: {}", e),
63            Error::NodeAgentClient(e)           => write!(f, "Error creating node agent client: {}", e),
64            Error::TargetReport(e)              => write!(f, "Unable to get target report from node agent: {}", e),
65            Error::TargetReportHash(e)          => write!(f, "Failure in hash operations while processing target report: {}", e),
66            Error::TargetReportInternal(e)      => write!(f, "Internal error in target report handling: {}", e),
67            Error::AttestationCert(e)           => write!(f, "Failure requesting attestation certificate: {}", e),
68            Error::AttestationCertHash(e)       => write!(f, "Failure in hash operations while processing attestation certificate: {}", e),
69            Error::AttestationCertInternal(e)   => write!(f, "Internal error in processing attestation certificate: {}", e),
70            Error::AttestationCertValidation(e) => write!(f, "Validation failed for data returned by Node Agent: {}", e),
71            Error::CertIssue(e)                 => write!(f, "Failure in final certificate issue step: {}", e),
72            Error::ConfigIdIssue(e)             => write!(f, "Failure in parsing input application config id: {}", e),
73            Error::NonceGeneration(e)           => write!(f, "Failure generating nonce: {}", e),
74            Error::NsmDriver(e)                 => write!(f, "Failure in communicating with NSM driver: {}", e),
75            Error::UnexpectedNsmResponse(e)     => write!(f, "Unexpected response from NSM driver: {}", e),
76        }
77    }
78}