main.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef H_PASSWD_MAIN_H
  2. #define H_PASSWD_MAIN_H
  3. #include <stdbool.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #ifndef KEY_MAX_LEN
  7. #define KEY_MAX_LEN (60) /* 密钥最大长度 */
  8. #endif
  9. #ifndef KEY_MIN_LEN
  10. #define KEY_MIN_LEN (10) /* 密钥最短长度 */
  11. #endif
  12. #ifndef VERSION
  13. #define VERSION "Special version."
  14. #define VERSION_INFO "Special characters, special uses."
  15. #endif
  16. #define MD5_SIZE (16)
  17. #define MD5_STR_LEN (MD5_SIZE * 2)
  18. #define DEL_CONTENT_SZIE (20)
  19. static void *s_calloc(size_t n, size_t s) {
  20. void *new = calloc(n, s);
  21. if (new == NULL)
  22. exit(EXIT_FAILURE);
  23. return new;
  24. }
  25. #define free(p) (((p) != NULL ? (free(p), NULL) : NULL), ((p) = NULL))
  26. #define calloc(n, s) (s_calloc(n, s))
  27. struct MD5_CTX {
  28. unsigned int count[2];
  29. unsigned int state[4];
  30. unsigned char buffer[64];
  31. };
  32. typedef struct MD5_CTX MD5_CTX;
  33. void MD5Init(MD5_CTX *context);
  34. void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int input_len);
  35. void MD5Final(MD5_CTX *context,unsigned char digest[16]);
  36. char *base64Encode(char *str);
  37. char *base64Decode(char *code);
  38. void initBase64(char *key);
  39. bool isLegalKey(char *key);
  40. char *makePasswordString(char *account, char *passwd, char *note);
  41. bool getInfoFromPasswordString(char *passwd_base64, char **account, char **passwd, char **note);
  42. void printInfo(char *account, char *passwd, char *note);
  43. void printPasswdStr(char *account, char *passwd, char *note, char *passwd_str);
  44. void randomInit(void);
  45. unsigned long long getRandom(int min, int max);
  46. char *randomPasswd(void);
  47. bool initPasswdInit(const char *path_);
  48. void addContent(char *name, char *passwd_str);
  49. char *findContent(char *name);
  50. void printFileTips(void);
  51. void setFileTips(char *tips);
  52. void printContent(void);
  53. bool writePasswdFile(void);
  54. bool delContent(size_t del_index[], size_t size);
  55. void delContentByName(char *name);
  56. #endif //H_PASSWD_MAIN_H