bare-buffer 2.5.10 → 2.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +4 -11
- package/package.json +3 -8
- package/prebuilds/android-arm/bare-buffer.bare +0 -0
- package/prebuilds/android-arm64/bare-buffer.bare +0 -0
- package/prebuilds/android-ia32/bare-buffer.bare +0 -0
- package/prebuilds/android-x64/bare-buffer.bare +0 -0
- package/prebuilds/win32-arm64/bare-buffer.bare +0 -0
- package/prebuilds/win32-x64/bare-buffer.bare +0 -0
- package/vendor/libbase64/CMakeLists.txt +0 -70
- package/vendor/libbase64/include/base64.h +0 -128
- package/vendor/libbase64/src/base64.c +0 -10
- package/vendor/libhex/CMakeLists.txt +0 -71
- package/vendor/libhex/include/hex.h +0 -88
- package/vendor/libhex/src/hex.c +0 -10
- package/vendor/libutf/CMakeLists.txt +0 -93
- package/vendor/libutf/include/utf/string.h +0 -786
- package/vendor/libutf/include/utf.h +0 -132
- package/vendor/libutf/src/ascii/validate.c +0 -47
- package/vendor/libutf/src/endianness.c +0 -19
- package/vendor/libutf/src/endianness.h +0 -54
- package/vendor/libutf/src/latin1/convert-to-utf16.c +0 -37
- package/vendor/libutf/src/latin1/convert-to-utf32.c +0 -34
- package/vendor/libutf/src/latin1/convert-to-utf8.c +0 -58
- package/vendor/libutf/src/latin1/length-from-utf16.c +0 -26
- package/vendor/libutf/src/latin1/length-from-utf32.c +0 -26
- package/vendor/libutf/src/latin1/length-from-utf8.c +0 -34
- package/vendor/libutf/src/utf16/convert-to-latin1.c +0 -41
- package/vendor/libutf/src/utf16/convert-to-utf32.c +0 -56
- package/vendor/libutf/src/utf16/convert-to-utf8.c +0 -75
- package/vendor/libutf/src/utf16/length-from-latin1.c +0 -26
- package/vendor/libutf/src/utf16/length-from-utf32.c +0 -33
- package/vendor/libutf/src/utf16/length-from-utf8.c +0 -38
- package/vendor/libutf/src/utf16/validate.c +0 -53
- package/vendor/libutf/src/utf32/convert-to-latin1.c +0 -40
- package/vendor/libutf/src/utf32/convert-to-utf16.c +0 -56
- package/vendor/libutf/src/utf32/convert-to-utf8.c +0 -71
- package/vendor/libutf/src/utf32/length-from-latin1.c +0 -26
- package/vendor/libutf/src/utf32/length-from-utf16.c +0 -35
- package/vendor/libutf/src/utf32/length-from-utf8.c +0 -35
- package/vendor/libutf/src/utf32/validate.c +0 -39
- package/vendor/libutf/src/utf8/convert-to-latin1.c +0 -70
- package/vendor/libutf/src/utf8/convert-to-utf16.c +0 -95
- package/vendor/libutf/src/utf8/convert-to-utf32.c +0 -110
- package/vendor/libutf/src/utf8/length-from-latin1.c +0 -32
- package/vendor/libutf/src/utf8/length-from-utf16.c +0 -44
- package/vendor/libutf/src/utf8/length-from-utf32.c +0 -35
- package/vendor/libutf/src/utf8/string.c +0 -149
- package/vendor/libutf/src/utf8/validate.c +0 -107
package/CMakeLists.txt
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
cmake_minimum_required(VERSION 3.25)
|
|
2
2
|
|
|
3
3
|
find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare)
|
|
4
|
+
find_package(cmake-fetch REQUIRED PATHS node_modules/cmake-fetch)
|
|
4
5
|
|
|
5
6
|
project(bare_buffer C)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if(NOT TARGET base64)
|
|
12
|
-
add_subdirectory(vendor/libbase64 EXCLUDE_FROM_ALL)
|
|
13
|
-
endif()
|
|
14
|
-
|
|
15
|
-
if(NOT TARGET hex)
|
|
16
|
-
add_subdirectory(vendor/libhex EXCLUDE_FROM_ALL)
|
|
17
|
-
endif()
|
|
8
|
+
fetch_package("github:holepunchto/libutf#65b6ba0")
|
|
9
|
+
fetch_package("github:holepunchto/libbase64#4cd8d8b")
|
|
10
|
+
fetch_package("github:holepunchto/libhex#939999b")
|
|
18
11
|
|
|
19
12
|
add_bare_module(bare_buffer)
|
|
20
13
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-buffer",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.11",
|
|
4
4
|
"description": "Native buffers for JavaScript",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -13,13 +13,7 @@
|
|
|
13
13
|
"binding.js",
|
|
14
14
|
"CMakeLists.txt",
|
|
15
15
|
"lib",
|
|
16
|
-
"prebuilds"
|
|
17
|
-
"vendor/libbase64/include",
|
|
18
|
-
"vendor/libbase64/src",
|
|
19
|
-
"vendor/libhex/include",
|
|
20
|
-
"vendor/libhex/src",
|
|
21
|
-
"vendor/libutf/include",
|
|
22
|
-
"vendor/libutf/src"
|
|
16
|
+
"prebuilds"
|
|
23
17
|
],
|
|
24
18
|
"addon": true,
|
|
25
19
|
"scripts": {
|
|
@@ -38,6 +32,7 @@
|
|
|
38
32
|
"devDependencies": {
|
|
39
33
|
"brittle": "^3.1.1",
|
|
40
34
|
"cmake-bare": "^1.1.6",
|
|
35
|
+
"cmake-fetch": "^1.0.0",
|
|
41
36
|
"standard": "^17.0.0"
|
|
42
37
|
}
|
|
43
38
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
cmake_minimum_required(VERSION 3.22)
|
|
2
|
-
|
|
3
|
-
project(base64 C)
|
|
4
|
-
|
|
5
|
-
if(NOT TARGET utf)
|
|
6
|
-
add_subdirectory(vendor/libutf EXCLUDE_FROM_ALL)
|
|
7
|
-
endif()
|
|
8
|
-
|
|
9
|
-
add_library(base64 OBJECT)
|
|
10
|
-
|
|
11
|
-
set_target_properties(
|
|
12
|
-
base64
|
|
13
|
-
PROPERTIES
|
|
14
|
-
C_STANDARD 99
|
|
15
|
-
POSITION_INDEPENDENT_CODE ON
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
target_sources(
|
|
19
|
-
base64
|
|
20
|
-
INTERFACE
|
|
21
|
-
include/base64.h
|
|
22
|
-
PRIVATE
|
|
23
|
-
src/base64.c
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
target_include_directories(
|
|
27
|
-
base64
|
|
28
|
-
PUBLIC
|
|
29
|
-
include
|
|
30
|
-
$<TARGET_PROPERTY:utf,INTERFACE_INCLUDE_DIRECTORIES>
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
add_library(base64_shared SHARED)
|
|
34
|
-
|
|
35
|
-
set_target_properties(
|
|
36
|
-
base64_shared
|
|
37
|
-
PROPERTIES
|
|
38
|
-
OUTPUT_NAME base64
|
|
39
|
-
WINDOWS_EXPORT_ALL_SYMBOLS ON
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
target_link_libraries(
|
|
43
|
-
base64_shared
|
|
44
|
-
PUBLIC
|
|
45
|
-
base64
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
add_library(base64_static STATIC)
|
|
49
|
-
|
|
50
|
-
set_target_properties(
|
|
51
|
-
base64_static
|
|
52
|
-
PROPERTIES
|
|
53
|
-
OUTPUT_NAME base64
|
|
54
|
-
PREFIX lib
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
target_link_libraries(
|
|
58
|
-
base64_static
|
|
59
|
-
PUBLIC
|
|
60
|
-
base64
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
install(TARGETS base64_shared base64_static)
|
|
64
|
-
|
|
65
|
-
install(FILES include/base64.h DESTINATION include)
|
|
66
|
-
|
|
67
|
-
if(PROJECT_IS_TOP_LEVEL)
|
|
68
|
-
enable_testing()
|
|
69
|
-
add_subdirectory(test)
|
|
70
|
-
endif()
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
#ifndef BASE64_H
|
|
2
|
-
#define BASE64_H
|
|
3
|
-
|
|
4
|
-
#include <stdbool.h>
|
|
5
|
-
#include <stddef.h>
|
|
6
|
-
#include <stdint.h>
|
|
7
|
-
#include <utf.h>
|
|
8
|
-
|
|
9
|
-
#ifdef __cplusplus
|
|
10
|
-
extern "C" {
|
|
11
|
-
#endif
|
|
12
|
-
|
|
13
|
-
static const char base64__alphabet[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
14
|
-
|
|
15
|
-
static const char base64__inverse_alphabet[256] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 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, -1, -1, -1, -1, -1, -1, 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, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
|
|
16
|
-
|
|
17
|
-
static inline int
|
|
18
|
-
base64__encode (const uint8_t *buffer, size_t buffer_len, utf8_t *string, size_t *string_len) {
|
|
19
|
-
size_t len = 4 * ((buffer_len + 2) / 3);
|
|
20
|
-
|
|
21
|
-
if (string == NULL) {
|
|
22
|
-
*string_len = len;
|
|
23
|
-
return 0;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (*string_len < len) return -1;
|
|
27
|
-
|
|
28
|
-
bool terminate = *string_len > len;
|
|
29
|
-
|
|
30
|
-
*string_len = len;
|
|
31
|
-
|
|
32
|
-
size_t k = 0, i = 0, n = buffer_len;
|
|
33
|
-
|
|
34
|
-
uint8_t a, b, c;
|
|
35
|
-
|
|
36
|
-
for (; i + 2 < n; i += 3) {
|
|
37
|
-
a = buffer[i];
|
|
38
|
-
b = buffer[i + 1];
|
|
39
|
-
c = buffer[i + 2];
|
|
40
|
-
|
|
41
|
-
string[k++] = base64__alphabet[a >> 2];
|
|
42
|
-
string[k++] = base64__alphabet[((a & 0x03) << 4) | (b >> 4)];
|
|
43
|
-
string[k++] = base64__alphabet[((b & 0x0f) << 2) | (c >> 6)];
|
|
44
|
-
string[k++] = base64__alphabet[c & 0x3f];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (i < n) {
|
|
48
|
-
a = buffer[i];
|
|
49
|
-
|
|
50
|
-
string[k++] = base64__alphabet[a >> 2];
|
|
51
|
-
|
|
52
|
-
if (i + 1 < n) {
|
|
53
|
-
b = buffer[i + 1];
|
|
54
|
-
|
|
55
|
-
string[k++] = base64__alphabet[((a & 0x03) << 4) | (b >> 4)];
|
|
56
|
-
string[k++] = base64__alphabet[(b & 0x0f) << 2];
|
|
57
|
-
} else {
|
|
58
|
-
string[k++] = base64__alphabet[(a & 0x03) << 4];
|
|
59
|
-
string[k++] = '=';
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
string[k++] = '=';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (terminate) string[k] = '\0';
|
|
66
|
-
|
|
67
|
-
return 0;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
static inline int
|
|
71
|
-
base64__decode (const utf8_t *string, size_t string_len, uint8_t *buffer, size_t *buffer_len) {
|
|
72
|
-
if (string_len % 4 != 0) return -1;
|
|
73
|
-
|
|
74
|
-
if (string_len == 0) {
|
|
75
|
-
*buffer_len = 0;
|
|
76
|
-
return 0;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
size_t len = string_len / 4 * 3;
|
|
80
|
-
|
|
81
|
-
if (string[string_len - 1] == '=') len--;
|
|
82
|
-
if (string[string_len - 2] == '=') len--;
|
|
83
|
-
|
|
84
|
-
if (buffer == NULL) {
|
|
85
|
-
*buffer_len = len;
|
|
86
|
-
return 0;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (*buffer_len < len) return -1;
|
|
90
|
-
|
|
91
|
-
*buffer_len = len;
|
|
92
|
-
|
|
93
|
-
size_t k = 0;
|
|
94
|
-
|
|
95
|
-
for (size_t i = 0, n = string_len; i < n; i += 4) {
|
|
96
|
-
char chunk[4];
|
|
97
|
-
|
|
98
|
-
for (size_t j = 0; j < 4; j++) {
|
|
99
|
-
chunk[j] = string[i + j] == '=' ? 0 : base64__inverse_alphabet[string[i + j]];
|
|
100
|
-
|
|
101
|
-
if (chunk[j] == (char) -1) return -1;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
uint32_t triple = (chunk[0] << 3 * 6) + (chunk[1] << 2 * 6) + (chunk[2] << 1 * 6) + (chunk[3] << 0 * 6);
|
|
105
|
-
|
|
106
|
-
if (k < len) buffer[k++] = (triple >> 2 * 8) & 0xFF;
|
|
107
|
-
if (k < len) buffer[k++] = (triple >> 1 * 8) & 0xFF;
|
|
108
|
-
if (k < len) buffer[k++] = (triple >> 0 * 8) & 0xFF;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return 0;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
inline int
|
|
115
|
-
base64_encode (const uint8_t *buffer, size_t buffer_len, utf8_t *string, size_t *string_len) {
|
|
116
|
-
return base64__encode(buffer, buffer_len, string, string_len);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
inline int
|
|
120
|
-
base64_decode (const utf8_t *string, size_t string_len, uint8_t *buffer, size_t *buffer_len) {
|
|
121
|
-
return base64__decode(string, string_len, buffer, buffer_len);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
#ifdef __cplusplus
|
|
125
|
-
}
|
|
126
|
-
#endif
|
|
127
|
-
|
|
128
|
-
#endif // BASE64_H
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#include <stdint.h>
|
|
2
|
-
#include <utf.h>
|
|
3
|
-
|
|
4
|
-
#include "../include/base64.h"
|
|
5
|
-
|
|
6
|
-
extern int
|
|
7
|
-
base64_encode (const uint8_t *buffer, size_t buffer_len, utf8_t *string, size_t *string_len);
|
|
8
|
-
|
|
9
|
-
extern int
|
|
10
|
-
base64_decode (const utf8_t *string, size_t string_len, uint8_t *buffer, size_t *buffer_len);
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
cmake_minimum_required(VERSION 3.22)
|
|
2
|
-
|
|
3
|
-
project(hex C)
|
|
4
|
-
|
|
5
|
-
if(NOT TARGET utf)
|
|
6
|
-
add_subdirectory(vendor/libutf EXCLUDE_FROM_ALL)
|
|
7
|
-
endif()
|
|
8
|
-
|
|
9
|
-
add_library(hex OBJECT)
|
|
10
|
-
|
|
11
|
-
set_target_properties(
|
|
12
|
-
hex
|
|
13
|
-
PROPERTIES
|
|
14
|
-
C_STANDARD 99
|
|
15
|
-
POSITION_INDEPENDENT_CODE ON
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
target_sources(
|
|
19
|
-
hex
|
|
20
|
-
INTERFACE
|
|
21
|
-
include/hex.h
|
|
22
|
-
PRIVATE
|
|
23
|
-
src/hex.c
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
target_include_directories(
|
|
27
|
-
hex
|
|
28
|
-
PUBLIC
|
|
29
|
-
include
|
|
30
|
-
$<TARGET_PROPERTY:utf,INTERFACE_INCLUDE_DIRECTORIES>
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
add_library(hex_shared SHARED)
|
|
34
|
-
|
|
35
|
-
set_target_properties(
|
|
36
|
-
hex_shared
|
|
37
|
-
PROPERTIES
|
|
38
|
-
OUTPUT_NAME hex
|
|
39
|
-
WINDOWS_EXPORT_ALL_SYMBOLS ON
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
target_link_libraries(
|
|
43
|
-
hex_shared
|
|
44
|
-
PUBLIC
|
|
45
|
-
hex
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
add_library(hex_static STATIC)
|
|
49
|
-
|
|
50
|
-
set_target_properties(
|
|
51
|
-
hex_static
|
|
52
|
-
PROPERTIES
|
|
53
|
-
OUTPUT_NAME hex
|
|
54
|
-
PREFIX lib
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
target_link_libraries(
|
|
58
|
-
hex_static
|
|
59
|
-
PUBLIC
|
|
60
|
-
hex
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
install(TARGETS hex_shared hex_static)
|
|
64
|
-
|
|
65
|
-
install(FILES include/hex.h DESTINATION include)
|
|
66
|
-
|
|
67
|
-
if(PROJECT_IS_TOP_LEVEL)
|
|
68
|
-
enable_testing()
|
|
69
|
-
|
|
70
|
-
add_subdirectory(test)
|
|
71
|
-
endif()
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
#ifndef HEX_H
|
|
2
|
-
#define HEX_H
|
|
3
|
-
|
|
4
|
-
#include <stdbool.h>
|
|
5
|
-
#include <stddef.h>
|
|
6
|
-
#include <stdint.h>
|
|
7
|
-
#include <utf.h>
|
|
8
|
-
|
|
9
|
-
#ifdef __cplusplus
|
|
10
|
-
extern "C" {
|
|
11
|
-
#endif
|
|
12
|
-
|
|
13
|
-
static const char hex__alphabet[16] = "0123456789abcdef";
|
|
14
|
-
|
|
15
|
-
static const char hex__inverse_alphabet[256] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
|
|
16
|
-
|
|
17
|
-
static inline int
|
|
18
|
-
hex__encode (const uint8_t *buffer, size_t buffer_len, utf8_t *string, size_t *string_len) {
|
|
19
|
-
size_t len = buffer_len * 2;
|
|
20
|
-
|
|
21
|
-
if (string == NULL) {
|
|
22
|
-
*string_len = len;
|
|
23
|
-
return 0;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (*string_len < len) return -1;
|
|
27
|
-
|
|
28
|
-
bool terminate = *string_len > len;
|
|
29
|
-
|
|
30
|
-
*string_len = len;
|
|
31
|
-
|
|
32
|
-
size_t k = 0;
|
|
33
|
-
|
|
34
|
-
for (size_t i = 0, n = buffer_len; i < n; i++) {
|
|
35
|
-
string[k++] = hex__alphabet[buffer[i] >> 4];
|
|
36
|
-
string[k++] = hex__alphabet[buffer[i] & 0x0f];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (terminate) string[k] = '\0';
|
|
40
|
-
|
|
41
|
-
return 0;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static inline int
|
|
45
|
-
hex__decode (const utf8_t *string, size_t string_len, uint8_t *buffer, size_t *buffer_len) {
|
|
46
|
-
size_t len = string_len >> 1;
|
|
47
|
-
|
|
48
|
-
if (buffer == NULL) {
|
|
49
|
-
*buffer_len = len;
|
|
50
|
-
return 0;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (*buffer_len < len) return -1;
|
|
54
|
-
|
|
55
|
-
*buffer_len = len;
|
|
56
|
-
|
|
57
|
-
size_t k = 0;
|
|
58
|
-
|
|
59
|
-
for (size_t i = 0, n = string_len; i < n; i += 2) {
|
|
60
|
-
char chunk[2];
|
|
61
|
-
|
|
62
|
-
for (size_t j = 0; j < 2; j++) {
|
|
63
|
-
chunk[j] = i + j < n ? hex__inverse_alphabet[string[i + j]] : 0;
|
|
64
|
-
|
|
65
|
-
if (chunk[j] == (char) -1) return -1;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
buffer[k++] = (chunk[0] << 4) | chunk[1];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return 0;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
inline int
|
|
75
|
-
hex_encode (const uint8_t *buffer, size_t buffer_len, utf8_t *string, size_t *string_len) {
|
|
76
|
-
return hex__encode(buffer, buffer_len, string, string_len);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
inline int
|
|
80
|
-
hex_decode (const utf8_t *string, size_t string_len, uint8_t *buffer, size_t *buffer_len) {
|
|
81
|
-
return hex__decode(string, string_len, buffer, buffer_len);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
#ifdef __cplusplus
|
|
85
|
-
}
|
|
86
|
-
#endif
|
|
87
|
-
|
|
88
|
-
#endif // HEX_H
|
package/vendor/libhex/src/hex.c
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#include <stdint.h>
|
|
2
|
-
#include <utf.h>
|
|
3
|
-
|
|
4
|
-
#include "../include/hex.h"
|
|
5
|
-
|
|
6
|
-
extern int
|
|
7
|
-
hex_encode (const uint8_t *buffer, size_t buffer_len, utf8_t *string, size_t *string_len);
|
|
8
|
-
|
|
9
|
-
extern int
|
|
10
|
-
hex_decode (const utf8_t *string, size_t string_len, uint8_t *buffer, size_t *buffer_len);
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
cmake_minimum_required(VERSION 3.25)
|
|
2
|
-
|
|
3
|
-
project(utf C)
|
|
4
|
-
|
|
5
|
-
add_library(utf OBJECT)
|
|
6
|
-
|
|
7
|
-
set_target_properties(
|
|
8
|
-
utf
|
|
9
|
-
PROPERTIES
|
|
10
|
-
C_STANDARD 99
|
|
11
|
-
POSITION_INDEPENDENT_CODE ON
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
target_sources(
|
|
15
|
-
utf
|
|
16
|
-
INTERFACE
|
|
17
|
-
include/utf.h
|
|
18
|
-
include/utf/string.h
|
|
19
|
-
PRIVATE
|
|
20
|
-
src/endianness.c
|
|
21
|
-
src/endianness.h
|
|
22
|
-
src/ascii/validate.c
|
|
23
|
-
src/utf8/convert-to-latin1.c
|
|
24
|
-
src/utf8/convert-to-utf16.c
|
|
25
|
-
src/utf8/convert-to-utf32.c
|
|
26
|
-
src/utf8/length-from-latin1.c
|
|
27
|
-
src/utf8/length-from-utf16.c
|
|
28
|
-
src/utf8/length-from-utf32.c
|
|
29
|
-
src/utf8/string.c
|
|
30
|
-
src/utf8/validate.c
|
|
31
|
-
src/utf16/convert-to-latin1.c
|
|
32
|
-
src/utf16/convert-to-utf8.c
|
|
33
|
-
src/utf16/convert-to-utf32.c
|
|
34
|
-
src/utf16/length-from-latin1.c
|
|
35
|
-
src/utf16/length-from-utf8.c
|
|
36
|
-
src/utf16/length-from-utf32.c
|
|
37
|
-
src/utf16/validate.c
|
|
38
|
-
src/utf32/convert-to-latin1.c
|
|
39
|
-
src/utf32/convert-to-utf8.c
|
|
40
|
-
src/utf32/convert-to-utf16.c
|
|
41
|
-
src/utf32/length-from-latin1.c
|
|
42
|
-
src/utf32/length-from-utf8.c
|
|
43
|
-
src/utf32/length-from-utf16.c
|
|
44
|
-
src/utf32/validate.c
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
target_include_directories(
|
|
48
|
-
utf
|
|
49
|
-
PUBLIC
|
|
50
|
-
include
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
add_library(utf_shared SHARED)
|
|
54
|
-
|
|
55
|
-
set_target_properties(
|
|
56
|
-
utf_shared
|
|
57
|
-
PROPERTIES
|
|
58
|
-
OUTPUT_NAME utf
|
|
59
|
-
WINDOWS_EXPORT_ALL_SYMBOLS ON
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
target_link_libraries(
|
|
63
|
-
utf_shared
|
|
64
|
-
PUBLIC
|
|
65
|
-
utf
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
add_library(utf_static STATIC)
|
|
69
|
-
|
|
70
|
-
set_target_properties(
|
|
71
|
-
utf_static
|
|
72
|
-
PROPERTIES
|
|
73
|
-
OUTPUT_NAME utf
|
|
74
|
-
PREFIX lib
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
target_link_libraries(
|
|
78
|
-
utf_static
|
|
79
|
-
PUBLIC
|
|
80
|
-
utf
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
install(TARGETS utf_shared utf_static)
|
|
84
|
-
|
|
85
|
-
install(FILES include/utf.h DESTINATION include)
|
|
86
|
-
|
|
87
|
-
install(DIRECTORY include/utf DESTINATION include)
|
|
88
|
-
|
|
89
|
-
if(PROJECT_IS_TOP_LEVEL)
|
|
90
|
-
enable_testing()
|
|
91
|
-
|
|
92
|
-
add_subdirectory(test)
|
|
93
|
-
endif()
|