C++ Library to handle BagIt structures. BagIt is a standard format to create transfer packages for digital preservation purposes. See https://en.wikipedia.org/wiki/BagIt for details http://andreas-romeyke.de
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

  1. // Copyright (C) 2018 Andreas Romeyke (art1@andreas-romeyke.de), 2018.
  2. //
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. #ifndef LIBCBAG_CHECKSUM
  16. #define LIBCBAG_CHECKSUM
  17. #include <sstream>
  18. #include <list>
  19. #include <string>
  20. #include <openssl/md5.h>
  21. #include <openssl/sha.h>
  22. using namespace std;
  23. typedef struct {
  24. long unsigned int octetcount;
  25. long unsigned int streamcount;
  26. } oxum_t;
  27. //enum Checksum_algorithms {md5=1, sha1, sha256};
  28. #define SequentialEnum(Name,...) \
  29. enum Name { __VA_ARGS__ }; \
  30. namespace \
  31. { \
  32. const std::initializer_list<Name> Name##List { __VA_ARGS__ }; \
  33. };
  34. SequentialEnum(checksum_algorithms,
  35. md5,
  36. sha1,
  37. sha256,
  38. );
  39. string string_of_algorithm( checksum_algorithms alg);
  40. class Checksum {
  41. private:
  42. stringstream log;
  43. public:
  44. //Checksum();
  45. bool is_algorithm_supported( checksum_algorithms alg );
  46. string checksum_of_file(const string& filepath, checksum_algorithms alg);
  47. oxum_t oxum_of_file(const string& filepath);
  48. oxum_t oxum_of_filelist( list<string> files);
  49. void get_logstream( stringstream & log);
  50. void reset_logstream();
  51. };
  52. #endif
  53. // vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab