1mod return_code;
4mod wrapper;
5
6pub use return_code::{
7 ArgumentNumber, BaseReturnCode, EsapiReturnCode, FapiReturnCode, MuapiReturnCode, ReturnCode,
8 SapiReturnCode, TctiReturnCode, TpmFormatOneResponseCode, TpmFormatZeroErrorResponseCode,
9 TpmFormatZeroResponseCode, TpmFormatZeroWarningResponseCode, TpmResponseCode,
10};
11pub use wrapper::WrapperErrorKind;
12
13pub type Result<T> = std::result::Result<T, Error>;
14
15#[derive(Debug, Copy, Clone, PartialEq, Eq)]
19pub enum Error {
20 WrapperError(WrapperErrorKind),
21 TssError(ReturnCode),
22}
23
24impl Error {
25 pub(crate) const fn local_error(kind: WrapperErrorKind) -> Self {
27 Error::WrapperError(kind)
28 }
29
30 pub(crate) const fn tss_error(return_code: ReturnCode) -> Self {
32 Error::TssError(return_code)
33 }
34}
35
36impl std::fmt::Display for Error {
37 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38 match self {
39 Error::WrapperError(e) => e.fmt(f),
40 Error::TssError(e) => e.fmt(f),
41 }
42 }
43}
44
45impl std::error::Error for Error {
46 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
47 match self {
48 Error::WrapperError(wrapper_error) => Some(wrapper_error),
49 Error::TssError(response_code) => Some(response_code),
50 }
51 }
52}