cmCryptoHash.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmCryptoHash_h
  11. #define cmCryptoHash_h
  12. #include "cmStandardIncludes.h"
  13. #include <cmsys/auto_ptr.hxx>
  14. class cmCryptoHash
  15. {
  16. public:
  17. static cmsys::auto_ptr<cmCryptoHash> New(const char* algo);
  18. std::string HashString(const char* input);
  19. std::string HashFile(const char* file);
  20. protected:
  21. virtual void Initialize()=0;
  22. virtual void Append(unsigned char const*, int)=0;
  23. virtual std::string Finalize()=0;
  24. };
  25. class cmCryptoHashMD5: public cmCryptoHash
  26. {
  27. struct cmsysMD5_s* MD5;
  28. public:
  29. cmCryptoHashMD5();
  30. ~cmCryptoHashMD5();
  31. protected:
  32. virtual void Initialize();
  33. virtual void Append(unsigned char const* buf, int sz);
  34. virtual std::string Finalize();
  35. };
  36. #define cmCryptoHash_SHA_CLASS_DECL(SHA) \
  37. class cmCryptoHash##SHA: public cmCryptoHash \
  38. { \
  39. union _SHA_CTX* SHA; \
  40. public: \
  41. cmCryptoHash##SHA(); \
  42. ~cmCryptoHash##SHA(); \
  43. protected: \
  44. virtual void Initialize(); \
  45. virtual void Append(unsigned char const* buf, int sz); \
  46. virtual std::string Finalize(); \
  47. }
  48. cmCryptoHash_SHA_CLASS_DECL(SHA1);
  49. cmCryptoHash_SHA_CLASS_DECL(SHA224);
  50. cmCryptoHash_SHA_CLASS_DECL(SHA256);
  51. cmCryptoHash_SHA_CLASS_DECL(SHA384);
  52. cmCryptoHash_SHA_CLASS_DECL(SHA512);
  53. #undef cmCryptoHash_SHA_CLASS_DECL
  54. #endif