2021-09-09 01:56:54 -07:00
|
|
|
// Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
|
//
|
|
|
|
|
// This source code is licensed under the MIT license found in the
|
|
|
|
|
// LICENSE file in the root directory of this source tree.
|
|
|
|
|
|
|
|
|
|
//! A list of error types which are produced during an execution of the protocol
|
|
|
|
|
use core::fmt::Debug;
|
|
|
|
|
#[cfg(feature = "std")]
|
|
|
|
|
use std::error::Error;
|
|
|
|
|
|
|
|
|
|
use displaydoc::Display;
|
|
|
|
|
|
|
|
|
|
/// Represents an error in the manipulation of internal cryptographic data
|
|
|
|
|
#[derive(Clone, Display, Eq, Hash, PartialEq)]
|
|
|
|
|
pub enum InternalError {
|
|
|
|
|
/// Could not parse byte sequence for key
|
|
|
|
|
InvalidByteSequence,
|
|
|
|
|
/// Invalid length for {name}: expected {len}, but is actually {actual_len}.
|
|
|
|
|
SizeError {
|
|
|
|
|
/// name
|
|
|
|
|
name: &'static str,
|
|
|
|
|
/// length
|
|
|
|
|
len: usize,
|
|
|
|
|
/// actual
|
|
|
|
|
actual_len: usize,
|
|
|
|
|
},
|
|
|
|
|
/// Could not decompress point.
|
|
|
|
|
PointError,
|
|
|
|
|
/// Computing the hash-to-curve function failed
|
|
|
|
|
HashToCurveError,
|
|
|
|
|
/// Failure to serialize or deserialize bytes
|
|
|
|
|
SerializationError,
|
2021-09-13 16:02:09 -07:00
|
|
|
/// Use of incompatible modes (base vs. verifiable)
|
|
|
|
|
IncompatibleModeError,
|
|
|
|
|
/**
|
|
|
|
|
* Internal error thrown when different-lengthed slices are supplied
|
|
|
|
|
* to the compute_composites() function.
|
|
|
|
|
*/
|
|
|
|
|
MismatchedLengthsForCompositeInputs,
|
|
|
|
|
/// In verifiable mode, occurs when the proof failed to verify
|
|
|
|
|
ProofVerificationError,
|
2021-09-09 01:56:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Debug for InternalError {
|
|
|
|
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
|
|
|
match self {
|
|
|
|
|
Self::InvalidByteSequence => f.debug_tuple("InvalidByteSequence").finish(),
|
|
|
|
|
Self::SizeError {
|
|
|
|
|
name,
|
|
|
|
|
len,
|
|
|
|
|
actual_len,
|
|
|
|
|
} => f
|
|
|
|
|
.debug_struct("SizeError")
|
|
|
|
|
.field("name", name)
|
|
|
|
|
.field("len", len)
|
|
|
|
|
.field("actual_len", actual_len)
|
|
|
|
|
.finish(),
|
|
|
|
|
Self::PointError => f.debug_tuple("PointError").finish(),
|
|
|
|
|
Self::HashToCurveError => f.debug_tuple("HashToCurveError").finish(),
|
|
|
|
|
Self::SerializationError => f.debug_tuple("SerializationError").finish(),
|
2021-09-13 16:02:09 -07:00
|
|
|
Self::IncompatibleModeError => f.debug_tuple("IncompatibleModeError").finish(),
|
|
|
|
|
Self::MismatchedLengthsForCompositeInputs => f
|
|
|
|
|
.debug_tuple("MismatchedLengthsForCompositeInputs")
|
|
|
|
|
.finish(),
|
|
|
|
|
Self::ProofVerificationError => f.debug_tuple("ProofVerificationError").finish(),
|
2021-09-09 01:56:54 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "std")]
|
|
|
|
|
impl Error for InternalError {}
|