1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3 #pragma once 4 5 #include <cstddef> 6 #include <cstdint> 7 #include <limits> 8 #include <string> 9 #include <string_view> 10 11 namespace bmcweb 12 { 13 14 struct OpenSSLGenerator 15 { 16 uint8_t operator()(); 17 maxbmcweb::OpenSSLGenerator18 static constexpr uint8_t max() 19 { 20 return std::numeric_limits<uint8_t>::max(); 21 } minbmcweb::OpenSSLGenerator22 static constexpr uint8_t min() 23 { 24 return std::numeric_limits<uint8_t>::min(); 25 } 26 errorbmcweb::OpenSSLGenerator27 bool error() const 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 41 std::string getRandomUUID(); 42 43 std::string getRandomIdOfLength(size_t length); 44 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 51 } // namespace bmcweb 52