blob: a007556f8b813852b31714c51c6cb48a576d22a3 [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 Tanousd7857202025-01-28 15:32:26 -08005#include <cstddef>
6#include <cstdint>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08007#include <limits>
Ed Tanous2c6ffdb2023-06-28 11:28:38 -07008#include <string>
Ed Tanousd7857202025-01-28 15:32:26 -08009#include <string_view>
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080010
Ed Tanousfc76b8a2020-09-28 17:21:52 -070011namespace bmcweb
12{
13
14struct OpenSSLGenerator
15{
Ed Tanousb7f3a822024-06-05 08:45:25 -070016 uint8_t operator()();
Ed Tanousfc76b8a2020-09-28 17:21:52 -070017
Ed Tanousad0006e2021-05-11 15:55:47 -070018 static constexpr uint8_t max()
Ed Tanousfc76b8a2020-09-28 17:21:52 -070019 {
20 return std::numeric_limits<uint8_t>::max();
21 }
Ed Tanousad0006e2021-05-11 15:55:47 -070022 static constexpr uint8_t min()
Ed Tanousfc76b8a2020-09-28 17:21:52 -070023 {
24 return std::numeric_limits<uint8_t>::min();
25 }
26
Ed Tanous9eb808c2022-01-25 10:19:23 -080027 bool error() const
Ed Tanousfc76b8a2020-09-28 17:21:52 -070028 {
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 Tanous2c6ffdb2023-06-28 11:28:38 -070041std::string getRandomUUID();
42
Ed Tanousb7f3a822024-06-05 08:45:25 -070043std::string getRandomIdOfLength(size_t length);
44
Ed Tanous724985f2024-06-05 09:19:06 -070045bool constantTimeStringCompare(std::string_view a, std::string_view b);
46struct ConstantTimeCompare
47{
48 bool operator()(std::string_view a, std::string_view b) const;
49};
50
Ed Tanousfc76b8a2020-09-28 17:21:52 -070051} // namespace bmcweb