rippled
ripple
conditions
impl
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 <ripple/basics/safe_cast.h>
21
#include <ripple/conditions/impl/error.h>
22
#include <
system_error
>
23
#include <
string
>
24
#include <
type_traits
>
25
26
namespace
ripple
{
27
namespace
cryptoconditions {
28
namespace
detail {
29
30
class
cryptoconditions_error_category
31
:
public
std::error_category
32
{
33
public
:
34
explicit
cryptoconditions_error_category
() =
default
;
35
36
const
char
*
37
name
() const noexcept
override
38
{
39
return
"cryptoconditions"
;
40
}
41
42
std::string
43
message
(
int
ev)
const override
44
{
45
switch
(safe_cast<error>(ev))
46
{
47
case
error::unsupported_type
:
48
return
"Specification: Requested type not supported."
;
49
50
case
error::unsupported_subtype
:
51
return
"Specification: Requested subtype not supported."
;
52
53
case
error::unknown_type
:
54
return
"Specification: Requested type not recognized."
;
55
56
case
error::unknown_subtype
:
57
return
"Specification: Requested subtypes not recognized."
;
58
59
case
error::fingerprint_size
:
60
return
"Specification: Incorrect fingerprint size."
;
61
62
case
error::incorrect_encoding
:
63
return
"Specification: Incorrect encoding."
;
64
65
case
error::trailing_garbage
:
66
return
"Bad buffer: contains trailing garbage."
;
67
68
case
error::buffer_empty
:
69
return
"Bad buffer: no data."
;
70
71
case
error::buffer_overfull
:
72
return
"Bad buffer: overfull."
;
73
74
case
error::buffer_underfull
:
75
return
"Bad buffer: underfull."
;
76
77
case
error::malformed_encoding
:
78
return
"Malformed DER encoding."
;
79
80
case
error::unexpected_tag
:
81
return
"Malformed DER encoding: Unexpected tag."
;
82
83
case
error::short_preamble
:
84
return
"Malformed DER encoding: Short preamble."
;
85
86
case
error::long_tag
:
87
return
"Implementation limit: Overlong tag."
;
88
89
case
error::large_size
:
90
return
"Implementation limit: Large payload."
;
91
92
case
error::preimage_too_long
:
93
return
"Implementation limit: Specified preimage is too long."
;
94
95
case
error::generic
:
96
default
:
97
return
"generic error"
;
98
}
99
}
100
101
std::error_condition
102
default_error_condition
(
int
ev)
const
noexcept
override
103
{
104
return
std::error_condition
{ ev, *
this
};
105
}
106
107
bool
108
equivalent
(
109
int
ev,
110
std::error_condition
const
& condition)
const
noexcept
override
111
{
112
return
&condition.category() ==
this
&&
113
condition.value() == ev;
114
}
115
116
bool
117
equivalent
(
118
std::error_code
const
&
error
,
119
int
ev)
const
noexcept
override
120
{
121
return
&
error
.category() ==
this
&&
122
error
.value() == ev;
123
}
124
};
125
126
inline
127
std::error_category
const
&
128
get_cryptoconditions_error_category
()
129
{
130
static
cryptoconditions_error_category
const
cat{};
131
return
cat;
132
}
133
134
}
// detail
135
136
std::error_code
137
make_error_code
(
error
ev)
138
{
139
return
std::error_code
{
140
safe_cast<std::underlying_type<error>::type>(ev),
141
detail::get_cryptoconditions_error_category
()
142
};
143
}
144
145
}
146
}
ripple::cryptoconditions::error::buffer_empty
@ buffer_empty
std::string
STL class.
ripple::cryptoconditions::error::unsupported_subtype
@ unsupported_subtype
system_error
std::error_category
STL class.
ripple::cryptoconditions::detail::cryptoconditions_error_category::equivalent
bool equivalent(std::error_code const &error, int ev) const noexcept override
Definition:
error.cpp:117
ripple::cryptoconditions::detail::cryptoconditions_error_category::default_error_condition
std::error_condition default_error_condition(int ev) const noexcept override
Definition:
error.cpp:102
ripple::cryptoconditions::error::fingerprint_size
@ fingerprint_size
ripple::cryptoconditions::error::incorrect_encoding
@ incorrect_encoding
ripple::cryptoconditions::detail::cryptoconditions_error_category::equivalent
bool equivalent(int ev, std::error_condition const &condition) const noexcept override
Definition:
error.cpp:108
std::error_code
STL class.
ripple::cryptoconditions::detail::cryptoconditions_error_category::message
std::string message(int ev) const override
Definition:
error.cpp:43
ripple::cryptoconditions::error::short_preamble
@ short_preamble
ripple::cryptoconditions::error::unknown_subtype
@ unknown_subtype
ripple::cryptoconditions::error::buffer_underfull
@ buffer_underfull
ripple::cryptoconditions::detail::cryptoconditions_error_category::name
const char * name() const noexcept override
Definition:
error.cpp:37
std::error_condition
STL class.
ripple::cryptoconditions::detail::get_cryptoconditions_error_category
std::error_category const & get_cryptoconditions_error_category()
Definition:
error.cpp:128
ripple::cryptoconditions::make_error_code
std::error_code make_error_code(error ev)
Definition:
error.cpp:137
ripple::cryptoconditions::error::unexpected_tag
@ unexpected_tag
ripple::cryptoconditions::error::unknown_type
@ unknown_type
ripple::cryptoconditions::detail::cryptoconditions_error_category::cryptoconditions_error_category
cryptoconditions_error_category()=default
ripple::cryptoconditions::error::preimage_too_long
@ preimage_too_long
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition:
RCLCensorshipDetector.h:29
ripple::cryptoconditions::error::long_tag
@ long_tag
ripple::cryptoconditions::error::buffer_overfull
@ buffer_overfull
ripple::cryptoconditions::error::generic
@ generic
ripple::cryptoconditions::error::large_size
@ large_size
ripple::cryptoconditions::error::trailing_garbage
@ trailing_garbage
ripple::cryptoconditions::detail::cryptoconditions_error_category
Definition:
error.cpp:30
type_traits
ripple::cryptoconditions::error::malformed_encoding
@ malformed_encoding
ripple::cryptoconditions::error::unsupported_type
@ unsupported_type
ripple::cryptoconditions::error
error
Definition:
error.h:29
string
Generated by
1.8.17