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