/* scorpiox-scorpioplayer-media-hash โ€” public C API (C99) * * Four identity hashes: Shooter, OpenSubtitles, stable UTF-16, full-stream MD5. * Bytes in, hex/decimal out. No network, no file-format parsing. */ #ifndef SCORPIOX_SPMHASH_H #define SCORPIOX_SPMHASH_H #include #include #ifdef __cplusplus extern "C" { #endif typedef enum { SPMHASH_OK = 0, SPMHASH_ERR_IO = 1, SPMHASH_ERR_TOO_SMALL = 2, SPMHASH_ERR_INVALID_ARG = 3, SPMHASH_ERR_INVALID_UTF8= 4, SPMHASH_ERR_OOM = 5, SPMHASH_ERR_BUFFER = 6 /* 1.1.0: out_hex/out_cap too small for the result */ } spmhash_status; #define SPMHASH_VERSION "1.1.0" /* Shooter: 4xMD5 lowercase hex joined by ';', or decimal stable-hash fallback * when len <= 8192 and fallback_name is non-NULL. */ int spmhash_shooter_file(const char *path, const char *fallback_name); int spmhash_shooter_buffer(const unsigned char *data, size_t len, const char *fallback_name); /* OpenSubtitles: 64-bit sum, big-endian lowercase hex (16 chars). */ int spmhash_opensubtitles_file(const char *path); int spmhash_opensubtitles_buffer(const unsigned char *data, size_t len); /* Stable hash over UTF-16 code units decoded from UTF-8. * *out receives the abs'd int32; 0 is a legal hash โ€” errors via return code. */ int spmhash_stable_utf8(const char *utf8, int32_t *out); /* Full-stream MD5, UPPERCASE hex (32 chars). */ int spmhash_md5_file(const char *path); int spmhash_md5_buffer(const unsigned char *data, size_t len); /* ---- 1.1.0: chunk hashing (remote streams; no file, no whole-file buffer) ---- * Bit-exact with the *_file / *_buffer variants for the same bytes (SPEC ยง8). * out_hex may be NULL (out_cap 0): the result is still in spmhash_result(). * Otherwise out_cap must hold the result + NUL (OSDb 17, Shooter 132), else * SPMHASH_ERR_BUFFER and out_hex[0] = 0. */ /* head = the first min(total_size, 65536) bytes; tail = the LAST * min(total_size, 65536) bytes of the file (if tail_len is larger, its last * bytes are used โ€” they end at EOF). */ int spmhash_opensubtitles_chunks(const unsigned char *head, size_t head_len, const unsigned char *tail, size_t tail_len, long long total_size, char *out_hex, size_t out_cap); /* b0..b3 = 4096 bytes at offsets 4096, total/3*2, total/3, total-8192 (read * order). A window that runs past EOF hashes as zeros, like the file path: pass * NULL/0, the exact short read, or 4096+ bytes for it. total_size <= 8192 uses * fallback_name (decimal stable hash) and ignores the blocks. */ int spmhash_shooter_chunks(const unsigned char *b0, size_t l0, const unsigned char *b1, size_t l1, const unsigned char *b2, size_t l2, const unsigned char *b3, size_t l3, long long total_size, const char *fallback_name, char *out_hex, size_t out_cap); /* Result string from the last successful shooter / opensubtitles / md5 call. * Valid until the next mutating call. */ const char *spmhash_result(void); const char *spmhash_last_error(void); #ifdef __cplusplus } #endif #endif /* SCORPIOX_SPMHASH_H */