curv/elliptic/curves/wrappers/
error.rs

1use std::fmt;
2
3use thiserror::Error;
4
5use crate::elliptic::curves::traits::*;
6
7#[derive(Debug, Error, Clone, PartialEq, Eq)]
8#[error("invalid point (point order ≠ group order)")]
9pub struct MismatchedPointOrder(());
10
11impl MismatchedPointOrder {
12    pub(super) fn new() -> Self {
13        MismatchedPointOrder(())
14    }
15}
16
17#[derive(Debug, Error)]
18pub enum PointFromBytesError {
19    #[error("failed to deserialize the point")]
20    DeserializationError,
21    #[error("invalid point ({0})")]
22    InvalidPoint(MismatchedPointOrder),
23}
24
25#[derive(Debug, Error)]
26pub enum PointFromCoordsError {
27    #[error("{}", NotOnCurve)]
28    NotOnCurve,
29    #[error("invalid point ({0})")]
30    InvalidPoint(MismatchedPointOrder),
31}
32
33/// Indicates that conversion or computation failed due to occurred zero point
34#[derive(Copy, Clone, Debug, Eq, PartialEq)]
35pub struct ZeroPointError(());
36
37impl ZeroPointError {
38    pub(super) fn new() -> Self {
39        ZeroPointError(())
40    }
41}
42
43impl fmt::Display for ZeroPointError {
44    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45        write!(f, "nonzero check failed: point is zero")
46    }
47}
48
49impl std::error::Error for ZeroPointError {}
50
51/// Indicates that conversion or computation failed due to occurred zero scalar
52#[derive(Copy, Clone, Debug, Eq, PartialEq)]
53pub struct ZeroScalarError(());
54
55impl ZeroScalarError {
56    pub(super) fn new() -> Self {
57        ZeroScalarError(())
58    }
59}
60
61impl fmt::Display for ZeroScalarError {
62    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63        write!(f, "nonzero check failed: scalar is zero")
64    }
65}
66
67impl std::error::Error for ZeroScalarError {}
68
69#[derive(Error, Debug)]
70pub enum InvalidPoint {
71    #[error("x,y correspond to zero point")]
72    ZeroPoint,
73    #[error("{}", MismatchedPointOrder(()))]
74    MismatchedPointOrder,
75}