rpm: removed opensuse special cases
[barry.git] / tools / brecsum.h
blobda64187626eaab59d8895e2adfc02820e78cc509
1 ///
2 /// \file brecsum.h
3 /// The Parser class for brecsum.
4 ///
6 /*
7 Copyright (C) 2008-2011, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_TOOLS_BRECSUM_H__
23 #define __BARRY_TOOLS_BRECSUM_H__
25 class ChecksumParser : public Barry::Parser
27 bool m_IncludeIds;
28 Barry::SHA_CTX m_ctx;
30 public:
31 explicit ChecksumParser(bool IncludeIds)
32 : m_IncludeIds(IncludeIds)
35 virtual void ParseRecord(const Barry::DBData &data,
36 const Barry::IConverter *ic)
38 using namespace std;
39 using namespace Barry;
41 SHA1_Init(&m_ctx);
43 if( m_IncludeIds ) {
44 SHA1_Update(&m_ctx, data.GetDBName().c_str(),
45 data.GetDBName().size());
47 uint8_t recType = data.GetRecType();
48 SHA1_Update(&m_ctx, &recType, sizeof(recType));
50 uint32_t uniqueId = data.GetUniqueId();
51 SHA1_Update(&m_ctx, &uniqueId, sizeof(uniqueId));
54 int len = data.GetData().GetSize() - data.GetOffset();
55 SHA1_Update(&m_ctx,
56 data.GetData().GetData() + data.GetOffset(), len);
58 unsigned char sha1[SHA_DIGEST_LENGTH];
59 SHA1_Final(sha1, &m_ctx);
61 for( int i = 0; i < SHA_DIGEST_LENGTH; i++ ) {
62 cout << hex << setfill('0') << setw(2)
63 << (unsigned int) sha1[i];
65 cout << endl;
69 #endif