Ed Tanous | fc76b8a | 2020-09-28 17:21:52 -0700 | [diff] [blame] | 1 | #pragma once |
2 | |||||
Ed Tanous | c160ae7 | 2024-03-27 18:45:20 -0700 | [diff] [blame] | 3 | #include "logging.hpp" |
4 | |||||
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 5 | #include <limits> |
Ed Tanous | 2c6ffdb | 2023-06-28 11:28:38 -0700 | [diff] [blame] | 6 | #include <string> |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 7 | |
Ed Tanous | fc76b8a | 2020-09-28 17:21:52 -0700 | [diff] [blame] | 8 | namespace bmcweb |
9 | { | ||||
10 | |||||
11 | struct OpenSSLGenerator | ||||
12 | { | ||||
Ed Tanous | b7f3a82 | 2024-06-05 08:45:25 -0700 | [diff] [blame] | 13 | uint8_t operator()(); |
Ed Tanous | fc76b8a | 2020-09-28 17:21:52 -0700 | [diff] [blame] | 14 | |
Ed Tanous | ad0006e | 2021-05-11 15:55:47 -0700 | [diff] [blame] | 15 | static constexpr uint8_t max() |
Ed Tanous | fc76b8a | 2020-09-28 17:21:52 -0700 | [diff] [blame] | 16 | { |
17 | return std::numeric_limits<uint8_t>::max(); | ||||
18 | } | ||||
Ed Tanous | ad0006e | 2021-05-11 15:55:47 -0700 | [diff] [blame] | 19 | static constexpr uint8_t min() |
Ed Tanous | fc76b8a | 2020-09-28 17:21:52 -0700 | [diff] [blame] | 20 | { |
21 | return std::numeric_limits<uint8_t>::min(); | ||||
22 | } | ||||
23 | |||||
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 24 | bool error() const |
Ed Tanous | fc76b8a | 2020-09-28 17:21:52 -0700 | [diff] [blame] | 25 | { |
26 | return err; | ||||
27 | } | ||||
28 | |||||
29 | // all generators require this variable | ||||
30 | using result_type = uint8_t; | ||||
31 | |||||
32 | private: | ||||
33 | // RAND_bytes() returns 1 on success, 0 otherwise. -1 if bad function | ||||
34 | static constexpr int opensslSuccess = 1; | ||||
35 | bool err = false; | ||||
36 | }; | ||||
37 | |||||
Ed Tanous | 2c6ffdb | 2023-06-28 11:28:38 -0700 | [diff] [blame] | 38 | std::string getRandomUUID(); |
39 | |||||
Ed Tanous | b7f3a82 | 2024-06-05 08:45:25 -0700 | [diff] [blame] | 40 | std::string getRandomIdOfLength(size_t length); |
41 | |||||
Ed Tanous | 724985f | 2024-06-05 09:19:06 -0700 | [diff] [blame] | 42 | bool constantTimeStringCompare(std::string_view a, std::string_view b); |
43 | struct ConstantTimeCompare | ||||
44 | { | ||||
45 | bool operator()(std::string_view a, std::string_view b) const; | ||||
46 | }; | ||||
47 | |||||
Ed Tanous | fc76b8a | 2020-09-28 17:21:52 -0700 | [diff] [blame] | 48 | } // namespace bmcweb |