-rw-r--r-- | src/eyetil.cc | 18 | ||||
-rw-r--r-- | src/eyetil.h | 11 |
2 files changed, 16 insertions, 13 deletions
diff --git a/src/eyetil.cc b/src/eyetil.cc index 11e2fb7..cd22eea 100644 --- a/src/eyetil.cc +++ b/src/eyetil.cc @@ -80,12 +80,17 @@ binary_t md5_digester::final() { binary_t rv(MD5_DIGEST_LENGTH); if(!MD5_Final((unsigned char*)&(rv.front()), &ctx)) throw std::runtime_error("failed to MD5_Final()"); return rv; } +uint16_t block512_t::tcpcksum(block512_t& data) { + uint32_t sum = std::accumulate(data.data,data.data+words,0); + while(uint32_t hw = sum>>16) sum = (sum&0xffff)+hw; + return 0xffff&~sum; +} static void make_path_for_template(const std::string& p,mode_t m) { struct stat st; std::string pp; for(std::string::size_type sl=p.find('/',1); sl!=std::string::npos; @@ -147,25 +152,12 @@ std::string tarchive_t::entry_pathname() { bool tarchive_t::read_data_into_fd(int fd) { assert(a); return archive_read_data_into_fd(a,fd)==ARCHIVE_OK; } -#pragma pack(1) -struct block512_t { - enum { words = 512 / sizeof(uint16_t) }; - uint16_t data[words]; - - static uint16_t tcpcksum(block512_t& data) { - uint32_t sum = std::accumulate(data.data,data.data+words,0); - while(uint32_t hw = sum>>16) sum = (sum&0xffff)+hw; - return 0xffff&~sum; - } - -}; -#pragma pack() binary_t integrity_digest(const void *ptr,size_t size,const std::string& ukey) { md5_digester rv; std::transform( (block512_t*)ptr, ((block512_t*)ptr)+size/sizeof(block512_t), rv.updater<uint16_t>(), block512_t::tcpcksum ); rv.update( binary_t(ukey) ); diff --git a/src/eyetil.h b/src/eyetil.h index 03b9ba8..7517ba6 100644 --- a/src/eyetil.h +++ b/src/eyetil.h @@ -60,12 +60,23 @@ struct md5_digester { }; template<> inline void md5_digester::update<binary_t>(const binary_t& x) { update((const unsigned char*)&(x.front()),x.size()); } +#pragma pack(1) +struct block512_t { + enum { words = 512 / sizeof(uint16_t) }; + uint16_t data[words]; + + inline uint8_t *dptr(size_t o) { return ((uint8_t*)this)+o; } + + static uint16_t tcpcksum(block512_t& data); +}; +#pragma pack() + class tmpdir_t { public: std::string dir; tmpdir_t(const std::string& dt); ~tmpdir_t(); |