按规范「注释只讲解作用,不掺杂历史原因,尽量英文」:把 includes 下 75 个 .vp 的中文 # 注释与三引号 docstring 改写为英文,每个注释块压到 2 行以内。 保留要点:作用、约束、危险警告(不得/必须/注意)、ABI 与类型约定(如 BYTEPTR | t.CPtr = i8** 的跨模块坍缩坑)、位宽/长度约定、fail-fast 要求、内存与句柄所有权。 未动:文件头注释(规范豁免,仍是中文)、运行时中文字符串常量(printf / fatal_error / MlirFail 等用户可见消息,属代码字面量)。 验证:独立脚本比对 HEAD 与工作区的代码骨架(剥离 # 注释与三引号 docstring 后的非空行)——75 个文件逐字节一致;行尾 CRLF/LF 未被改动;全文剩余中文仅 547 行头注释、0 条行尾注释。bootstrap 三重重编 SUCCESS;全量 77/77 顺序回归通过。
76 lines
3.2 KiB
Plaintext
76 lines
3.2 KiB
Plaintext
import t, c
|
|
from openssl.types import *
|
|
|
|
# ============================================================
|
|
# openssl/crypto.vp — OpenSSL 全局初始化 / 版本 / 内存工具
|
|
# 对应头文件: crypto.h / opensslv.h
|
|
# ============================================================
|
|
|
|
# ---- Version query types (type arg of OpenSSL_version(type)) ----
|
|
define OpenSslVersion = 0# OPENSSL_VERSION full version text
|
|
define OpenSslBuiltOn = 2# OPENSSL_BUILT_ON build time
|
|
define OpenSslPlatform = 3# OPENSSL_PLATFORM platform
|
|
define OpenSslDir = 4# OPENSSL_DIR
|
|
define OpenSslEnginesDir = 5# OPENSSL_ENGINES_DIR
|
|
define OpenSslVersionString = 6# OPENSSL_VERSION_STRING "3.x.y"
|
|
define OpenSslModulesDir = 8# OPENSSL_MODULES_DIR
|
|
define OpenSslCpuInfo = 9# OPENSSL_CPU_INFO
|
|
|
|
# ---- OPENSSL_init_crypto / OPENSSL_init_ssl option bits ----
|
|
define OpenSslInitNoLoadCryptoStrings = 0x00000001
|
|
define OpenSslInitNoLoadConfig = 0x00000004
|
|
define OpenSslInitNoAddAllCiphers = 0x00000008
|
|
define OpenSslInitNoAddAllDigests = 0x00000010
|
|
define OpenSslInitLoadConfig = 0x00000040
|
|
define OpenSslInitAsync = 0x00000080
|
|
define OpenSslInitDebugFile = 0x00010000
|
|
define OpenSslInitAtFork = 0x00020000
|
|
define OpenSslInitNoLoadSslStrings = 0x00100000
|
|
define OpenSslInitNoAtomics = 0x00200000
|
|
|
|
# ---- Version numbers (3.6.2, depends on the linked library) ----
|
|
define OpenSslVersionMajor = 3
|
|
define OpenSslVersionMinor = 6
|
|
define OpenSslVersionPatch = 2
|
|
|
|
# ---- Global init / cleanup ----
|
|
# int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
|
|
extern def OPENSSL_init_crypto(opts: uint64, settings: bytes) -> int
|
|
# int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
|
|
extern def OPENSSL_init_ssl(opts: uint64, settings: bytes) -> int
|
|
extern def OPENSSL_cleanup()
|
|
|
|
# ---- Version query ----
|
|
# const char *OpenSSL_version(int type)
|
|
extern def OpenSSL_version(type: int) -> str
|
|
# unsigned long OpenSSL_version_num(void)
|
|
extern def OpenSSL_version_num() -> uint32
|
|
extern def OPENSSL_version_pre_release() -> str
|
|
extern def OPENSSL_version_build_metadata() -> str
|
|
|
|
# ---- Memory / secure erase ----
|
|
# void OPENSSL_cleanse(void *ptr, size_t len)
|
|
extern def OPENSSL_cleanse(ptr: bytes, len: sizet)
|
|
# void CRYPTO_free(void *ptr, const char *file, int line)
|
|
extern def CRYPTO_free(ptr: bytes, file: str, line: int)
|
|
# void *CRYPTO_malloc(size_t num, const char *file, int line)
|
|
extern def CRYPTO_malloc(num: sizet, file: str, line: int) -> bytes
|
|
# int CRYPTO_memcmp(const void *in_a, const void *in_b, size_t len)
|
|
extern def CRYPTO_memcmp(in_a: bytes, in_b: bytes, len: sizet) -> int
|
|
# char *OPENSSL_buf2hexstr(const unsigned char *buf, long buflen) -> free with ossl_free
|
|
extern def OPENSSL_buf2hexstr(buf: bytes, buflen: int32) -> str
|
|
# int OPENSSL_hexchar2int(unsigned char c)
|
|
extern def OPENSSL_hexchar2int(c: uint8) -> int
|
|
# int OPENSSL_strcasecmp(const char *s1, const char *s2)
|
|
extern def OPENSSL_strcasecmp(s1: str, s2: str) -> int
|
|
# int OPENSSL_strncasecmp(const char *s1, const char *s2, size_t n)
|
|
extern def OPENSSL_strncasecmp(s1: str, s2: str, n: sizet) -> int
|
|
|
|
# ---- Convenience wrappers (CRYPTO_free/CRYPTO_malloc macros take file/line; wrapped as single-arg) ----
|
|
def ossl_free(ptr: bytes):
|
|
CRYPTO_free(ptr, "", 0)
|
|
|
|
|
|
def ossl_malloc(num: sizet) -> bytes:
|
|
return CRYPTO_malloc(num, "", 0)
|