xrpld
Loading...
Searching...
No Matches
error.cpp
1#include <xrpl/conditions/detail/error.h>
2
3#include <xrpl/basics/safe_cast.h>
4
5#include <string>
6#include <system_error>
7#include <type_traits>
8
10namespace detail {
11
13{
14public:
15 explicit CryptoconditionsErrorCategory() = default;
16
17 [[nodiscard]] char const*
18 name() const noexcept override
19 {
20 return "cryptoconditions";
21 }
22
23 [[nodiscard]] std::string
24 message(int ev) const override
25 {
26 switch (safeCast<Error>(ev))
27 {
29 return "Specification: Requested type not supported.";
30
32 return "Specification: Requested subtype not supported.";
33
35 return "Specification: Requested type not recognized.";
36
38 return "Specification: Requested subtypes not recognized.";
39
41 return "Specification: Incorrect fingerprint size.";
42
44 return "Specification: Incorrect encoding.";
45
47 return "Bad buffer: contains trailing garbage.";
48
50 return "Bad buffer: no data.";
51
53 return "Bad buffer: overfull.";
54
56 return "Bad buffer: underfull.";
57
59 return "Malformed DER encoding.";
60
62 return "Malformed DER encoding: Unexpected tag.";
63
65 return "Malformed DER encoding: Short preamble.";
66
67 case Error::LongTag:
68 return "Implementation limit: Overlong tag.";
69
71 return "Implementation limit: Large payload.";
72
74 return "Implementation limit: Specified preimage is too long.";
75
76 case Error::Generic:
77 default:
78 return "generic error";
79 }
80 }
81
82 [[nodiscard]] std::error_condition
83 default_error_condition(int ev) const noexcept override
84 {
85 return std::error_condition{ev, *this};
86 }
87
88 [[nodiscard]] bool
89 equivalent(int ev, std::error_condition const& condition) const noexcept override
90 {
91 return &condition.category() == this && condition.value() == ev;
92 }
93
94 [[nodiscard]] bool
95 equivalent(std::error_code const& error, int ev) const noexcept override
96 {
97 return &error.category() == this && error.value() == ev;
98 }
99};
100
101inline std::error_category const&
103{
104 static CryptoconditionsErrorCategory const kCat{};
105 return kCat;
106}
107
108} // namespace detail
109
116
117} // namespace xrpl::cryptoconditions
std::error_condition default_error_condition(int ev) const noexcept override
Definition error.cpp:83
bool equivalent(int ev, std::error_condition const &condition) const noexcept override
Definition error.cpp:89
char const * name() const noexcept override
Definition error.cpp:18
bool equivalent(std::error_code const &error, int ev) const noexcept override
Definition error.cpp:95
std::error_category const & getCryptoconditionsErrorCategory()
Definition error.cpp:102
std::error_code make_error_code(Error ev)
Definition error.cpp:111
constexpr std::enable_if_t< std::is_integral_v< Dest > &&std::is_integral_v< Src >, Dest > safeCast(Src s) noexcept
Definition safe_cast.h:21