generic_ec/
errors.rs

1//! When something goes wrong
2
3#[cfg(feature = "std")]
4use std::error::Error;
5
6use core::fmt;
7
8/// Indicates that provided integer (usually encoded as bytes) can't be a valid coordinate of a point on curve `E`
9#[derive(Debug, Clone, Copy)]
10pub struct InvalidCoordinate;
11
12impl fmt::Display for InvalidCoordinate {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        f.write_str("invalid coordinate")
15    }
16}
17
18#[cfg(feature = "std")]
19impl Error for InvalidCoordinate {}
20
21/// Indicates that point is not valid
22#[derive(Debug, Clone, Copy)]
23pub struct InvalidPoint;
24
25impl fmt::Display for InvalidPoint {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        f.write_str("invalid point")
28    }
29}
30
31#[cfg(feature = "std")]
32impl Error for InvalidPoint {}
33
34/// Indicates that scalar is not valid
35#[derive(Debug, Clone, Copy)]
36pub struct InvalidScalar;
37
38impl fmt::Display for InvalidScalar {
39    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40        f.write_str("invalid scalar")
41    }
42}
43
44#[cfg(feature = "std")]
45impl Error for InvalidScalar {}
46
47/// Appeared zero point is not expected/accepted
48#[derive(Debug, Clone, Copy)]
49pub struct ZeroPoint;
50
51impl fmt::Display for ZeroPoint {
52    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53        f.write_str("zero point")
54    }
55}
56
57#[cfg(feature = "std")]
58impl Error for ZeroPoint {}
59
60/// Appeared zero scalar is not expected/accepted
61#[derive(Debug, Clone, Copy)]
62pub struct ZeroScalar;
63
64impl fmt::Display for ZeroScalar {
65    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66        f.write_str("zero scalar")
67    }
68}
69
70#[cfg(feature = "std")]
71impl Error for ZeroScalar {}