rippled
Loading...
Searching...
No Matches
error.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2016 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/conditions/detail/error.h>
21
22#include <xrpl/basics/safe_cast.h>
23
24#include <string>
25
26namespace ripple {
27namespace cryptoconditions {
28namespace detail {
29
31{
32public:
33 explicit cryptoconditions_error_category() = default;
34
35 char const*
36 name() const noexcept override
37 {
38 return "cryptoconditions";
39 }
40
42 message(int ev) const override
43 {
44 switch (safe_cast<error>(ev))
45 {
47 return "Specification: Requested type not supported.";
48
50 return "Specification: Requested subtype not supported.";
51
53 return "Specification: Requested type not recognized.";
54
56 return "Specification: Requested subtypes not recognized.";
57
59 return "Specification: Incorrect fingerprint size.";
60
62 return "Specification: Incorrect encoding.";
63
65 return "Bad buffer: contains trailing garbage.";
66
68 return "Bad buffer: no data.";
69
71 return "Bad buffer: overfull.";
72
74 return "Bad buffer: underfull.";
75
77 return "Malformed DER encoding.";
78
80 return "Malformed DER encoding: Unexpected tag.";
81
83 return "Malformed DER encoding: Short preamble.";
84
85 case error::long_tag:
86 return "Implementation limit: Overlong tag.";
87
89 return "Implementation limit: Large payload.";
90
92 return "Implementation limit: Specified preimage is too long.";
93
94 case error::generic:
95 default:
96 return "generic error";
97 }
98 }
99
101 default_error_condition(int ev) const noexcept override
102 {
103 return std::error_condition{ev, *this};
104 }
105
106 bool
107 equivalent(int ev, std::error_condition const& condition)
108 const noexcept override
109 {
110 return &condition.category() == this && condition.value() == ev;
111 }
112
113 bool
114 equivalent(std::error_code const& error, int ev) const noexcept override
115 {
116 return &error.category() == this && error.value() == ev;
117 }
118};
119
120inline std::error_category const&
122{
123 static cryptoconditions_error_category const cat{};
124 return cat;
125}
126
127} // namespace detail
128
131{
132 return std::error_code{
133 safe_cast<std::underlying_type<error>::type>(ev),
135}
136
137} // namespace cryptoconditions
138} // namespace ripple
bool equivalent(int ev, std::error_condition const &condition) const noexcept override
Definition error.cpp:107
bool equivalent(std::error_code const &error, int ev) const noexcept override
Definition error.cpp:114
std::error_condition default_error_condition(int ev) const noexcept override
Definition error.cpp:101
std::error_category const & get_cryptoconditions_error_category()
Definition error.cpp:121
std::error_code make_error_code(error ev)
Definition error.cpp:130
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25