forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTWData.h
127 lines (104 loc) · 4.92 KB
/
TWData.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.
#pragma once
#include "TWBase.h"
TW_EXTERN_C_BEGIN
typedef const void TWString;
/// Defines a resizable block of data.
///
/// The implementantion of these methods should be language-specific to minimize translation overhead. For instance it
/// should be a `jbyteArray` for Java and an `NSData` for Swift.
typedef const void TWData;
/// Creates a block of data from a byte array.
///
/// \param bytes Non-null raw bytes buffer
/// \param size size of the buffer
/// \return Non-null filled block of data.
TWData *_Nonnull TWDataCreateWithBytes(const uint8_t *_Nonnull bytes, size_t size) TW_VISIBILITY_DEFAULT;
/// Creates an uninitialized block of data with the provided size.
///
/// \param size size for the block of data
/// \return Non-null uninitialized block of data with the provided size
TWData *_Nonnull TWDataCreateWithSize(size_t size) TW_VISIBILITY_DEFAULT;
/// Creates a block of data by copying another block of data.
///
/// \param data buffer that need to be copied
/// \return Non-null filled block of data.
TWData *_Nonnull TWDataCreateWithData(TWData *_Nonnull data) TW_VISIBILITY_DEFAULT;
/// Creates a block of data from a hexadecimal string. Odd length is invalid (intended grouping to bytes is not obvious).
///
/// \param hex input hex string
/// \return Non-null filled block of data
TWData *_Nullable TWDataCreateWithHexString(const TWString *_Nonnull hex) TW_VISIBILITY_DEFAULT;
/// Returns the size in bytes.
///
/// \param data A non-null valid block of data
/// \return the size of the given block of data
size_t TWDataSize(TWData *_Nonnull data) TW_VISIBILITY_DEFAULT;
/// Returns the raw pointer to the contents of data.
///
/// \param data A non-null valid block of data
/// \return the raw pointer to the contents of data
uint8_t *_Nonnull TWDataBytes(TWData *_Nonnull data) TW_VISIBILITY_DEFAULT;
/// Returns the byte at the provided index.
///
/// \param data A non-null valid block of data
/// \param index index of the byte that we want to fetch - index need to be < TWDataSize(data)
/// \return the byte at the provided index
uint8_t TWDataGet(TWData *_Nonnull data, size_t index) TW_VISIBILITY_DEFAULT;
/// Sets the byte at the provided index.
///
/// \param data A non-null valid block of data
/// \param index index of the byte that we want to set - index need to be < TWDataSize(data)
/// \param byte Given byte to be written in data
void TWDataSet(TWData *_Nonnull data, size_t index, uint8_t byte) TW_VISIBILITY_DEFAULT;
/// Copies a range of bytes into the provided buffer.
///
/// \param data A non-null valid block of data
/// \param start starting index of the range - index need to be < TWDataSize(data)
/// \param size size of the range we want to copy - size need to be < TWDataSize(data) - start
/// \param output The output buffer where we want to copy the data.
void TWDataCopyBytes(TWData *_Nonnull data, size_t start, size_t size, uint8_t *_Nonnull output) TW_VISIBILITY_DEFAULT;
/// Replaces a range of bytes with the contents of the provided buffer.
///
/// \param data A non-null valid block of data
/// \param start starting index of the range - index need to be < TWDataSize(data)
/// \param size size of the range we want to replace - size need to be < TWDataSize(data) - start
/// \param bytes The buffer that will replace the range of data
void TWDataReplaceBytes(TWData *_Nonnull data, size_t start, size_t size, const uint8_t *_Nonnull bytes) TW_VISIBILITY_DEFAULT;
/// Appends data from a byte array.
///
/// \param data A non-null valid block of data
/// \param bytes Non-null byte array
/// \param size The size of the byte array
void TWDataAppendBytes(TWData *_Nonnull data, const uint8_t *_Nonnull bytes, size_t size) TW_VISIBILITY_DEFAULT;
/// Appends a single byte.
///
/// \param data A non-null valid block of data
/// \param byte A single byte
void TWDataAppendByte(TWData *_Nonnull data, uint8_t byte) TW_VISIBILITY_DEFAULT;
/// Appends a block of data.
///
/// \param data A non-null valid block of data
/// \param append A non-null valid block of data
void TWDataAppendData(TWData *_Nonnull data, TWData *_Nonnull append) TW_VISIBILITY_DEFAULT;
/// Reverse the bytes.
///
/// \param data A non-null valid block of data
void TWDataReverse(TWData *_Nonnull data) TW_VISIBILITY_DEFAULT;
/// Sets all bytes to the given value.
///
/// \param data A non-null valid block of data
void TWDataReset(TWData *_Nonnull data) TW_VISIBILITY_DEFAULT;
/// Deletes a block of data created with a `TWDataCreate*` method.
///
/// \param data A non-null valid block of data
void TWDataDelete(TWData *_Nonnull data) TW_VISIBILITY_DEFAULT;
/// Determines whether two data blocks are equal.
///
/// \param lhs left non null block of data to be compared
/// \param rhs right non null block of data to be compared
/// \return true if both block of data are equal, false otherwise
bool TWDataEqual(TWData *_Nonnull lhs, TWData *_Nonnull rhs) TW_VISIBILITY_DEFAULT;
TW_EXTERN_C_END