-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconversions.h
34 lines (26 loc) · 918 Bytes
/
conversions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef LIBHWSEC_CONVERSIONS_H_
#define LIBHWSEC_CONVERSIONS_H_
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
namespace hwsec {
// Type conversion from C string buffer (char*) to bytes buffer (uint8_t*)
inline const uint8_t* CStringAsBytesByffer(const char* str) {
return reinterpret_cast<const uint8_t*>(str);
}
inline std::string BytesToString(const std::vector<uint8_t>& bytes) {
return std::string(bytes.begin(), bytes.end());
}
inline base::Optional<std::string> BytesToString(
const base::Optional<std::vector<uint8_t>>& maybe_bytes) {
if (maybe_bytes == base::nullopt) {
return base::nullopt;
}
return BytesToString(*maybe_bytes);
}
} // namespace hwsec
#endif // LIBHWSEC_CONVERSIONS_H_