libs/http/include/boost/http/bcrypt/error.hpp

100.0% Lines (2/2) 100.0% Functions (1/1) -% Branches (0/0)
libs/http/include/boost/http/bcrypt/error.hpp
Line Hits Source Code
1 //
2 // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/cppalliance/http
8 //
9
10 #ifndef BOOST_HTTP_BCRYPT_ERROR_HPP
11 #define BOOST_HTTP_BCRYPT_ERROR_HPP
12
13 #include <boost/http/detail/config.hpp>
14 #include <boost/system/error_category.hpp>
15 #include <boost/system/is_error_code_enum.hpp>
16 #include <system_error>
17
18 namespace boost {
19 namespace http {
20 namespace bcrypt {
21
22 /** Error codes for bcrypt operations.
23
24 These errors indicate malformed input from untrusted sources.
25 */
26 enum class error
27 {
28 /// Success
29 ok = 0,
30
31 /// Salt string is malformed
32 invalid_salt,
33
34 /// Hash string is malformed
35 invalid_hash
36 };
37
38 } // bcrypt
39 } // http
40
41 namespace system {
42 template<>
43 struct is_error_code_enum<
44 ::boost::http::bcrypt::error>
45 {
46 static bool const value = true;
47 };
48 } // system
49 } // boost
50
51 namespace std {
52 template<>
53 struct is_error_code_enum<
54 ::boost::http::bcrypt::error>
55 : std::true_type {};
56 } // std
57
58 namespace boost {
59 namespace http {
60 namespace bcrypt {
61
62 namespace detail {
63
64 struct BOOST_SYMBOL_VISIBLE
65 error_cat_type
66 : system::error_category
67 {
68 BOOST_HTTP_DECL const char* name(
69 ) const noexcept override;
70 BOOST_HTTP_DECL std::string message(
71 int) const override;
72 BOOST_HTTP_DECL char const* message(
73 int, char*, std::size_t
74 ) const noexcept override;
75 BOOST_SYSTEM_CONSTEXPR error_cat_type()
76 : error_category(0xbc8f2a4e7c193d56)
77 {
78 }
79 };
80
81 BOOST_HTTP_DECL extern
82 error_cat_type error_cat;
83
84 } // detail
85
86 inline
87 BOOST_SYSTEM_CONSTEXPR
88 system::error_code
89 15 make_error_code(
90 error ev) noexcept
91 {
92 return system::error_code{
93 static_cast<std::underlying_type<
94 error>::type>(ev),
95 15 detail::error_cat};
96 }
97
98 } // bcrypt
99 } // http
100 } // boost
101
102 #endif
103