# cbindgen configuration for gmcrypto-c.
# Regen via: cargo build -p gmcrypto-c --features regen-header
# (or set GMCRYPTO_C_REGEN_HEADER=1 in the environment).

language = "C"
header = "/*\n * gmcrypto-c — C ABI for gmcrypto-core (pure-Rust SM2/SM3/SM4 SDK).\n *\n * AUTO-GENERATED by cbindgen. DO NOT EDIT BY HAND.\n * Regenerate via: cargo build -p gmcrypto-c --features regen-header\n *\n * Failure-mode invariant (v0.4 W4 / Q4.8 of docs/v0.4-scope.md):\n * every int return is 0 on success, non-zero on failure. Non-zero\n * codes are NOT enumerated — they are equivalent `Failed` per the\n * crate's failure-mode discipline.\n *\n * Pointer / length preconditions (caller-upheld — violating them is\n * undefined behavior, NOT a GMCRYPTO_ERR): every non-null pointer argument\n * must point to at least the stated number of bytes (e.g. a key pointer to\n * its KEY_SIZE, an iv to 16 bytes), each *_len must not exceed the real\n * allocation, and out/out_capacity pairs must describe a writable buffer of\n * at least out_capacity bytes. A null pointer is reported as GMCRYPTO_ERR;\n * an out-of-bounds or mis-sized non-null pointer is undefined behavior.\n */"
include_guard = "GMCRYPTO_H_"
autogen_warning = "/* Warning: this file is auto-generated by cbindgen; do not edit. */"
no_includes = false
sys_includes = ["stddef.h", "stdint.h"]
style = "type"
documentation = true
documentation_style = "c"
# Hand-maintained C caller-convenience macros, emitted right after the include
# block. Kept here (not edited into the generated header) so they survive
# `--features regen-header`. Literal TOML string: backslash line-continuations
# are preserved verbatim for the C preprocessor.
after_includes = '''

/*
 * Output-buffer size required by gmcrypto_sm4_cbc_encrypt() for a plaintext of
 * `pt_len` bytes: PKCS#7 always appends a full padding block, so the size is
 * ((pt_len / 16) + 1) * 16. The caller must ensure this does not overflow
 * size_t.
 */
#define GMCRYPTO_SM4_CBC_OUTPUT_SIZE(pt_len) ((((size_t)(pt_len) / 16u) + 1u) * 16u)

/*
 * Best-effort secret scrub: overwrite `len` bytes at `ptr` with zeros through a
 * volatile pointer the compiler may not optimize away. Evaluates `ptr` and
 * `len` exactly once. Prefer a platform secure-zero (memset_s / explicit_bzero
 * / SecureZeroMemory) where one is available.
 */
#define GMCRYPTO_ZEROIZE(ptr, len) \
    do { \
        volatile unsigned char *gmcrypto_zptr_ = (volatile unsigned char *)(ptr); \
        size_t gmcrypto_zlen_ = (size_t)(len); \
        while (gmcrypto_zlen_ != 0u) { *gmcrypto_zptr_++ = 0u; gmcrypto_zlen_--; } \
    } while (0)
'''

[export]
prefix = ""

[export.rename]
# Use snake_case-friendly C names for opaque handle types.

[fn]
prefix = ""
postfix = ""
args = "auto"
rename_args = "snake_case"
must_use = ""

[enum]
prefix_with_name = true
rename_variants = "ScreamingSnakeCase"

[struct]
rename_fields = "snake_case"

[parse]
parse_deps = false
extra_bindings = []

[parse.expand]
crates = []
