summaryrefslogtreecommitdiffstats
path: root/Source/cmCryptoHash.h
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-11-03 15:33:43 (GMT)
committerBrad King <brad.king@kitware.com>2016-11-10 13:29:37 (GMT)
commit9a596b33bbfdb274ccf7f678c78cb8826c7c363b (patch)
treeedf141d9c6fc8dc3cb23a2048b6fe13ad444e612 /Source/cmCryptoHash.h
parent47f91a6183a6bb65a423d5acb1b75c4b39c17a87 (diff)
downloadCMake-9a596b33bbfdb274ccf7f678c78cb8826c7c363b.zip
CMake-9a596b33bbfdb274ccf7f678c78cb8826c7c363b.tar.gz
CMake-9a596b33bbfdb274ccf7f678c78cb8826c7c363b.tar.bz2
cmCryptoHash: Re-implement in terms of librhash
Offer direct construction with an enumeration of supported algorithms. Also expose the Initialize/Append/Finalize steps publicly and add a FinalizeHex method.
Diffstat (limited to 'Source/cmCryptoHash.h')
-rw-r--r--Source/cmCryptoHash.h61
1 files changed, 20 insertions, 41 deletions
diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h
index 5c2d3ca..95080ac 100644
--- a/Source/cmCryptoHash.h
+++ b/Source/cmCryptoHash.h
@@ -15,7 +15,18 @@
class cmCryptoHash
{
public:
- virtual ~cmCryptoHash() {}
+ enum Algo
+ {
+ AlgoMD5,
+ AlgoSHA1,
+ AlgoSHA224,
+ AlgoSHA256,
+ AlgoSHA384,
+ AlgoSHA512
+ };
+
+ cmCryptoHash(Algo algo);
+ ~cmCryptoHash();
/// @brief Returns a new hash generator of the requested type
/// @arg algo Hash type name. Supported hash types are
@@ -53,47 +64,15 @@ public:
/// An empty string otherwise.
std::string HashFile(const std::string& file);
-protected:
- virtual void Initialize() = 0;
- virtual void Append(unsigned char const*, int) = 0;
- virtual std::vector<unsigned char> Finalize() = 0;
-};
-
-class cmCryptoHashMD5 : public cmCryptoHash
-{
- struct cmsysMD5_s* MD5;
-
-public:
- cmCryptoHashMD5();
- ~cmCryptoHashMD5() CM_OVERRIDE;
+ void Initialize();
+ void Append(void const*, size_t);
+ void Append(std::string const& str);
+ std::vector<unsigned char> Finalize();
+ std::string FinalizeHex();
-protected:
- void Initialize() CM_OVERRIDE;
- void Append(unsigned char const* buf, int sz) CM_OVERRIDE;
- std::vector<unsigned char> Finalize() CM_OVERRIDE;
+private:
+ unsigned int Id;
+ struct rhash_context* CTX;
};
-#define cmCryptoHash_SHA_CLASS_DECL(SHA) \
- class cmCryptoHash##SHA : public cmCryptoHash \
- { \
- union _SHA_CTX* SHA; \
- \
- public: \
- cmCryptoHash##SHA(); \
- ~cmCryptoHash##SHA(); \
- \
- protected: \
- virtual void Initialize(); \
- virtual void Append(unsigned char const* buf, int sz); \
- virtual std::vector<unsigned char> Finalize(); \
- }
-
-cmCryptoHash_SHA_CLASS_DECL(SHA1);
-cmCryptoHash_SHA_CLASS_DECL(SHA224);
-cmCryptoHash_SHA_CLASS_DECL(SHA256);
-cmCryptoHash_SHA_CLASS_DECL(SHA384);
-cmCryptoHash_SHA_CLASS_DECL(SHA512);
-
-#undef cmCryptoHash_SHA_CLASS_DECL
-
#endif