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