rippled
token_errors.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2022 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 #ifndef RIPPLE_PROTOCOL_TOKEN_ERRORS_H_INCLUDED
21 #define RIPPLE_PROTOCOL_TOKEN_ERRORS_H_INCLUDED
22 
23 #include <system_error>
24 
25 namespace ripple {
26 enum class TokenCodecErrc {
27  success = 0,
35  unknown,
36 };
37 }
38 
39 namespace std {
40 template <>
41 struct is_error_code_enum<ripple::TokenCodecErrc> : true_type
42 {
43 };
44 } // namespace std
45 
46 namespace ripple {
47 namespace detail {
49 {
50 public:
51  // Return a short descriptive name for the category
52  virtual const char*
53  name() const noexcept override final
54  {
55  return "TokenCodecError";
56  }
57  // Return what each enum means in text
58  virtual std::string
59  message(int c) const override final
60  {
61  switch (static_cast<TokenCodecErrc>(c))
62  {
64  return "conversion successful";
66  return "input too large";
68  return "input too small";
70  return "bad base 58 character";
72  return "output too small";
74  return "mismatched token type";
76  return "mismatched checksum";
78  return "invalid encoding char";
80  return "unknown";
81  default:
82  return "unknown";
83  }
84  }
85 };
86 } // namespace detail
87 
90 {
92  return c;
93 }
94 
95 inline std::error_code
97 {
98  return {static_cast<int>(e), TokenCodecErrcCategory()};
99 }
100 } // namespace ripple
101 #endif // TOKEN_ERRORS_H_
ripple::TokenCodecErrcCategory
const ripple::detail::TokenCodecErrcCategory & TokenCodecErrcCategory()
Definition: token_errors.h:89
std::true_type
ripple::TokenCodecErrc::mismatchedChecksum
@ mismatchedChecksum
ripple::TokenCodecErrc::unknown
@ unknown
std::string
STL class.
system_error
ripple::detail::TokenCodecErrcCategory::name
virtual const char * name() const noexcept override final
Definition: token_errors.h:53
std::error_category
STL class.
ripple::TokenCodecErrc
TokenCodecErrc
Definition: token_errors.h:26
ripple::TokenCodecErrc::outputTooSmall
@ outputTooSmall
std::error_code
STL class.
ripple::TokenCodecErrc::success
@ success
ripple::detail::TokenCodecErrcCategory
Definition: token_errors.h:48
ripple::TokenCodecErrc::mismatchedTokenType
@ mismatchedTokenType
std::is_error_code_enum
ripple::TokenCodecErrc::inputTooLarge
@ inputTooLarge
ripple::TokenCodecErrc::badB58Character
@ badB58Character
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::TokenCodecErrc::inputTooSmall
@ inputTooSmall
std
STL namespace.
ripple::detail::TokenCodecErrcCategory::message
virtual std::string message(int c) const override final
Definition: token_errors.h:59
ripple::make_error_code
std::error_code make_error_code(ripple::TokenCodecErrc e)
Definition: token_errors.h:96
ripple::TokenCodecErrc::invalidEncodingChar
@ invalidEncodingChar