blob: 70e5ed08bd1cc77ed25302cb7cef7a770edf08ee [file] [log] [blame]
Ed Tanousfc76b8a2020-09-28 17:21:52 -07001#pragma once
2
Ed Tanousc160ae72024-03-27 18:45:20 -07003#include "logging.hpp"
4
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08005#include <limits>
Ed Tanous2c6ffdb2023-06-28 11:28:38 -07006#include <string>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08007
Ed Tanousfc76b8a2020-09-28 17:21:52 -07008namespace bmcweb
9{
10
11struct OpenSSLGenerator
12{
Ed Tanousb7f3a822024-06-05 08:45:25 -070013 uint8_t operator()();
Ed Tanousfc76b8a2020-09-28 17:21:52 -070014
Ed Tanousad0006e2021-05-11 15:55:47 -070015 static constexpr uint8_t max()
Ed Tanousfc76b8a2020-09-28 17:21:52 -070016 {
17 return std::numeric_limits<uint8_t>::max();
18 }
Ed Tanousad0006e2021-05-11 15:55:47 -070019 static constexpr uint8_t min()
Ed Tanousfc76b8a2020-09-28 17:21:52 -070020 {
21 return std::numeric_limits<uint8_t>::min();
22 }
23
Ed Tanous9eb808c2022-01-25 10:19:23 -080024 bool error() const
Ed Tanousfc76b8a2020-09-28 17:21:52 -070025 {
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 Tanous2c6ffdb2023-06-28 11:28:38 -070038std::string getRandomUUID();
39
Ed Tanousb7f3a822024-06-05 08:45:25 -070040std::string getRandomIdOfLength(size_t length);
41
Ed Tanous724985f2024-06-05 09:19:06 -070042bool constantTimeStringCompare(std::string_view a, std::string_view b);
43struct ConstantTimeCompare
44{
45 bool operator()(std::string_view a, std::string_view b) const;
46};
47
Ed Tanousfc76b8a2020-09-28 17:21:52 -070048} // namespace bmcweb