pybase16384 0.3.9__cp312-cp312-musllinux_1_2_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.
- pybase16384/__init__.py +205 -0
- pybase16384/backends/__init__.py +1 -0
- pybase16384/backends/cffi/__init__.py +463 -0
- pybase16384/backends/cffi/_core.abi3.so +0 -0
- pybase16384/backends/cffi/build.py +183 -0
- pybase16384/backends/cython/__init__.py +36 -0
- pybase16384/backends/cython/_core.abi3.so +0 -0
- pybase16384/backends/cython/_core.c +39928 -0
- pybase16384/backends/cython/_core.pxi +12 -0
- pybase16384/backends/cython/_core.pyx +619 -0
- pybase16384/backends/cython/base16384.pxd +113 -0
- pybase16384-0.3.9.dist-info/METADATA +216 -0
- pybase16384-0.3.9.dist-info/RECORD +16 -0
- pybase16384-0.3.9.dist-info/WHEEL +5 -0
- pybase16384-0.3.9.dist-info/licenses/LICENSE +674 -0
- pybase16384-0.3.9.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) 2008-2021 synodriver <synodriver@gmail.com>
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import platform
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from cffi import FFI
|
|
9
|
+
|
|
10
|
+
if sys.maxsize > 2**32:
|
|
11
|
+
CPUBIT = 64
|
|
12
|
+
else:
|
|
13
|
+
CPUBIT = 32
|
|
14
|
+
|
|
15
|
+
system = platform.system()
|
|
16
|
+
if system == "Windows":
|
|
17
|
+
macro_base = [("_WIN64", None)]
|
|
18
|
+
elif system == "Linux":
|
|
19
|
+
macro_base = [("__linux__", None)]
|
|
20
|
+
elif system == "Darwin":
|
|
21
|
+
macro_base = [("__MAC_10_0", None)]
|
|
22
|
+
else:
|
|
23
|
+
macro_base = []
|
|
24
|
+
|
|
25
|
+
if sys.byteorder != "little":
|
|
26
|
+
macro_base.append(("WORDS_BIGENDIAN", None))
|
|
27
|
+
|
|
28
|
+
if CPUBIT == 64:
|
|
29
|
+
macro_base.append(("CPUBIT64", None))
|
|
30
|
+
macro_base.append(("IS_64BIT_PROCESSOR", None))
|
|
31
|
+
else:
|
|
32
|
+
macro_base.append(("CPUBIT32", None))
|
|
33
|
+
|
|
34
|
+
ffibuilder = FFI()
|
|
35
|
+
ffibuilder.cdef(
|
|
36
|
+
"""
|
|
37
|
+
// base16384_err_t is the return value of base16384_en/decode_file
|
|
38
|
+
enum base16384_err_t {
|
|
39
|
+
base16384_err_ok,
|
|
40
|
+
base16384_err_get_file_size,
|
|
41
|
+
base16384_err_fopen_output_file,
|
|
42
|
+
base16384_err_fopen_input_file,
|
|
43
|
+
base16384_err_write_file,
|
|
44
|
+
base16384_err_open_input_file,
|
|
45
|
+
base16384_err_map_input_file,
|
|
46
|
+
base16384_err_read_file,
|
|
47
|
+
base16384_err_invalid_file_name,
|
|
48
|
+
base16384_err_invalid_commandline_parameter,
|
|
49
|
+
base16384_err_invalid_decoding_checksum
|
|
50
|
+
};
|
|
51
|
+
// base16384_err_t is the return value of base16384_en/decode_file
|
|
52
|
+
typedef enum base16384_err_t base16384_err_t;
|
|
53
|
+
int base16384_encode_len(int dlen);
|
|
54
|
+
int base16384_decode_len(int dlen, int offset);
|
|
55
|
+
int base16384_encode(const char* data, int dlen, char* buf);
|
|
56
|
+
int base16384_decode(const char* data, int dlen, char* buf);
|
|
57
|
+
base16384_err_t base16384_encode_file(const char* input, const char* output, char* encbuf, char* decbuf);
|
|
58
|
+
base16384_err_t base16384_decode_file(const char* input, const char* output, char* encbuf, char* decbuf);
|
|
59
|
+
|
|
60
|
+
// base16384_encode_fp encodes input file to output file.
|
|
61
|
+
// encbuf & decbuf must be no less than BASE16384_ENCBUFSZ & BASE16384_DECBUFSZ
|
|
62
|
+
base16384_err_t base16384_encode_fp(FILE* input, FILE* output, char* encbuf, char* decbuf);
|
|
63
|
+
|
|
64
|
+
// base16384_encode_fd encodes input fd to output fd.
|
|
65
|
+
// encbuf & decbuf must be no less than BASE16384_ENCBUFSZ & BASE16384_DECBUFSZ
|
|
66
|
+
base16384_err_t base16384_encode_fd(int input, int output, char* encbuf, char* decbuf);
|
|
67
|
+
|
|
68
|
+
// base16384_decode_fp decodes input file to output file.
|
|
69
|
+
// encbuf & decbuf must be no less than BASE16384_ENCBUFSZ & BASE16384_DECBUFSZ
|
|
70
|
+
base16384_err_t base16384_decode_fp(FILE* input, FILE* output, char* encbuf, char* decbuf);
|
|
71
|
+
|
|
72
|
+
// base16384_decode_fd decodes input fd to output fd.
|
|
73
|
+
// encbuf & decbuf must be no less than BASE16384_ENCBUFSZ & BASE16384_DECBUFSZ
|
|
74
|
+
base16384_err_t base16384_decode_fd(int input, int output, char* encbuf, char* decbuf);
|
|
75
|
+
|
|
76
|
+
int base16384_encode_unsafe(const char * data, int dlen, char * buf);
|
|
77
|
+
int base16384_decode_unsafe(const char * data, int dlen, char * buf);
|
|
78
|
+
int base16384_encode_safe(const char * data, int dlen, char * buf);
|
|
79
|
+
int base16384_decode_safe(const char * data, int dlen, char * buf);
|
|
80
|
+
|
|
81
|
+
base16384_err_t base16384_encode_file_detailed(const char* input, const char* output, char* encbuf, char* decbuf, int flag);
|
|
82
|
+
base16384_err_t base16384_decode_file_detailed(const char* input, const char* output, char* encbuf, char* decbuf, int flag);
|
|
83
|
+
base16384_err_t base16384_encode_fd_detailed(int input, int output, char* encbuf, char* decbuf, int flag);
|
|
84
|
+
base16384_err_t base16384_decode_fd_detailed(int input, int output, char* encbuf, char* decbuf, int flag);
|
|
85
|
+
base16384_err_t base16384_encode_fp_detailed(FILE* input, FILE* output, char* encbuf, char* decbuf, int flag);
|
|
86
|
+
base16384_err_t base16384_decode_fp_detailed(FILE* input, FILE* output, char* encbuf, char* decbuf, int flag);
|
|
87
|
+
|
|
88
|
+
int32_t pybase16384_64bits();
|
|
89
|
+
|
|
90
|
+
int get_encsize();
|
|
91
|
+
|
|
92
|
+
int get_decsize();
|
|
93
|
+
|
|
94
|
+
int BASE16384_FLAG_NOHEADER_();
|
|
95
|
+
|
|
96
|
+
int BASE16384_FLAG_SUM_CHECK_ON_REMAIN_();
|
|
97
|
+
|
|
98
|
+
int BASE16384_FLAG_DO_SUM_CHECK_FORCELY_();
|
|
99
|
+
|
|
100
|
+
typedef ssize_t (*base16384_reader_t)(const void *client_data, void *buffer, size_t count);
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @brief custom writer function interface
|
|
104
|
+
* @param client_data the data pointer defined by the client
|
|
105
|
+
* @param buffer from where read data
|
|
106
|
+
* @param count write bytes count
|
|
107
|
+
* @return the size written
|
|
108
|
+
*/
|
|
109
|
+
typedef ssize_t (*base16384_writer_t)(const void *client_data, const void *buffer, size_t count);
|
|
110
|
+
|
|
111
|
+
union base16384_io_function_t {
|
|
112
|
+
base16384_reader_t reader;
|
|
113
|
+
base16384_writer_t writer;
|
|
114
|
+
};
|
|
115
|
+
typedef union base16384_io_function_t base16384_io_function_t;
|
|
116
|
+
|
|
117
|
+
struct base16384_stream_t {
|
|
118
|
+
base16384_io_function_t f;
|
|
119
|
+
void *client_data;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* @brief for stream encode/decode
|
|
123
|
+
*/
|
|
124
|
+
typedef struct base16384_stream_t base16384_stream_t;
|
|
125
|
+
|
|
126
|
+
base16384_err_t base16384_encode_stream_detailed(base16384_stream_t* input, base16384_stream_t* output, char* encbuf, char* decbuf, int flag);
|
|
127
|
+
base16384_err_t base16384_decode_stream_detailed(base16384_stream_t* input, base16384_stream_t* output, char* encbuf, char* decbuf, int flag);
|
|
128
|
+
|
|
129
|
+
extern "Python" ssize_t b14_readcallback(const void *client_data, void *buffer, size_t count);
|
|
130
|
+
|
|
131
|
+
extern "Python" ssize_t b14_writecallback(const void *client_data, const void *buffer, size_t count);
|
|
132
|
+
"""
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
source = """
|
|
136
|
+
#include "base16384.h"
|
|
137
|
+
|
|
138
|
+
#ifdef CPUBIT32
|
|
139
|
+
#define pybase16384_64bits() (0)
|
|
140
|
+
#else
|
|
141
|
+
#define pybase16384_64bits() (1)
|
|
142
|
+
#endif
|
|
143
|
+
|
|
144
|
+
int get_encsize()
|
|
145
|
+
{
|
|
146
|
+
return BASE16384_ENCBUFSZ;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
int get_decsize()
|
|
150
|
+
{
|
|
151
|
+
return BASE16384_DECBUFSZ;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
int BASE16384_FLAG_NOHEADER_()
|
|
155
|
+
{
|
|
156
|
+
return BASE16384_FLAG_NOHEADER;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
int BASE16384_FLAG_SUM_CHECK_ON_REMAIN_()
|
|
160
|
+
{
|
|
161
|
+
return BASE16384_FLAG_SUM_CHECK_ON_REMAIN;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
int BASE16384_FLAG_DO_SUM_CHECK_FORCELY_()
|
|
165
|
+
{
|
|
166
|
+
return BASE16384_FLAG_DO_SUM_CHECK_FORCELY;
|
|
167
|
+
}
|
|
168
|
+
"""
|
|
169
|
+
|
|
170
|
+
ffibuilder.set_source(
|
|
171
|
+
"pybase16384.backends.cffi._core",
|
|
172
|
+
source,
|
|
173
|
+
sources=[
|
|
174
|
+
f"./base16384/base14{CPUBIT}.c",
|
|
175
|
+
"./base16384/file.c",
|
|
176
|
+
"./base16384/wrap.c",
|
|
177
|
+
],
|
|
178
|
+
include_dirs=["./base16384"],
|
|
179
|
+
define_macros=macro_base,
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
if __name__ == "__main__":
|
|
183
|
+
ffibuilder.compile()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) 2008-2021 synodriver <synodriver@gmail.com>
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from pybase16384.backends.cython._core import (
|
|
6
|
+
DECBUFSZ,
|
|
7
|
+
ENCBUFSZ,
|
|
8
|
+
FLAG_DO_SUM_CHECK_FORCELY,
|
|
9
|
+
FLAG_NOHEADER,
|
|
10
|
+
FLAG_SUM_CHECK_ON_REMAIN,
|
|
11
|
+
_decode,
|
|
12
|
+
_decode_into,
|
|
13
|
+
_decode_into_safe,
|
|
14
|
+
_decode_safe,
|
|
15
|
+
_encode,
|
|
16
|
+
_encode_into,
|
|
17
|
+
_encode_into_safe,
|
|
18
|
+
_encode_safe,
|
|
19
|
+
decode_fd,
|
|
20
|
+
decode_fd_detailed,
|
|
21
|
+
decode_file,
|
|
22
|
+
decode_file_safe,
|
|
23
|
+
decode_len,
|
|
24
|
+
decode_local_file,
|
|
25
|
+
decode_local_file_detailed,
|
|
26
|
+
decode_stream_detailed,
|
|
27
|
+
encode_fd,
|
|
28
|
+
encode_fd_detailed,
|
|
29
|
+
encode_file,
|
|
30
|
+
encode_file_safe,
|
|
31
|
+
encode_len,
|
|
32
|
+
encode_local_file,
|
|
33
|
+
encode_local_file_detailed,
|
|
34
|
+
encode_stream_detailed,
|
|
35
|
+
is_64bits,
|
|
36
|
+
)
|
|
Binary file
|