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#include <xrpl/basics/safe_cast.h>
22
23#include <string>
24
25namespace ripple {
26namespace cryptoconditions {
27namespace detail {
28
30{
31public:
32 explicit cryptoconditions_error_category() = default;
33
34 const char*
35 name() const noexcept override
36 {
37 return "cryptoconditions";
38 }
39
41 message(int ev) const override
42 {
43 switch (safe_cast<error>(ev))
44 {
46 return "Specification: Requested type not supported.";
47
49 return "Specification: Requested subtype not supported.";
50
52 return "Specification: Requested type not recognized.";
53
55 return "Specification: Requested subtypes not recognized.";
56
58 return "Specification: Incorrect fingerprint size.";
59
61 return "Specification: Incorrect encoding.";
62
64 return "Bad buffer: contains trailing garbage.";
65
67 return "Bad buffer: no data.";
68
70 return "Bad buffer: overfull.";
71
73 return "Bad buffer: underfull.";
74
76 return "Malformed DER encoding.";
77
79 return "Malformed DER encoding: Unexpected tag.";
80
82 return "Malformed DER encoding: Short preamble.";
83
84 case error::long_tag:
85 return "Implementation limit: Overlong tag.";
86
88 return "Implementation limit: Large payload.";
89
91 return "Implementation limit: Specified preimage is too long.";
92
93 case error::generic:
94 default:
95 return "generic error";
96 }
97 }
98
100 default_error_condition(int ev) const noexcept override
101 {
102 return std::error_condition{ev, *this};
103 }
104
105 bool
106 equivalent(int ev, std::error_condition const& condition)
107 const noexcept override
108 {
109 return &condition.category() == this && condition.value() == ev;
110 }
111
112 bool
113 equivalent(std::error_code const& error, int ev) const noexcept override
114 {
115 return &error.category() == this && error.value() == ev;
116 }
117};
118
119inline std::error_category const&
121{
122 static cryptoconditions_error_category const cat{};
123 return cat;
124}
125
126} // namespace detail
127
130{
131 return std::error_code{
132 safe_cast<std::underlying_type<error>::type>(ev),
134}
135
136} // namespace cryptoconditions
137} // namespace ripple
bool equivalent(int ev, std::error_condition const &condition) const noexcept override
Definition: error.cpp:106
bool equivalent(std::error_code const &error, int ev) const noexcept override
Definition: error.cpp:113
std::error_condition default_error_condition(int ev) const noexcept override
Definition: error.cpp:100
std::error_category const & get_cryptoconditions_error_category()
Definition: error.cpp:120
std::error_code make_error_code(error ev)
Definition: error.cpp:129
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26