scryptenc_print_error.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <assert.h>
  2. #include <stddef.h>
  3. #include "warnp.h"
  4. #include "scryptenc.h"
  5. #include "scryptenc_print_error.h"
  6. /**
  7. * scryptenc_print_error(rc, infilename, outfilename):
  8. * Print the error corresponding to ${rc}. If relevant, use ${infilename}
  9. * or ${outfilename} to display an error about reading or writing; these
  10. * arguments can be NULL to indicate standard input or output.
  11. */
  12. void
  13. scryptenc_print_error(int rc, const char * infilename,
  14. const char * outfilename)
  15. {
  16. /* Sanity check: this should only be used for errors. */
  17. assert(rc != SCRYPT_OK);
  18. /* Display error. */
  19. switch (rc) {
  20. case SCRYPT_ELIMIT:
  21. warnp("Error determining amount of available memory");
  22. break;
  23. case SCRYPT_ECLOCK:
  24. warnp("Error reading clocks");
  25. break;
  26. case SCRYPT_EKEY:
  27. warnp("Error computing derived key");
  28. break;
  29. case SCRYPT_ESALT:
  30. warnp("Error reading salt");
  31. break;
  32. case SCRYPT_EOPENSSL:
  33. warnp("OpenSSL error");
  34. break;
  35. case SCRYPT_ENOMEM:
  36. warnp("Error allocating memory");
  37. break;
  38. case SCRYPT_EINVAL:
  39. warn0("Input is not valid scrypt-encrypted block");
  40. break;
  41. case SCRYPT_EVERSION:
  42. warn0("Unrecognized scrypt format version");
  43. break;
  44. case SCRYPT_ETOOBIG:
  45. warn0("Decrypting file would require too much memory");
  46. break;
  47. case SCRYPT_ETOOSLOW:
  48. warn0("Decrypting file would take too much CPU time");
  49. break;
  50. case SCRYPT_EBIGSLOW:
  51. warn0("Decrypting file would require too much memory"
  52. " and CPU time");
  53. break;
  54. case SCRYPT_EPASS:
  55. warn0("Passphrase is incorrect");
  56. break;
  57. case SCRYPT_EWRFILE:
  58. warnp("Error writing file: %s",
  59. (outfilename != NULL) ? outfilename : "standard output");
  60. break;
  61. case SCRYPT_ERDFILE:
  62. warnp("Error reading file: %s",
  63. (infilename != NULL) ? infilename : "standard input");
  64. break;
  65. case SCRYPT_EPARAM:
  66. warn0("Error in explicit parameters");
  67. break;
  68. }
  69. }