/** * @file include/ActivMiddleware/Misc/Sha1Helper.h * * @brief Helper class for SHA1 calculation. */ #if (!defined ACTIV_MISC_SHA1_HELPER_H) #define ACTIV_MISC_SHA1_HELPER_H #include "ActivMiddleware/ActivMiddleware.h" #include ACTIV_BOOST_INCLUDE(uuid/detail/sha1.hpp) //! Activ namespace. namespace Activ { /** * @brief Sha1 calculator helper. */ class Sha1Helper { public: static const size_t digestLength = 20; typedef byte_t Digest[digestLength]; //! Default constructor. Sha1Helper(); /** * @brief Constructor. * * @param pData the data to hash. * @param dataLength the length of the data. */ Sha1Helper(const void * const pData, const size_t dataLength); //! Reset. void Reset(); /** * @brief Hash some (more) data. * * @param pData the data to hash. * @param dataLength the length of the data. */ void ProcessData(const void *pData, size_t dataLength); /** * @brief Get the hash value. Only call this function once between Reset()s (or construction and Reset()). * * @return The hash. */ const Digest &Get(); private: Boost::uuids::detail::sha1 m_sha1Calculator; uint32_t m_digest[5]; }; // --------------------------------------------------------------------------------------------------------------------------------- inline Sha1Helper::Sha1Helper() { } // --------------------------------------------------------------------------------------------------------------------------------- inline Sha1Helper::Sha1Helper(const void * const pData, const size_t dataLength) { ProcessData(pData, dataLength); } // --------------------------------------------------------------------------------------------------------------------------------- inline void Sha1Helper::Reset() { m_sha1Calculator.reset(); } // --------------------------------------------------------------------------------------------------------------------------------- inline void Sha1Helper::ProcessData(const void *pData, size_t dataLength) { m_sha1Calculator.process_bytes(pData, dataLength); } // --------------------------------------------------------------------------------------------------------------------------------- inline const Sha1Helper::Digest &Sha1Helper::Get() { m_sha1Calculator.get_digest(m_digest); ACTIV_FOREACH (uint32_t &block, m_digest) { block = HostToBigEndianOrder(block); } return reinterpret_cast(m_digest); } } // namespace Activ #endif // (!defined ACTIV_MISC_SHA1_HELPER_H)