diem_secure_storage/
error.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8use serde::{Deserialize, Serialize};
9use std::io;
10use thiserror::Error;
11
12#[derive(Debug, Deserialize, Error, PartialEq, Serialize)]
13pub enum Error {
14    #[error("Entropy error: {0}")]
15    EntropyError(String),
16    #[error("Internal error: {0}")]
17    InternalError(String),
18    #[error("Key already exists: {0}")]
19    KeyAlreadyExists(String),
20    #[error("Key not set: {0}")]
21    KeyNotSet(String),
22    #[error("Permission denied")]
23    PermissionDenied,
24    #[error("Serialization error: {0}")]
25    SerializationError(String),
26    #[error("Key version not found, key name: {0}, version: {1}")]
27    KeyVersionNotFound(String, String),
28}
29
30impl From<base64::DecodeError> for Error {
31    fn from(error: base64::DecodeError) -> Self {
32        Self::SerializationError(format!("{}", error))
33    }
34}
35
36impl From<chrono::format::ParseError> for Error {
37    fn from(error: chrono::format::ParseError) -> Self {
38        Self::SerializationError(format!("{}", error))
39    }
40}
41
42impl From<io::Error> for Error {
43    fn from(error: io::Error) -> Self {
44        Self::InternalError(format!("{}", error))
45    }
46}
47
48impl From<bcs::Error> for Error {
49    fn from(error: bcs::Error) -> Self {
50        Self::SerializationError(format!("{}", error))
51    }
52}
53
54impl From<serde_json::Error> for Error {
55    fn from(error: serde_json::Error) -> Self {
56        Self::SerializationError(format!("{}", error))
57    }
58}