1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_METRICS_STRUCTURED_LIB_KEY_UTIL_H_ 6 #define COMPONENTS_METRICS_STRUCTURED_LIB_KEY_UTIL_H_ 7 8 #include <optional> 9 #include <string> 10 11 #include "base/values.h" 12 #include "components/metrics/structured/lib/proto/key.pb.h" 13 14 namespace metrics::structured { 15 16 // Key size to hash strings for structured metrics. 17 inline constexpr size_t kKeySize = 32; 18 19 namespace util { 20 21 // Generates a new key to be used for hashing. This function should be used to 22 // create new keys or to replace a key that needs to be rotated. 23 std::string GenerateNewKey(); 24 25 // Helper conversion function between Value and KeyProto. 26 base::Value CreateValueFromKeyProto(const KeyProto& proto); 27 std::optional<KeyProto> CreateKeyProtoFromValue(const base::Value::Dict& value); 28 29 } // namespace util 30 } // namespace metrics::structured 31 32 #endif // COMPONENTS_METRICS_STRUCTURED_LIB_KEY_UTIL_H_ 33