blob: 1844be493a4c482187409e7fb34d79873cdae577 [file] [log] [blame]
Craig Hesling240147a2019-07-22 13:17:33 -07001// Copyright 2019 The Chromium OS Authors. All rights reserved.
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 BIOD_UTILS_H_
6#define BIOD_UTILS_H_
7
Craig Heslingdedf7222021-04-08 13:08:34 -07008#include <string>
Craig Hesling240147a2019-07-22 13:17:33 -07009#include <type_traits>
10
11namespace biod {
12
13// This function can be used to fetch the value of an enum
14// typecasted to it's base type (int if none specified).
15//
16// enum class FlockSize : uint8_t {
17// kOne = 1,
18// kTwo,
19// ...
20// };
21//
22// uint8_t total_animals = to_utype(FlockSize::kTwo);
23template <typename E>
24constexpr auto to_utype(E enumerator) noexcept {
25 return static_cast<std::underlying_type_t<E>>(enumerator);
26}
27
Craig Heslingdedf7222021-04-08 13:08:34 -070028/**
29 * @brief Convert id to a privacy preserving identifier string.
30 *
31 * Log files are uploaded via crash reports and feedback reports.
32 * This function helps ensure that the IDs logged are only unique within
33 * a single crash/feedback report and not across many different reports.
34 * Only use this string for logging purposes.
35 *
36 * @param id A plain text string id.
37 * @return std::string The mutated loggable id string.
38 */
39std::string LogSafeID(const std::string& id);
40
Craig Hesling240147a2019-07-22 13:17:33 -070041} // namespace biod
42
43#endif // BIOD_UTILS_H_