Guest User

Untitled

a guest
Aug 11th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cstring>
  3.  
  4. #include "utils.h"
  5. #include "app.h"
  6. #include "wallet.h"
  7. #include "enclave.h"
  8.  
  9. void info_print(const char* str) {
  10. printf("[INFO] %s\n", str);
  11. }
  12.  
  13. void warning_print(const char* str) {
  14. printf("[WARNING] %s\n", str);
  15. }
  16.  
  17. void error_print(const char* str) {
  18. printf("[ERROR] %s\n", str);
  19. }
  20.  
  21. void print_wallet(const wallet_t* wallet) {
  22. printf("\n-----------------------------------------\n\n");
  23. printf("Simple password wallet based on Intel SGX.\n\n");
  24. printf("Number of items: %lu\n\n", wallet->size);
  25. for (int i = 0; i < wallet->size; ++i) {
  26. printf("#%d -- %s\n", i, wallet->items[i].title);
  27. printf("[username:] %s\n", wallet->items[i].username);
  28. printf("[password:] %s\n", wallet->items[i].password);
  29. printf("\n");
  30. }
  31. printf("\n------------------------------------------\n\n");
  32. }
  33.  
  34. int is_error(int error_code) {
  35. char err_message[100];
  36.  
  37. // check error case
  38. switch(error_code) {
  39. case RET_SUCCESS:
  40. return 0;
  41.  
  42. case ERR_PASSWORD_OUT_OF_RANGE:
  43. sprintf(err_message, "Password should be at least 8 characters long and at most %d.", MAX_ITEM_SIZE);
  44. break;
  45.  
  46. case ERR_WALLET_ALREADY_EXISTS:
  47. sprintf(err_message, "Wallet already exists: delete file '%s' first.", WALLET_FILE);
  48. break;
  49.  
  50. case ERR_CANNOT_SAVE_WALLET:
  51. strcpy(err_message, "Coud not save wallet.");
  52. break;
  53.  
  54. case ERR_CANNOT_LOAD_WALLET:
  55. strcpy(err_message, "Coud not load wallet.");
  56. break;
  57.  
  58. case ERR_WRONG_MASTER_PASSWORD:
  59. strcpy(err_message, "Wrong master password.");
  60. break;
  61.  
  62. case ERR_WALLET_FULL:
  63. sprintf(err_message, "Wallet full (maximum number of item: %d).", MAX_ITEMS);
  64. break;
  65.  
  66. case ERR_ITEM_DOES_NOT_EXIST:
  67. strcpy(err_message, "Item does not exist.");
  68. break;
  69.  
  70. case ERR_ITEM_TOO_LONG:
  71. sprintf(err_message, "Item too longth (maximum size: %d).", MAX_ITEM_SIZE);
  72. break;
  73.  
  74. case ERR_FAIL_SEAL:
  75. sprintf(err_message, "Fail to seal wallet.");
  76. break;
  77.  
  78. case ERR_FAIL_UNSEAL:
  79. sprintf(err_message, "Fail to unseal wallet.");
  80. break;
  81.  
  82. default:
  83. sprintf(err_message, "Unknown error.");
  84. }
  85.  
  86. // print error message
  87. error_print(err_message);
  88. return 1;
  89. }
  90.  
  91. void show_help() {
  92. const char* command = "[-h Show this screen] [-v Show version] [-s Show wallet] " \
  93. "[-n master-password] [-p master-password -c new-master-password]" \
  94. "[-p master-password -a -x items_title -y items_username -z toitems_password]" \
  95. "[-p master-password -r items_index]";
  96. printf("\nusage: %s %s\n\n", APP_NAME, command);
  97. }
Add Comment
Please, Sign In to add comment