1
// Copyright © 2017-2020 Trust Wallet.
2
//
3
// This file is part of Trust. The full Trust copyright notice, including
4
// terms governing use, modification, and redistribution, is contained in the
5
// file LICENSE at the root of the source code distribution tree.
6

7
#pragma once
8

9
#include <cstdint>
10
#include <vector>
11
#include <string>
12
#include <array>
13

14
namespace TW {
15

16
using byte = std::uint8_t;
17
using Data = std::vector<byte>;
18

19 1
inline void pad_left(Data& data, const uint32_t size) {
20 1
    data.insert(data.begin(), size - data.size(), 0);
21
}
22

23 1
inline Data data(const std::string& data) {
24 1
    return std::vector<byte>(data.begin(), data.end());
25
}
26

27 1
inline Data data(const byte* data, size_t size) {
28 1
    return std::vector<byte>(data, data + size);
29
}
30

31 1
inline void append(Data& data, const Data& suffix) {
32 1
    data.insert(data.end(), suffix.begin(), suffix.end());
33
}
34

35 1
inline void append(Data& data, const byte suffix) {
36 1
    data.push_back(suffix);
37
}
38

39
/// Return a part (subdata) of the requested size of the input data.
40
Data subData(const Data& data, size_t index, size_t length);
41

42
/// Determines if a byte array has a specific prefix.
43
template <typename T>
44 1
inline bool has_prefix(const Data& data, T& prefix) {
45 1
    return std::equal(prefix.begin(), prefix.end(), data.begin(), data.begin() + std::min(data.size(), prefix.size()));
46
}
47

48
} // namespace TW

Read our documentation on viewing source code .

Loading