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