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