按规范「注释只讲解作用,不掺杂历史原因,尽量英文」:把 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 顺序回归通过。
178 lines
9.5 KiB
Plaintext
178 lines
9.5 KiB
Plaintext
import t, c
|
|
from openssl.types import *
|
|
|
|
# ============================================================
|
|
# openssl/x509.vp — X509 证书解析 / 校验 + 必要 ASN.1 助手
|
|
# 对应头文件: x509.h / x509_vfy.h / asn1.h
|
|
#
|
|
# 证书网络解析场景:读取 subject/issuer/SAN/有效期/公钥、链式校验。
|
|
# ============================================================
|
|
|
|
define X509VOk = 0
|
|
define X509Version1 = 0
|
|
define X509Version2 = 1
|
|
define X509Version3 = 2
|
|
|
|
# ============================================================
|
|
# 1) Certificate object lifecycle
|
|
# ============================================================
|
|
# X509 *X509_new(void) / void X509_free(X509 *a)
|
|
extern def X509_new() -> X509Ptr
|
|
extern def X509_free(a: X509Ptr)
|
|
# int i2d_X509(X509 *a, unsigned char **pp) / X509 *d2i_X509(X509 **a, const unsigned char **pp, long length)
|
|
# (pp semantics are complex; use d2i_X509_bio/i2d_X509_bio, so raw d2i/i2d are not exposed)
|
|
extern def d2i_X509_bio(bp: BioPtr, x509: bytes) -> X509Ptr
|
|
extern def i2d_X509_bio(bp: BioPtr, x509: X509Ptr) -> int
|
|
|
|
# ============================================================
|
|
# 2) Certificate field access
|
|
# ============================================================
|
|
# long X509_get_version(const X509 *x)
|
|
extern def X509_get_version(x: X509Ptr) -> int32
|
|
# ASN1_INTEGER *X509_get_serialNumber(X509 *x)
|
|
extern def X509_get_serialNumber(x: X509Ptr) -> Asn1IntegerPtr
|
|
# X509_NAME *X509_get_subject_name(const X509 *a)
|
|
extern def X509_get_subject_name(a: X509Ptr) -> X509NamePtr
|
|
# X509_NAME *X509_get_issuer_name(const X509 *a)
|
|
extern def X509_get_issuer_name(a: X509Ptr) -> X509NamePtr
|
|
# const ASN1_TIME *X509_get0_notBefore(const X509 *x)
|
|
extern def X509_get0_notBefore(x: X509Ptr) -> Asn1TimePtr
|
|
# const ASN1_TIME *X509_get0_notAfter(const X509 *x)
|
|
extern def X509_get0_notAfter(x: X509Ptr) -> Asn1TimePtr
|
|
# EVP_PKEY *X509_get_pubkey(X509 *x)
|
|
extern def X509_get_pubkey(x: X509Ptr) -> EvpPkeyPtr
|
|
# ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x)
|
|
extern def X509_get0_pubkey_bitstr(x: X509Ptr) -> Asn1BitStringPtr
|
|
# int X509_get_signature_nid(const X509 *x)
|
|
extern def X509_get_signature_nid(x: X509Ptr) -> int
|
|
# int X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md, unsigned int *len)
|
|
extern def X509_digest(data: X509Ptr, type: EvpMdPtr, md: bytes, len: bytes) -> int
|
|
# int X509_verify(X509 *a, EVP_PKEY *r)
|
|
extern def X509_verify(a: X509Ptr, r: EvpPkeyPtr) -> int
|
|
|
|
# ============================================================
|
|
# 3) X509_NAME access (subject/issuer RDN entries)
|
|
# ============================================================
|
|
# int X509_NAME_entry_count(const X509_NAME *name)
|
|
extern def X509_NAME_entry_count(name: X509NamePtr) -> int
|
|
# int X509_NAME_get_index_by_NID(const X509_NAME *name, int nid, int lastpos)
|
|
extern def X509_NAME_get_index_by_NID(name: X509NamePtr, nid: int, lastpos: int) -> int
|
|
# X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, int loc)
|
|
extern def X509_NAME_get_entry(name: X509NamePtr, loc: int) -> X509NameEntryPtr
|
|
# ASN1_OBJECT *X509_NAME_ENTRY_get_object(const X509_NAME_ENTRY *ne)
|
|
extern def X509_NAME_ENTRY_get_object(ne: X509NameEntryPtr) -> Asn1ObjectPtr
|
|
# ASN1_STRING *X509_NAME_ENTRY_get_data(const X509_NAME_ENTRY *ne)
|
|
extern def X509_NAME_ENTRY_get_data(ne: X509NameEntryPtr) -> Asn1StringPtr
|
|
# int X509_NAME_get_text_by_NID(const X509_NAME *name, int nid, char *buf, int len)
|
|
extern def X509_NAME_get_text_by_NID(name: X509NamePtr, nid: int, buf: bytes, len: int) -> int
|
|
# char *X509_NAME_oneline(const X509_NAME *a, char *buf, int size) -> returns pointer to buf
|
|
extern def X509_NAME_oneline(a: X509NamePtr, buf: bytes, size: int) -> str
|
|
|
|
# ============================================================
|
|
# 4) Extensions (SAN, ...)
|
|
# ============================================================
|
|
# int X509_get_ext_count(const X509 *x)
|
|
extern def X509_get_ext_count(x: X509Ptr) -> int
|
|
# X509_EXTENSION *X509_get_ext(const X509 *x, int loc)
|
|
extern def X509_get_ext(x: X509Ptr, loc: int) -> X509ExtensionPtr
|
|
# int X509_get_ext_by_NID(const X509 *x, int nid, int lastpos)
|
|
extern def X509_get_ext_by_NID(x: X509Ptr, nid: int, lastpos: int) -> int
|
|
# void *X509_get_ext_d2i(const X509 *x, int nid, int *crit, int *idx)
|
|
extern def X509_get_ext_d2i(x: X509Ptr, nid: int, crit: bytes, idx: bytes) -> GeneralNamesPtr
|
|
# ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex)
|
|
extern def X509_EXTENSION_get_object(ex: X509ExtensionPtr) -> Asn1ObjectPtr
|
|
# ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne)
|
|
extern def X509_EXTENSION_get_data(ne: X509ExtensionPtr) -> Asn1OctetStringPtr
|
|
# int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent)
|
|
extern def X509V3_EXT_print(out: BioPtr, ext: X509ExtensionPtr,
|
|
flag: uint32, indent: int) -> int
|
|
|
|
# GENERAL_NAME iteration (SAN: DNS/URI/IP/email)
|
|
extern def GENERAL_NAME_free(a: GeneralNamePtr)
|
|
extern def GENERAL_NAMES_free(a: GeneralNamesPtr)
|
|
# int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen)
|
|
extern def GENERAL_NAME_print(out: BioPtr, gen: GeneralNamePtr) -> int
|
|
# Generic OPENSSL stack access (backing STACK_OF; sk_xxx_num/value macros land here)
|
|
# int OPENSSL_sk_num(const OPENSSL_STACK *st)
|
|
extern def OPENSSL_sk_num(st: bytes) -> int
|
|
# void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)
|
|
extern def OPENSSL_sk_value(st: bytes, i: int) -> GeneralNamePtr
|
|
# void OPENSSL_sk_free(OPENSSL_STACK *st)
|
|
extern def OPENSSL_sk_free(st: bytes)
|
|
# const char *OBJ_nid2sn ... lives in objects.vp; GNR constants go here
|
|
define GenEmail = 1
|
|
define GenDns = 2
|
|
define GenUri = 6
|
|
define GenIpadd = 7
|
|
|
|
# ---- SAN convenience access (count GENERAL_NAME entries) ----
|
|
def x509_san_count(gns: GeneralNamesPtr) -> int:
|
|
return OPENSSL_sk_num(gns)
|
|
|
|
# ============================================================
|
|
# 5) Certificate chain verification (X509_STORE_CTX)
|
|
# ============================================================
|
|
# X509_STORE *X509_STORE_new(void) / void X509_STORE_free(X509_STORE *v)
|
|
extern def X509_STORE_new() -> X509StorePtr
|
|
extern def X509_STORE_free(v: X509StorePtr)
|
|
# int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
|
|
extern def X509_STORE_add_cert(ctx: X509StorePtr, x: X509Ptr) -> int
|
|
# int X509_STORE_load_file(X509_STORE *xs, const char *file)
|
|
extern def X509_STORE_load_file(xs: X509StorePtr, file: str) -> int
|
|
# int X509_STORE_load_path(X509_STORE *xs, const char *path)
|
|
extern def X509_STORE_load_path(xs: X509StorePtr, path: str) -> int
|
|
# int X509_STORE_load_locations(X509_STORE *s, const char *file, const char *dir)
|
|
extern def X509_STORE_load_locations(s: X509StorePtr, file: str, dir: str) -> int
|
|
# int X509_STORE_set_default_paths(X509_STORE *xs)
|
|
extern def X509_STORE_set_default_paths(xs: X509StorePtr) -> int
|
|
|
|
# X509_STORE_CTX
|
|
extern def X509_STORE_CTX_new() -> X509StoreCtxPtr
|
|
extern def X509_STORE_CTX_free(ctx: X509StoreCtxPtr)
|
|
# int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *trust_store,
|
|
# X509 *target, STACK_OF(X509) *untrusted)
|
|
extern def X509_STORE_CTX_init(ctx: X509StoreCtxPtr, trust_store: X509StorePtr,
|
|
target: X509Ptr, untrusted: bytes) -> int
|
|
# void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *target)
|
|
extern def X509_STORE_CTX_set_cert(ctx: X509StoreCtxPtr, target: X509Ptr)
|
|
# void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *sk)
|
|
extern def X509_STORE_CTX_set_chain(ctx: X509StoreCtxPtr, sk: bytes)
|
|
# int X509_verify_cert(X509_STORE_CTX *ctx)
|
|
extern def X509_verify_cert(ctx: X509StoreCtxPtr) -> int
|
|
# int X509_STORE_CTX_get_error(const X509_STORE_CTX *ctx)
|
|
extern def X509_STORE_CTX_get_error(ctx: X509StoreCtxPtr) -> int
|
|
# int X509_STORE_CTX_get_error_depth(const X509_STORE_CTX *ctx)
|
|
extern def X509_STORE_CTX_get_error_depth(ctx: X509StoreCtxPtr) -> int
|
|
# X509 *X509_STORE_CTX_get_current_cert(const X509_STORE_CTX *ctx)
|
|
extern def X509_STORE_CTX_get_current_cert(ctx: X509StoreCtxPtr) -> X509Ptr
|
|
# const char *X509_verify_cert_error_string(long n)
|
|
extern def X509_verify_cert_error_string(n: int32) -> str
|
|
|
|
# ============================================================
|
|
# 6) ASN.1 string / time helpers (asn1.h)
|
|
# ============================================================
|
|
# int ASN1_STRING_length(const ASN1_STRING *x)
|
|
extern def ASN1_STRING_length(x: Asn1StringPtr) -> int
|
|
# const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x)
|
|
extern def ASN1_STRING_get0_data(x: Asn1StringPtr) -> bytes
|
|
# int ASN1_STRING_type(const ASN1_STRING *x)
|
|
extern def ASN1_STRING_type(x: Asn1StringPtr) -> int
|
|
# int ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in) -> returns length; caller must CRYPTO_free(*out)
|
|
extern def ASN1_STRING_to_UTF8(out: bytes, inn: Asn1StringPtr) -> int
|
|
# int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v)
|
|
extern def ASN1_STRING_print(bp: BioPtr, v: Asn1StringPtr) -> int
|
|
# int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags)
|
|
extern def ASN1_STRING_print_ex(out: BioPtr, str: Asn1StringPtr, flags: uint32) -> int
|
|
# int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm)
|
|
extern def ASN1_TIME_print(bp: BioPtr, tm: Asn1TimePtr) -> int
|
|
# int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b)
|
|
extern def ASN1_TIME_compare(a: Asn1TimePtr, b: Asn1TimePtr) -> int
|
|
# int ASN1_INTEGER_get(const ASN1_INTEGER *a)
|
|
extern def ASN1_INTEGER_get(a: Asn1IntegerPtr) -> int32
|
|
# int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
|
|
extern def ASN1_INTEGER_set(a: Asn1IntegerPtr, v: int32) -> int
|
|
# int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a) -> prints decimal to BIO
|
|
extern def i2a_ASN1_INTEGER(bp: BioPtr, a: Asn1IntegerPtr) -> int
|
|
# const char *ASN1_tag2str(int tag)
|
|
extern def ASN1_tag2str(tag: int) -> str
|