pybase16384 0.3.5__cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl → 0.3.7__cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
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.
Potentially problematic release.
This version of pybase16384 might be problematic. Click here for more details.
- pybase16384/__init__.py +91 -1
- pybase16384/backends/cffi/__init__.py +189 -14
- pybase16384/backends/cffi/_core.abi3.so +0 -0
- pybase16384/backends/cffi/build.py +40 -2
- pybase16384/backends/cython/__init__.py +15 -0
- pybase16384/backends/cython/_core.abi3.so +0 -0
- pybase16384/backends/cython/_core.c +8013 -2264
- pybase16384/backends/cython/_core.pyx +256 -6
- pybase16384/backends/cython/base16384.pxd +46 -2
- {pybase16384-0.3.5.dist-info → pybase16384-0.3.7.dist-info}/METADATA +59 -11
- pybase16384-0.3.7.dist-info/RECORD +16 -0
- pybase16384-0.3.5.dist-info/RECORD +0 -16
- {pybase16384-0.3.5.dist-info → pybase16384-0.3.7.dist-info}/LICENSE +0 -0
- {pybase16384-0.3.5.dist-info → pybase16384-0.3.7.dist-info}/WHEEL +0 -0
- {pybase16384-0.3.5.dist-info → pybase16384-0.3.7.dist-info}/top_level.txt +0 -0
pybase16384/__init__.py
CHANGED
|
@@ -17,38 +17,68 @@ def _should_use_cffi() -> bool:
|
|
|
17
17
|
|
|
18
18
|
if not _should_use_cffi():
|
|
19
19
|
from pybase16384.backends.cython import (
|
|
20
|
+
DECBUFSZ,
|
|
21
|
+
ENCBUFSZ,
|
|
22
|
+
FLAG_DO_SUM_CHECK_FORCELY,
|
|
23
|
+
FLAG_NOHEADER,
|
|
24
|
+
FLAG_SUM_CHECK_ON_REMAIN,
|
|
20
25
|
_decode,
|
|
21
26
|
_decode_into,
|
|
27
|
+
_decode_into_safe,
|
|
28
|
+
_decode_safe,
|
|
22
29
|
_encode,
|
|
23
30
|
_encode_into,
|
|
31
|
+
_encode_into_safe,
|
|
32
|
+
_encode_safe,
|
|
24
33
|
decode_fd,
|
|
34
|
+
decode_fd_detailed,
|
|
25
35
|
decode_file,
|
|
36
|
+
decode_file_safe,
|
|
26
37
|
decode_len,
|
|
27
38
|
decode_local_file,
|
|
39
|
+
decode_local_file_detailed,
|
|
28
40
|
encode_fd,
|
|
41
|
+
encode_fd_detailed,
|
|
29
42
|
encode_file,
|
|
43
|
+
encode_file_safe,
|
|
30
44
|
encode_len,
|
|
31
45
|
encode_local_file,
|
|
46
|
+
encode_local_file_detailed,
|
|
32
47
|
is_64bits,
|
|
33
48
|
)
|
|
34
49
|
else:
|
|
35
50
|
from pybase16384.backends.cffi import (
|
|
51
|
+
DECBUFSZ,
|
|
52
|
+
ENCBUFSZ,
|
|
53
|
+
FLAG_DO_SUM_CHECK_FORCELY,
|
|
54
|
+
FLAG_NOHEADER,
|
|
55
|
+
FLAG_SUM_CHECK_ON_REMAIN,
|
|
36
56
|
_decode,
|
|
37
57
|
_decode_into,
|
|
58
|
+
_decode_into_safe,
|
|
59
|
+
_decode_safe,
|
|
38
60
|
_encode,
|
|
39
61
|
_encode_into,
|
|
62
|
+
_encode_into_safe,
|
|
63
|
+
_encode_safe,
|
|
40
64
|
decode_fd,
|
|
65
|
+
decode_fd_detailed,
|
|
41
66
|
decode_file,
|
|
67
|
+
decode_file_safe,
|
|
42
68
|
decode_len,
|
|
43
69
|
decode_local_file,
|
|
70
|
+
decode_local_file_detailed,
|
|
44
71
|
encode_fd,
|
|
72
|
+
encode_fd_detailed,
|
|
45
73
|
encode_file,
|
|
74
|
+
encode_file_safe,
|
|
46
75
|
encode_len,
|
|
47
76
|
encode_local_file,
|
|
77
|
+
encode_local_file_detailed,
|
|
48
78
|
is_64bits,
|
|
49
79
|
)
|
|
50
80
|
|
|
51
|
-
__version__ = "0.3.
|
|
81
|
+
__version__ = "0.3.7"
|
|
52
82
|
|
|
53
83
|
|
|
54
84
|
def encode(data: bytes) -> bytes:
|
|
@@ -58,6 +88,13 @@ def encode(data: bytes) -> bytes:
|
|
|
58
88
|
return out.getvalue()
|
|
59
89
|
|
|
60
90
|
|
|
91
|
+
def encode_safe(data: bytes) -> bytes:
|
|
92
|
+
inp = BytesIO(data)
|
|
93
|
+
out = BytesIO()
|
|
94
|
+
encode_file_safe(inp, out, False, len(data) // 7)
|
|
95
|
+
return out.getvalue()
|
|
96
|
+
|
|
97
|
+
|
|
61
98
|
def decode(data: bytes) -> bytes:
|
|
62
99
|
inp = BytesIO(data)
|
|
63
100
|
out = BytesIO()
|
|
@@ -65,6 +102,13 @@ def decode(data: bytes) -> bytes:
|
|
|
65
102
|
return out.getvalue()
|
|
66
103
|
|
|
67
104
|
|
|
105
|
+
def decode_safe(data: bytes) -> bytes:
|
|
106
|
+
inp = BytesIO(data)
|
|
107
|
+
out = BytesIO()
|
|
108
|
+
decode_file_safe(inp, out, len(data) // 8)
|
|
109
|
+
return out.getvalue()
|
|
110
|
+
|
|
111
|
+
|
|
68
112
|
def encode_from_string(data: str, write_head: bool = False) -> bytes:
|
|
69
113
|
bt = data.encode()
|
|
70
114
|
inp = BytesIO(bt)
|
|
@@ -73,6 +117,14 @@ def encode_from_string(data: str, write_head: bool = False) -> bytes:
|
|
|
73
117
|
return out.getvalue()
|
|
74
118
|
|
|
75
119
|
|
|
120
|
+
def encode_from_string_safe(data: str, write_head: bool = False) -> bytes:
|
|
121
|
+
bt = data.encode()
|
|
122
|
+
inp = BytesIO(bt)
|
|
123
|
+
out = BytesIO()
|
|
124
|
+
encode_file_safe(inp, out, write_head, len(bt) // 7)
|
|
125
|
+
return out.getvalue()
|
|
126
|
+
|
|
127
|
+
|
|
76
128
|
def encode_to_string(data: bytes) -> str:
|
|
77
129
|
inp = BytesIO(data)
|
|
78
130
|
out = BytesIO()
|
|
@@ -80,6 +132,13 @@ def encode_to_string(data: bytes) -> str:
|
|
|
80
132
|
return out.getvalue().decode("utf-16-be")
|
|
81
133
|
|
|
82
134
|
|
|
135
|
+
def encode_to_string_safe(data: bytes) -> str:
|
|
136
|
+
inp = BytesIO(data)
|
|
137
|
+
out = BytesIO()
|
|
138
|
+
encode_file_safe(inp, out, False, len(data) // 7)
|
|
139
|
+
return out.getvalue().decode("utf-16-be")
|
|
140
|
+
|
|
141
|
+
|
|
83
142
|
def encode_string(data: str) -> str:
|
|
84
143
|
data = data.encode()
|
|
85
144
|
inp = BytesIO(data)
|
|
@@ -88,6 +147,14 @@ def encode_string(data: str) -> str:
|
|
|
88
147
|
return out.getvalue().decode("utf-16-be")
|
|
89
148
|
|
|
90
149
|
|
|
150
|
+
def encode_string_safe(data: str) -> str:
|
|
151
|
+
data = data.encode()
|
|
152
|
+
inp = BytesIO(data)
|
|
153
|
+
out = BytesIO()
|
|
154
|
+
encode_file_safe(inp, out, False, len(data) // 7)
|
|
155
|
+
return out.getvalue().decode("utf-16-be")
|
|
156
|
+
|
|
157
|
+
|
|
91
158
|
def decode_from_bytes(data: bytes) -> str:
|
|
92
159
|
inp = BytesIO(data)
|
|
93
160
|
out = BytesIO()
|
|
@@ -95,6 +162,13 @@ def decode_from_bytes(data: bytes) -> str:
|
|
|
95
162
|
return out.getvalue().decode()
|
|
96
163
|
|
|
97
164
|
|
|
165
|
+
def decode_from_bytes_safe(data: bytes) -> str:
|
|
166
|
+
inp = BytesIO(data)
|
|
167
|
+
out = BytesIO()
|
|
168
|
+
decode_file_safe(inp, out, len(data) // 8)
|
|
169
|
+
return out.getvalue().decode()
|
|
170
|
+
|
|
171
|
+
|
|
98
172
|
def decode_from_string(data: str) -> bytes:
|
|
99
173
|
bt = data.encode("utf-16-be")
|
|
100
174
|
inp = BytesIO(bt)
|
|
@@ -103,9 +177,25 @@ def decode_from_string(data: str) -> bytes:
|
|
|
103
177
|
return out.getvalue()
|
|
104
178
|
|
|
105
179
|
|
|
180
|
+
def decode_from_string_safe(data: str) -> bytes:
|
|
181
|
+
bt = data.encode("utf-16-be")
|
|
182
|
+
inp = BytesIO(bt)
|
|
183
|
+
out = BytesIO()
|
|
184
|
+
decode_file_safe(inp, out, len(bt) // 8)
|
|
185
|
+
return out.getvalue()
|
|
186
|
+
|
|
187
|
+
|
|
106
188
|
def decode_string(data: str) -> str:
|
|
107
189
|
bt = data.encode("utf-16-be")
|
|
108
190
|
inp = BytesIO(bt)
|
|
109
191
|
out = BytesIO()
|
|
110
192
|
decode_file(inp, out, len(bt) // 8)
|
|
111
193
|
return out.getvalue().decode()
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def decode_string_safe(data: str) -> str:
|
|
197
|
+
bt = data.encode("utf-16-be")
|
|
198
|
+
inp = BytesIO(bt)
|
|
199
|
+
out = BytesIO()
|
|
200
|
+
decode_file_safe(inp, out, len(bt) // 8)
|
|
201
|
+
return out.getvalue().decode()
|
|
@@ -11,6 +11,12 @@ __version__ = "0.1.0"
|
|
|
11
11
|
encode_len = lib.base16384_encode_len
|
|
12
12
|
decode_len = lib.base16384_decode_len
|
|
13
13
|
|
|
14
|
+
ENCBUFSZ = lib.get_encsize()
|
|
15
|
+
DECBUFSZ = lib.get_decsize()
|
|
16
|
+
FLAG_NOHEADER = lib.BASE16384_FLAG_NOHEADER_()
|
|
17
|
+
FLAG_SUM_CHECK_ON_REMAIN = lib.BASE16384_FLAG_SUM_CHECK_ON_REMAIN_()
|
|
18
|
+
FLAG_DO_SUM_CHECK_FORCELY = lib.BASE16384_FLAG_DO_SUM_CHECK_FORCELY_()
|
|
19
|
+
|
|
14
20
|
|
|
15
21
|
# -----------------low level api------------------------------
|
|
16
22
|
def _encode(data: bytes) -> bytes:
|
|
@@ -23,8 +29,22 @@ def _encode(data: bytes) -> bytes:
|
|
|
23
29
|
return ffi.unpack(output_buf, count)
|
|
24
30
|
|
|
25
31
|
|
|
32
|
+
def _encode_safe(data: bytes) -> bytes:
|
|
33
|
+
length = len(data)
|
|
34
|
+
output_size = encode_len(length)
|
|
35
|
+
output_buf = ffi.new(f"char[{output_size}]")
|
|
36
|
+
if output_buf == ffi.NULL:
|
|
37
|
+
raise MemoryError
|
|
38
|
+
count = lib.base16384_encode_safe(ffi.from_buffer(data), length, output_buf)
|
|
39
|
+
return ffi.unpack(output_buf, count)
|
|
40
|
+
|
|
41
|
+
|
|
26
42
|
def _encode_into(data: bytes, out: bytearray) -> int:
|
|
27
|
-
return lib.base16384_encode(
|
|
43
|
+
return lib.base16384_encode(ffi.from_buffer(data), len(data), ffi.from_buffer(out))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _encode_into_safe(data: bytes, out: bytearray) -> int:
|
|
47
|
+
return lib.base16384_encode_safe(
|
|
28
48
|
ffi.from_buffer(data), len(data), ffi.from_buffer(out)
|
|
29
49
|
)
|
|
30
50
|
|
|
@@ -39,8 +59,22 @@ def _decode(data: bytes) -> bytes:
|
|
|
39
59
|
return ffi.unpack(output_buf, count)
|
|
40
60
|
|
|
41
61
|
|
|
62
|
+
def _decode_safe(data: bytes) -> bytes:
|
|
63
|
+
length = len(data)
|
|
64
|
+
output_size = decode_len(length, 0)
|
|
65
|
+
output_buf = ffi.new(f"char[{output_size}]")
|
|
66
|
+
if output_buf == ffi.NULL:
|
|
67
|
+
raise MemoryError
|
|
68
|
+
count = lib.base16384_decode_safe(ffi.from_buffer(data), length, output_buf)
|
|
69
|
+
return ffi.unpack(output_buf, count)
|
|
70
|
+
|
|
71
|
+
|
|
42
72
|
def _decode_into(data: bytes, out: bytearray) -> int:
|
|
43
|
-
return lib.base16384_decode(
|
|
73
|
+
return lib.base16384_decode(ffi.from_buffer(data), len(data), ffi.from_buffer(out))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _decode_into_safe(data: bytes, out: bytearray) -> int:
|
|
77
|
+
return lib.base16384_decode_safe(
|
|
44
78
|
ffi.from_buffer(data), len(data), ffi.from_buffer(out)
|
|
45
79
|
)
|
|
46
80
|
|
|
@@ -92,9 +126,51 @@ def encode_file(input: IO, output: IO, write_head: bool = False, buf_rate: int =
|
|
|
92
126
|
input.seek(-size, 1)
|
|
93
127
|
continue
|
|
94
128
|
|
|
95
|
-
count = lib.base16384_encode(
|
|
96
|
-
|
|
129
|
+
count = lib.base16384_encode(ffi.from_buffer(chunk), size, output_buf)
|
|
130
|
+
output.write(ffi.unpack(output_buf, count))
|
|
131
|
+
if size < 7:
|
|
132
|
+
break
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def encode_file_safe(
|
|
136
|
+
input: IO, output: IO, write_head: bool = False, buf_rate: int = 10
|
|
137
|
+
):
|
|
138
|
+
if not _check_file(input):
|
|
139
|
+
raise TypeError(
|
|
140
|
+
"input except a file-like object, got %s" % type(input).__name__
|
|
141
|
+
)
|
|
142
|
+
if not _check_file(output):
|
|
143
|
+
raise TypeError(
|
|
144
|
+
"output except a file-like object, got %s" % type(input).__name__
|
|
97
145
|
)
|
|
146
|
+
if buf_rate <= 0:
|
|
147
|
+
buf_rate = 1
|
|
148
|
+
if write_head:
|
|
149
|
+
output.write(b"\xfe\xff")
|
|
150
|
+
|
|
151
|
+
current_buf_len: int = buf_rate * 7 # 一次读取这么多字节
|
|
152
|
+
output_size: int = encode_len(current_buf_len) # 因为encode_len不是单调的 safe不用加16
|
|
153
|
+
output_buf = ffi.new(f"char[{output_size}]")
|
|
154
|
+
if output_buf == ffi.NULL:
|
|
155
|
+
raise MemoryError
|
|
156
|
+
first_check: int = 1 # 检查一次就行了 怎么可能出现第一次读出来是bytes 以后又变卦了的对象呢 不会吧不会吧
|
|
157
|
+
while True:
|
|
158
|
+
chunk = input.read(current_buf_len)
|
|
159
|
+
if first_check:
|
|
160
|
+
first_check = 0
|
|
161
|
+
if not isinstance(chunk, bytes):
|
|
162
|
+
raise TypeError(
|
|
163
|
+
f"input must be a file-like rb object, got {type(input).__name__}"
|
|
164
|
+
)
|
|
165
|
+
size = len(chunk)
|
|
166
|
+
if size < current_buf_len: # 数据不够了 要减小一次读取的量
|
|
167
|
+
if buf_rate > 1: # 重新设置一次读取的大小 重新设置流的位置 当然要是已经是一次读取7字节了 那就不能再变小了 直接encode吧
|
|
168
|
+
buf_rate = buf_rate // 2
|
|
169
|
+
current_buf_len = buf_rate * 7
|
|
170
|
+
input.seek(-size, 1)
|
|
171
|
+
continue
|
|
172
|
+
|
|
173
|
+
count = lib.base16384_encode_safe(ffi.from_buffer(chunk), size, output_buf)
|
|
98
174
|
output.write(ffi.unpack(output_buf, count))
|
|
99
175
|
if size < 7:
|
|
100
176
|
break
|
|
@@ -146,9 +222,57 @@ def decode_file(input: IO, output: IO, buf_rate: int = 10):
|
|
|
146
222
|
else:
|
|
147
223
|
input.seek(-2, 1)
|
|
148
224
|
|
|
149
|
-
count = lib.base16384_decode(
|
|
150
|
-
|
|
225
|
+
count = lib.base16384_decode(ffi.from_buffer(chunk), size, output_buf)
|
|
226
|
+
output.write(ffi.unpack(output_buf, count))
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def decode_file_safe(input: IO, output: IO, buf_rate: int = 10):
|
|
230
|
+
if not _check_file(input):
|
|
231
|
+
raise TypeError(
|
|
232
|
+
"input except a file-like object, got %s" % type(input).__name__
|
|
151
233
|
)
|
|
234
|
+
if not _check_file(output):
|
|
235
|
+
raise TypeError(
|
|
236
|
+
"output except a file-like object, got %s" % type(output).__name__
|
|
237
|
+
)
|
|
238
|
+
if buf_rate <= 0:
|
|
239
|
+
buf_rate = 1
|
|
240
|
+
|
|
241
|
+
chunk = input.read(1) # type: bytes
|
|
242
|
+
if not isinstance(chunk, bytes):
|
|
243
|
+
raise TypeError(
|
|
244
|
+
f"input must be a file-like rb object, got {type(input).__name__}"
|
|
245
|
+
)
|
|
246
|
+
if chunk == b"\xfe": # 去头
|
|
247
|
+
input.read(1)
|
|
248
|
+
else:
|
|
249
|
+
input.seek(0, 0) # 没有头 回到开头
|
|
250
|
+
|
|
251
|
+
current_buf_len: int = buf_rate * 8
|
|
252
|
+
output_size: int = decode_len(current_buf_len, 0)
|
|
253
|
+
output_buf = ffi.new(f"char[{output_size}]")
|
|
254
|
+
if output_buf == ffi.NULL:
|
|
255
|
+
raise MemoryError
|
|
256
|
+
while True:
|
|
257
|
+
chunk = input.read(current_buf_len) # 8的倍数
|
|
258
|
+
size = len(chunk)
|
|
259
|
+
if size == 0:
|
|
260
|
+
break
|
|
261
|
+
if size < current_buf_len: # 长度不够了
|
|
262
|
+
if buf_rate > 1: # 还能继续变小
|
|
263
|
+
buf_rate = buf_rate // 2 # 重新设置一次读取的大小
|
|
264
|
+
current_buf_len = buf_rate * 8
|
|
265
|
+
input.seek(-size, 1)
|
|
266
|
+
continue
|
|
267
|
+
tmp = input.read(2) # type: bytes
|
|
268
|
+
if len(tmp) == 2:
|
|
269
|
+
if tmp[0] == 61: # = stream完了 一次解码8n+2个字节
|
|
270
|
+
chunk += tmp
|
|
271
|
+
size += 2
|
|
272
|
+
else:
|
|
273
|
+
input.seek(-2, 1)
|
|
274
|
+
|
|
275
|
+
count = lib.base16384_decode_safe(ffi.from_buffer(chunk), size, output_buf)
|
|
152
276
|
output.write(ffi.unpack(output_buf, count))
|
|
153
277
|
|
|
154
278
|
|
|
@@ -176,13 +300,23 @@ def err_to_str(ret) -> str:
|
|
|
176
300
|
return "base16384_err_open_input_file"
|
|
177
301
|
elif ret == lib.base16384_err_map_input_file:
|
|
178
302
|
return "base16384_err_map_input_file"
|
|
303
|
+
elif ret == lib.base16384_err_read_file:
|
|
304
|
+
return "base16384_err_read_file"
|
|
305
|
+
elif ret == lib.base16384_err_invalid_file_name:
|
|
306
|
+
return "base16384_err_invalid_file_name"
|
|
307
|
+
elif ret == lib.base16384_err_invalid_file_name:
|
|
308
|
+
return "base16384_err_invalid_file_name"
|
|
309
|
+
elif ret == lib.base16384_err_invalid_commandline_parameter:
|
|
310
|
+
return "base16384_err_invalid_commandline_parameter"
|
|
311
|
+
elif ret == lib.base16384_err_invalid_decoding_checksum:
|
|
312
|
+
return "base16384_err_invalid_decoding_checksum"
|
|
179
313
|
|
|
180
314
|
|
|
181
315
|
def encode_local_file(inp, out) -> None:
|
|
182
316
|
inp_name: bytes = ensure_bytes(inp)
|
|
183
317
|
out_name: bytes = ensure_bytes(out)
|
|
184
|
-
encbuf = ffi.new(f"char[{
|
|
185
|
-
decbuf = ffi.new(f"char[{
|
|
318
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
319
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
186
320
|
ret = lib.base16384_encode_file(
|
|
187
321
|
ffi.from_buffer(inp_name), ffi.from_buffer(out_name), encbuf, decbuf
|
|
188
322
|
)
|
|
@@ -193,8 +327,8 @@ def encode_local_file(inp, out) -> None:
|
|
|
193
327
|
def decode_local_file(inp, out) -> None:
|
|
194
328
|
inp_name: bytes = ensure_bytes(inp)
|
|
195
329
|
out_name: bytes = ensure_bytes(out)
|
|
196
|
-
encbuf = ffi.new(f"char[{
|
|
197
|
-
decbuf = ffi.new(f"char[{
|
|
330
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
331
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
198
332
|
ret = lib.base16384_decode_file(
|
|
199
333
|
ffi.from_buffer(inp_name), ffi.from_buffer(out_name), encbuf, decbuf
|
|
200
334
|
)
|
|
@@ -203,16 +337,57 @@ def decode_local_file(inp, out) -> None:
|
|
|
203
337
|
|
|
204
338
|
|
|
205
339
|
def encode_fd(inp: int, out: int) -> None:
|
|
206
|
-
encbuf = ffi.new(f"char[{
|
|
207
|
-
decbuf = ffi.new(f"char[{
|
|
340
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
341
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
208
342
|
ret = lib.base16384_encode_fd(inp, out, encbuf, decbuf)
|
|
209
343
|
if ret != lib.base16384_err_ok:
|
|
210
344
|
raise ValueError(err_to_str(ret))
|
|
211
345
|
|
|
212
346
|
|
|
213
347
|
def decode_fd(inp: int, out: int) -> None:
|
|
214
|
-
encbuf = ffi.new(f"char[{
|
|
215
|
-
decbuf = ffi.new(f"char[{
|
|
348
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
349
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
216
350
|
ret = lib.base16384_decode_fd(inp, out, encbuf, decbuf)
|
|
217
351
|
if ret != lib.base16384_err_ok:
|
|
218
352
|
raise ValueError(err_to_str(ret))
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
# detail
|
|
356
|
+
def encode_local_file_detailed(inp, out, flag: int) -> None:
|
|
357
|
+
inp_name: bytes = ensure_bytes(inp)
|
|
358
|
+
out_name: bytes = ensure_bytes(out)
|
|
359
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
360
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
361
|
+
ret = lib.base16384_encode_file_detailed(
|
|
362
|
+
ffi.from_buffer(inp_name), ffi.from_buffer(out_name), encbuf, decbuf, flag
|
|
363
|
+
)
|
|
364
|
+
if ret != lib.base16384_err_ok:
|
|
365
|
+
raise ValueError(err_to_str(ret))
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def decode_local_file_detailed(inp, out, flag: int) -> None:
|
|
369
|
+
inp_name: bytes = ensure_bytes(inp)
|
|
370
|
+
out_name: bytes = ensure_bytes(out)
|
|
371
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
372
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
373
|
+
ret = lib.base16384_decode_file_detailed(
|
|
374
|
+
ffi.from_buffer(inp_name), ffi.from_buffer(out_name), encbuf, decbuf, flag
|
|
375
|
+
)
|
|
376
|
+
if ret != lib.base16384_err_ok:
|
|
377
|
+
raise ValueError(err_to_str(ret))
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def encode_fd_detailed(inp: int, out: int, flag: int) -> None:
|
|
381
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
382
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
383
|
+
ret = lib.base16384_encode_fd_detailed(inp, out, encbuf, decbuf, flag)
|
|
384
|
+
if ret != lib.base16384_err_ok:
|
|
385
|
+
raise ValueError(err_to_str(ret))
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
def decode_fd_detailed(inp: int, out: int, flag: int) -> None:
|
|
389
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
390
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
391
|
+
ret = lib.base16384_decode_fd_detailed(inp, out, encbuf, decbuf, flag)
|
|
392
|
+
if ret != lib.base16384_err_ok:
|
|
393
|
+
raise ValueError(err_to_str(ret))
|
|
Binary file
|
|
@@ -26,6 +26,7 @@ if sys.byteorder != "little":
|
|
|
26
26
|
|
|
27
27
|
if CPUBIT == 64:
|
|
28
28
|
macro_base.append(("CPUBIT64", None))
|
|
29
|
+
macro_base.append(("IS_64BIT_PROCESSOR", None))
|
|
29
30
|
else:
|
|
30
31
|
macro_base.append(("CPUBIT32", None))
|
|
31
32
|
|
|
@@ -41,6 +42,10 @@ enum base16384_err_t {
|
|
|
41
42
|
base16384_err_write_file,
|
|
42
43
|
base16384_err_open_input_file,
|
|
43
44
|
base16384_err_map_input_file,
|
|
45
|
+
base16384_err_read_file,
|
|
46
|
+
base16384_err_invalid_file_name,
|
|
47
|
+
base16384_err_invalid_commandline_parameter,
|
|
48
|
+
base16384_err_invalid_decoding_checksum
|
|
44
49
|
};
|
|
45
50
|
// base16384_err_t is the return value of base16384_en/decode_file
|
|
46
51
|
typedef enum base16384_err_t base16384_err_t;
|
|
@@ -67,11 +72,29 @@ base16384_err_t base16384_decode_fp(FILE* input, FILE* output, char* encbuf, cha
|
|
|
67
72
|
// encbuf & decbuf must be no less than BASE16384_ENCBUFSZ & BASE16384_DECBUFSZ
|
|
68
73
|
base16384_err_t base16384_decode_fd(int input, int output, char* encbuf, char* decbuf);
|
|
69
74
|
|
|
75
|
+
int base16384_encode_unsafe(const char * data, int dlen, char * buf);
|
|
76
|
+
int base16384_decode_unsafe(const char * data, int dlen, char * buf);
|
|
77
|
+
int base16384_encode_safe(const char * data, int dlen, char * buf);
|
|
78
|
+
int base16384_decode_safe(const char * data, int dlen, char * buf);
|
|
79
|
+
|
|
80
|
+
base16384_err_t base16384_encode_file_detailed(const char* input, const char* output, char* encbuf, char* decbuf, int flag);
|
|
81
|
+
base16384_err_t base16384_decode_file_detailed(const char* input, const char* output, char* encbuf, char* decbuf, int flag);
|
|
82
|
+
base16384_err_t base16384_encode_fd_detailed(int input, int output, char* encbuf, char* decbuf, int flag);
|
|
83
|
+
base16384_err_t base16384_decode_fd_detailed(int input, int output, char* encbuf, char* decbuf, int flag);
|
|
84
|
+
base16384_err_t base16384_encode_fp_detailed(FILE* input, FILE* output, char* encbuf, char* decbuf, int flag);
|
|
85
|
+
base16384_err_t base16384_decode_fp_detailed(FILE* input, FILE* output, char* encbuf, char* decbuf, int flag);
|
|
86
|
+
|
|
70
87
|
int32_t pybase16384_64bits();
|
|
71
88
|
|
|
72
89
|
int get_encsize();
|
|
73
90
|
|
|
74
91
|
int get_decsize();
|
|
92
|
+
|
|
93
|
+
int BASE16384_FLAG_NOHEADER_();
|
|
94
|
+
|
|
95
|
+
int BASE16384_FLAG_SUM_CHECK_ON_REMAIN_();
|
|
96
|
+
|
|
97
|
+
int BASE16384_FLAG_DO_SUM_CHECK_FORCELY_();
|
|
75
98
|
"""
|
|
76
99
|
)
|
|
77
100
|
|
|
@@ -79,9 +102,9 @@ source = """
|
|
|
79
102
|
#include "base16384.h"
|
|
80
103
|
|
|
81
104
|
#ifdef CPUBIT32
|
|
82
|
-
#define pybase16384_64bits() 0
|
|
105
|
+
#define pybase16384_64bits() (0)
|
|
83
106
|
#else
|
|
84
|
-
#define pybase16384_64bits() 1
|
|
107
|
+
#define pybase16384_64bits() (1)
|
|
85
108
|
#endif
|
|
86
109
|
|
|
87
110
|
int get_encsize()
|
|
@@ -93,6 +116,21 @@ int get_decsize()
|
|
|
93
116
|
{
|
|
94
117
|
return BASE16384_DECBUFSZ;
|
|
95
118
|
}
|
|
119
|
+
|
|
120
|
+
int BASE16384_FLAG_NOHEADER_()
|
|
121
|
+
{
|
|
122
|
+
return BASE16384_FLAG_NOHEADER;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
int BASE16384_FLAG_SUM_CHECK_ON_REMAIN_()
|
|
126
|
+
{
|
|
127
|
+
return BASE16384_FLAG_SUM_CHECK_ON_REMAIN;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
int BASE16384_FLAG_DO_SUM_CHECK_FORCELY_()
|
|
131
|
+
{
|
|
132
|
+
return BASE16384_FLAG_DO_SUM_CHECK_FORCELY;
|
|
133
|
+
}
|
|
96
134
|
"""
|
|
97
135
|
|
|
98
136
|
ffibuilder.set_source(
|
|
@@ -2,17 +2,32 @@
|
|
|
2
2
|
Copyright (c) 2008-2021 synodriver <synodriver@gmail.com>
|
|
3
3
|
"""
|
|
4
4
|
from pybase16384.backends.cython._core import (
|
|
5
|
+
DECBUFSZ,
|
|
6
|
+
ENCBUFSZ,
|
|
7
|
+
FLAG_DO_SUM_CHECK_FORCELY,
|
|
8
|
+
FLAG_NOHEADER,
|
|
9
|
+
FLAG_SUM_CHECK_ON_REMAIN,
|
|
5
10
|
_decode,
|
|
6
11
|
_decode_into,
|
|
12
|
+
_decode_into_safe,
|
|
13
|
+
_decode_safe,
|
|
7
14
|
_encode,
|
|
8
15
|
_encode_into,
|
|
16
|
+
_encode_into_safe,
|
|
17
|
+
_encode_safe,
|
|
9
18
|
decode_fd,
|
|
19
|
+
decode_fd_detailed,
|
|
10
20
|
decode_file,
|
|
21
|
+
decode_file_safe,
|
|
11
22
|
decode_len,
|
|
12
23
|
decode_local_file,
|
|
24
|
+
decode_local_file_detailed,
|
|
13
25
|
encode_fd,
|
|
26
|
+
encode_fd_detailed,
|
|
14
27
|
encode_file,
|
|
28
|
+
encode_file_safe,
|
|
15
29
|
encode_len,
|
|
16
30
|
encode_local_file,
|
|
31
|
+
encode_local_file_detailed,
|
|
17
32
|
is_64bits,
|
|
18
33
|
)
|
|
Binary file
|