1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
//! Collection of errors to be used in fastcrypto.
//!
//! A function should validate its arguments and return an indicative error where needed.
//! However, once the function is executing the cryptographic protocol/algorithm (directly/
//! indirectly) then it should not return explicit errors as it might leak private information.
//! In those cases the function should return the opaque, general error [FastCryptoError::GeneralOpaqueError].
//! When in doubt, prefer [FastCryptoError::GeneralOpaqueError].
use thiserror::Error;
pub type FastCryptoResult<T> = Result<T, FastCryptoError>;
/// Collection of errors to be used in fastcrypto.
#[derive(Clone, Debug, Error, Eq, PartialEq)]
pub enum FastCryptoError {
/// Invalid value was given to the function
#[error("Invalid value was given to the function")]
InvalidInput,
/// Input is to short.
#[error("Expected input of length at least {0}")]
InputTooShort(usize),
/// Input is to long.
#[error("Expected input of length at most {0}")]
InputTooLong(usize),
/// Input length is wrong.
#[error("Expected input of length exactly {0}")]
InputLengthWrong(usize),
/// Invalid signature was given to the function
#[error("Invalid signature was given to the function")]
InvalidSignature,
/// Invalid proof was given to the function
#[error("Invalid proof was given to the function")]
InvalidProof,
/// Not enough inputs were given to the function, retry with more
#[error("Not enough inputs were given to the function, retry with more")]
NotEnoughInputs,
/// Invalid message was given to the function
#[error("Invalid message was given to the function")]
InvalidMessage,
/// Message should be ignored
#[error("Message should be ignored")]
IgnoredMessage,
/// The presigs iterator has no more values. Please create a new iterator.
#[error("Out of presigs in the iterator, please create new presigs")]
OutOfPresigs,
/// Error in error decoding because there are too many errors to correct.
#[error("Too many errors to correct in error decoding. Up to {0} errors can be corrected.")]
TooManyErrors(usize),
/// The inputs given does not have enough weight.
#[error("Total weight of inputs to small. Should give at least {0}.")]
NotEnoughWeight(usize),
/// General cryptographic error.
#[error("General cryptographic error: {0}")]
GeneralError(String),
/// General opaque cryptographic error.
#[error("General cryptographic error")]
GeneralOpaqueError,
}
impl From<signature::Error> for FastCryptoError {
fn from(_: signature::Error) -> Self {
FastCryptoError::InvalidSignature
}
}