filecryption.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include <stddef.h>
  3. #include <stdint.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #ifdef _MSC_VER
  8. #ifdef LIBFILECRYPTION_EXPORTS
  9. #define FILECRYPTION_API(type) _declspec(dllexport) type
  10. #else
  11. #define FILECRYPTION_API(type) _declspec(dllimport) type
  12. #endif
  13. # elif ( defined(__GNUC__) && __GNUC__ >= 4 )
  14. #define FILECRYPTION_API(type) __attribute__((visibility("default"))) type
  15. #else
  16. #define FILECRYPTION_API(type)
  17. #endif
  18. #ifndef RVC_FILEENC_STR
  19. #define RVC_FILEENC_STR "enc_"
  20. #endif
  21. #ifndef RVC_FILEDEC_STR
  22. #define RVC_FILEDEC_STR "dec_"
  23. #endif
  24. //加密算法版本
  25. enum eRvcCryptionVersion{
  26. eVerA,
  27. eVerB,
  28. eVerC,
  29. eVerD
  30. };
  31. enum filecrypt_loglevel {
  32. FILECRYPT_LEVEL_DEBUG,
  33. FILECRYPT_LEVEL_INFO,
  34. FILECRYPT_LEVEL_WARN,
  35. FILECRYPT_LEVEL_ERROR,
  36. FILECRYPT_LEVEL_FATAL
  37. };
  38. typedef struct filecryption_callback_s {
  39. void (*oncryptionexception)(void *user_data);
  40. void (*oncryptionfinished)(void *user_data);
  41. void (*dbg)(filecrypt_loglevel elevel, const char* fmt, ...);
  42. }filecryption_callback_t;
  43. #ifndef safe_log
  44. #define safe_log(x, elevel, strformat, ...) \
  45. do{\
  46. if (x && x->dbg){ x->dbg(elevel, strformat, ##__VA_ARGS__);}\
  47. }while(0)
  48. #endif
  49. FILECRYPTION_API(int) encryption_file(char* poutfile, uint32_t uoutlen, const char* pfilename, const filecryption_callback_t* pcallback, eRvcCryptionVersion eversion);
  50. FILECRYPTION_API(int) decryption_file(char* poutfile, uint32_t uoutlen, const char* pfilename, const filecryption_callback_t* pcallback = NULL, eRvcCryptionVersion eversion = eVerA);
  51. FILECRYPTION_API(bool) is_file_encrypted(const char* pfilename, const filecryption_callback_t* pcallback);
  52. FILECRYPTION_API(int) rvc_file_decrypt(unsigned char** pdechead, uint32_t* udecheadlen, int* ioffset, char** pstrjson, uint32_t* ujsonlen,const char* pfilename, const filecryption_callback_t* pcallback = NULL, eRvcCryptionVersion eversion = eVerA);
  53. FILECRYPTION_API(int) rvc_free_data(void** pdechead);
  54. FILECRYPTION_API(bool) is_file_completed(const char* pfilename, const filecryption_callback_t* pcallback);
  55. FILECRYPTION_API(int) get_file_sm3digest(char* strbuf, uint32_t ubuflen, const char* pfilename);
  56. #ifdef __cplusplus
  57. } // extern "C" {
  58. #endif