dusk_poseidon/
error.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4//
5// Copyright (c) DUSK NETWORK. All rights reserved.
6
7use dusk_safe::Error as SafeError;
8
9/// Defines all possible error variants for SAFE
10#[derive(Debug, Clone, Copy, PartialEq)]
11pub enum Error {
12    /// A call to during the lifetime of the [`safe::Sponge`] that doesn't fit
13    /// the io-pattern.
14    IOPatternViolation,
15
16    /// An invalid io-pattern.
17    InvalidIOPattern,
18
19    /// The input doesn't yield enough input elements.
20    TooFewInputElements,
21
22    /// Failed to encrypt the message into the cipher with the provided secret
23    /// and nonce.
24    EncryptionFailed,
25
26    /// Failed to decrypt the message from the cipher with the provided secret
27    /// and nonce.
28    DecryptionFailed,
29
30    /// Invalid point on the jubjub-curve
31    InvalidPoint,
32}
33
34impl From<SafeError> for Error {
35    fn from(safe_error: SafeError) -> Self {
36        match safe_error {
37            SafeError::IOPatternViolation => Self::IOPatternViolation,
38            SafeError::InvalidIOPattern => Self::InvalidIOPattern,
39            SafeError::TooFewInputElements => Self::TooFewInputElements,
40            SafeError::EncryptionFailed => Self::EncryptionFailed,
41            SafeError::DecryptionFailed => Self::DecryptionFailed,
42        }
43    }
44}