blob: 440a2c16b6a381db749925d390779206309d12cd [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Ed Tanousfc76b8a2020-09-28 17:21:52 -07003#pragma once
4
Ed Tanousc160ae72024-03-27 18:45:20 -07005#include "logging.hpp"
6
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08007#include <limits>
Ed Tanous2c6ffdb2023-06-28 11:28:38 -07008#include <string>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08009
Ed Tanousfc76b8a2020-09-28 17:21:52 -070010namespace bmcweb
11{
12
13struct OpenSSLGenerator
14{
Ed Tanousb7f3a822024-06-05 08:45:25 -070015 uint8_t operator()();
Ed Tanousfc76b8a2020-09-28 17:21:52 -070016
Ed Tanousad0006e2021-05-11 15:55:47 -070017 static constexpr uint8_t max()
Ed Tanousfc76b8a2020-09-28 17:21:52 -070018 {
19 return std::numeric_limits<uint8_t>::max();
20 }
Ed Tanousad0006e2021-05-11 15:55:47 -070021 static constexpr uint8_t min()
Ed Tanousfc76b8a2020-09-28 17:21:52 -070022 {
23 return std::numeric_limits<uint8_t>::min();
24 }
25
Ed Tanous9eb808c2022-01-25 10:19:23 -080026 bool error() const
Ed Tanousfc76b8a2020-09-28 17:21:52 -070027 {
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 Tanous2c6ffdb2023-06-28 11:28:38 -070040std::string getRandomUUID();
41
Ed Tanousb7f3a822024-06-05 08:45:25 -070042std::string getRandomIdOfLength(size_t length);
43
Ed Tanous724985f2024-06-05 09:19:06 -070044bool constantTimeStringCompare(std::string_view a, std::string_view b);
45struct ConstantTimeCompare
46{
47 bool operator()(std::string_view a, std::string_view b) const;
48};
49
Ed Tanousfc76b8a2020-09-28 17:21:52 -070050} // namespace bmcweb