filecryption.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_LOG_NO,
  33. FILECRYPT_LOG_DEBUG,
  34. FILECRYPT_LOG_INFO,
  35. FILECRYPT_LOG_ERROR
  36. };
  37. typedef struct filecryption_callback_s {
  38. void (*oncryptionexception)(void *user_data);
  39. void (*oncryptionfinished)(void *user_data);
  40. void (*dbg)(filecrypt_loglevel elevel, const char* fmt, ...);
  41. }filecryption_callback_t;
  42. #ifndef safe_log
  43. #define safe_log(x, elevel, strformat, ...) \
  44. do{\
  45. if (x && x->dbg){ x->dbg(elevel, strformat, ##__VA_ARGS__);}\
  46. }while(0)
  47. #endif
  48. FILECRYPTION_API(int) encryption_file(char* poutfile, uint32_t uoutlen, const char* pfilename, const filecryption_callback_t* pcallback, eRvcCryptionVersion eversion);
  49. FILECRYPTION_API(int) decryption_file(char* poutfile, uint32_t uoutlen, const char* pfilename, const filecryption_callback_t* pcallback = NULL, eRvcCryptionVersion eversion = eVerA);
  50. FILECRYPTION_API(bool) is_file_encrypted(const char* pfilename, const filecryption_callback_t* pcallback);
  51. 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);
  52. FILECRYPTION_API(int) rvc_free_data(void** pdechead);
  53. FILECRYPTION_API(bool) is_file_completed(const char* pfilename, const filecryption_callback_t* pcallback);
  54. FILECRYPTION_API(int) get_file_sm3digest(char* strbuf, uint32_t ubuflen, const char* pfilename);
  55. #ifdef __cplusplus
  56. } // extern "C" {
  57. #endif