brecsum.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __BARRY_TOOLS_BRECSUM_H__
00023 #define __BARRY_TOOLS_BRECSUM_H__
00024
00025 class ChecksumParser : public Barry::Parser
00026 {
00027 bool m_IncludeIds;
00028 Barry::SHA_CTX m_ctx;
00029
00030 public:
00031 explicit ChecksumParser(bool IncludeIds)
00032 : m_IncludeIds(IncludeIds)
00033 {}
00034
00035 virtual void ParseRecord(const Barry::DBData &data,
00036 const Barry::IConverter *ic)
00037 {
00038 using namespace std;
00039 using namespace Barry;
00040
00041 SHA1_Init(&m_ctx);
00042
00043 if( m_IncludeIds ) {
00044 SHA1_Update(&m_ctx, data.GetDBName().c_str(),
00045 data.GetDBName().size());
00046
00047 uint8_t recType = data.GetRecType();
00048 SHA1_Update(&m_ctx, &recType, sizeof(recType));
00049
00050 uint32_t uniqueId = data.GetUniqueId();
00051 SHA1_Update(&m_ctx, &uniqueId, sizeof(uniqueId));
00052 }
00053
00054 int len = data.GetData().GetSize() - data.GetOffset();
00055 SHA1_Update(&m_ctx,
00056 data.GetData().GetData() + data.GetOffset(), len);
00057
00058 unsigned char sha1[SHA_DIGEST_LENGTH];
00059 SHA1_Final(sha1, &m_ctx);
00060
00061 for( int i = 0; i < SHA_DIGEST_LENGTH; i++ ) {
00062 cout << hex << setfill('0') << setw(2)
00063 << (unsigned int) sha1[i];
00064 }
00065 cout << endl;
00066 }
00067 };
00068
00069 #endif
00070