rippled
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 <string>
23 #include <system_error>
24 #include <type_traits>
25 
26 namespace ripple {
27 namespace cryptoconditions {
28 namespace detail {
29 
31 {
32 public:
33  explicit cryptoconditions_error_category() = default;
34 
35  const char*
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 
88  case error::large_size:
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 
120 inline 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
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:114
ripple::cryptoconditions::detail::cryptoconditions_error_category::default_error_condition
std::error_condition default_error_condition(int ev) const noexcept override
Definition: error.cpp:101
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:107
std::error_code
STL class.
ripple::cryptoconditions::detail::cryptoconditions_error_category::message
std::string message(int ev) const override
Definition: error.cpp:42
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:36
std::error_condition
STL class.
ripple::cryptoconditions::detail::get_cryptoconditions_error_category
std::error_category const & get_cryptoconditions_error_category()
Definition: error.cpp:121
ripple::cryptoconditions::make_error_code
std::error_code make_error_code(error ev)
Definition: error.cpp:130
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