summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2013-02-13 22:32:22 (GMT)
committer Michael Krelin <hacker@klever.net>2013-02-13 22:32:22 (GMT)
commitdd545573337e3c54ad4c2c64d72f750ad03aa2c9 (patch) (side-by-side diff)
treeedf4e4294fc20418f5590f2698b8ae9b8bb31c65
parentd6d845ab3cdbc76943d68329aa0aaa3ddf2af21a (diff)
downloadiii-dd545573337e3c54ad4c2c64d72f750ad03aa2c9.zip
iii-dd545573337e3c54ad4c2c64d72f750ad03aa2c9.tar.gz
iii-dd545573337e3c54ad4c2c64d72f750ad03aa2c9.tar.bz2
introduced streaming integrity digest updater
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/eyetil.cc28
-rw-r--r--src/eyetil.h11
2 files changed, 39 insertions, 0 deletions
diff --git a/src/eyetil.cc b/src/eyetil.cc
index cd22eea..6ccc4ae 100644
--- a/src/eyetil.cc
+++ b/src/eyetil.cc
@@ -89,6 +89,34 @@ uint16_t block512_t::tcpcksum(block512_t& data) {
return 0xffff&~sum;
}
+void integrity_digester::update(const void *d_,size_t s) {
+ uint8_t *d=(uint8_t*)d_;
+ if(data_size) {
+ int l = sizeof(data)-data_size;
+ if(l>s) {
+ memmove(data.dptr(data_size),d,s); data_size+=s; return;
+ }
+ memmove(data.dptr(data_size),d,l); d+=l; s-=l;
+ md5.update<uint16_t>( data.tcpcksum(data) );
+ }
+ if(s<sizeof(data)) {
+ memmove(data.dptr(0),d,s); data_size=s; return;
+ }
+ size_t bb=s/sizeof(block512_t);
+ std::transform((block512_t*)d,((block512_t*)d)+bb,
+ md5.updater<uint16_t>(),block512_t::tcpcksum);
+ size_t ss=bb*sizeof(block512_t);
+ d+=ss; s-=ss;
+ assert(s<sizeof(block512_t));
+ if(s) memmove(data.dptr(0),d,data_size=s);
+}
+
+binary_t integrity_digester::final(const std::string& ukey) {
+ assert(!data_size);
+ md5.update( binary_t(ukey) );
+ return md5.final();
+}
+
static void make_path_for_template(const std::string& p,mode_t m) {
struct stat st;
std::string pp;
diff --git a/src/eyetil.h b/src/eyetil.h
index 7517ba6..8784cb4 100644
--- a/src/eyetil.h
+++ b/src/eyetil.h
@@ -74,6 +74,17 @@ struct block512_t {
};
#pragma pack()
+struct integrity_digester {
+ md5_digester md5;
+ size_t data_size;
+ block512_t data;
+
+ integrity_digester() : data_size(0) { }
+ void update(const void *d,size_t s);
+ binary_t final(const std::string& ukey);
+};
+
+
class tmpdir_t {
public:
std::string dir;