snarkos_errors/objects/
account.rs

1// Copyright (C) 2019-2020 Aleo Systems Inc.
2// This file is part of the snarkOS library.
3
4// The snarkOS library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The snarkOS library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the snarkOS library. If not, see <https://www.gnu.org/licenses/>.
16
17use crate::algorithms::{CRHError, CommitmentError, EncryptionError, PRFError, SignatureError};
18
19#[derive(Debug, Error)]
20pub enum AccountError {
21    #[error("{}", _0)]
22    CommitmentError(CommitmentError),
23
24    #[error("{}", _0)]
25    CRHError(CRHError),
26
27    #[error("{}: {}", _0, _1)]
28    Crate(&'static str, String),
29
30    #[error("{}", _0)]
31    EncryptionError(EncryptionError),
32
33    #[error("invalid account commitment")]
34    InvalidAccountCommitment,
35
36    #[error("invalid byte length: {}", _0)]
37    InvalidByteLength(usize),
38
39    #[error("invalid character length: {}", _0)]
40    InvalidCharacterLength(usize),
41
42    #[error("invalid prefix: {:?}", _0)]
43    InvalidPrefix(String),
44
45    #[error("invalid prefix bytes: {:?}", _0)]
46    InvalidPrefixBytes(Vec<u8>),
47
48    #[error("invalid account private key seed")]
49    InvalidPrivateKeySeed,
50
51    #[error("{}", _0)]
52    Message(String),
53
54    #[error("{}", _0)]
55    PRFError(PRFError),
56
57    #[error("{}", _0)]
58    SignatureError(SignatureError),
59}
60
61impl From<CommitmentError> for AccountError {
62    fn from(error: CommitmentError) -> Self {
63        AccountError::CommitmentError(error)
64    }
65}
66
67impl From<CRHError> for AccountError {
68    fn from(error: CRHError) -> Self {
69        AccountError::CRHError(error)
70    }
71}
72
73impl From<EncryptionError> for AccountError {
74    fn from(error: EncryptionError) -> Self {
75        AccountError::EncryptionError(error)
76    }
77}
78
79impl From<PRFError> for AccountError {
80    fn from(error: PRFError) -> Self {
81        AccountError::PRFError(error)
82    }
83}
84
85impl From<SignatureError> for AccountError {
86    fn from(error: SignatureError) -> Self {
87        AccountError::SignatureError(error)
88    }
89}
90
91impl From<base58::FromBase58Error> for AccountError {
92    fn from(error: base58::FromBase58Error) -> Self {
93        AccountError::Crate("base58", format!("{:?}", error))
94    }
95}
96
97impl From<bech32::Error> for AccountError {
98    fn from(error: bech32::Error) -> Self {
99        AccountError::Crate("bech32", format!("{:?}", error))
100    }
101}
102
103impl From<std::io::Error> for AccountError {
104    fn from(error: std::io::Error) -> Self {
105        AccountError::Crate("std::io", format!("{:?}", error))
106    }
107}