1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3 #pragma once 4 5 #include "logging.hpp" 6 7 #include <limits> 8 #include <string> 9 10 namespace bmcweb 11 { 12 13 struct OpenSSLGenerator 14 { 15 uint8_t operator()(); 16 17 static constexpr uint8_t max() 18 { 19 return std::numeric_limits<uint8_t>::max(); 20 } 21 static constexpr uint8_t min() 22 { 23 return std::numeric_limits<uint8_t>::min(); 24 } 25 26 bool error() const 27 { 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 40 std::string getRandomUUID(); 41 42 std::string getRandomIdOfLength(size_t length); 43 44 bool constantTimeStringCompare(std::string_view a, std::string_view b); 45 struct ConstantTimeCompare 46 { 47 bool operator()(std::string_view a, std::string_view b) const; 48 }; 49 50 } // namespace bmcweb 51