3 /// The Parser class for brecsum.
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
31 explicit ChecksumParser(bool IncludeIds
)
32 : m_IncludeIds(IncludeIds
)
35 virtual void ParseRecord(const Barry::DBData
&data
,
36 const Barry::IConverter
*ic
)
39 using namespace Barry
;
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();
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
];