author | Michael Krelin <hacker@klever.net> | 2011-08-30 20:04:30 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2011-08-30 20:04:30 (UTC) |
commit | 111044b60ba5f40e003d1ba1d4082794985aa3ad (patch) (unidiff) | |
tree | ce7949dad0cded81f47f7f067b43d2c29a795067 /src/eyetil.cc | |
parent | 09b6e86aaad70bc7488604b2e291d098a7de0eac (diff) | |
download | iii-111044b60ba5f40e003d1ba1d4082794985aa3ad.zip iii-111044b60ba5f40e003d1ba1d4082794985aa3ad.tar.gz iii-111044b60ba5f40e003d1ba1d4082794985aa3ad.tar.bz2 |
introduce incremental md5 digester
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | src/eyetil.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/eyetil.cc b/src/eyetil.cc index 7669cb6..57ae607 100644 --- a/src/eyetil.cc +++ b/src/eyetil.cc | |||
@@ -67,12 +67,26 @@ binary_t binary_t::md5() const { | |||
67 | (const unsigned char*)&(front()),size(), | 67 | (const unsigned char*)&(front()),size(), |
68 | (unsigned char*)&(rv.front()) )) | 68 | (unsigned char*)&(rv.front()) )) |
69 | throw std::runtime_error("failed to md5()"); | 69 | throw std::runtime_error("failed to md5()"); |
70 | return rv; | 70 | return rv; |
71 | } | 71 | } |
72 | 72 | ||
73 | void md5_digester::init() { | ||
74 | if(!MD5_Init(&ctx)) throw std::runtime_error("failed to MD5_Init()"); | ||
75 | } | ||
76 | void md5_digester::update(const void *d,size_t l) { | ||
77 | if(!MD5_Update(&ctx,d,l)) throw std::runtime_error("failed to MD5_Update()"); | ||
78 | } | ||
79 | binary_t md5_digester::final() { | ||
80 | binary_t rv(MD5_DIGEST_LENGTH); | ||
81 | if(!MD5_Final((unsigned char*)&(rv.front()), &ctx)) | ||
82 | throw std::runtime_error("failed to MD5_Final()"); | ||
83 | return rv; | ||
84 | } | ||
85 | |||
86 | |||
73 | static void make_path_for_template(const std::string& p,mode_t m) { | 87 | static void make_path_for_template(const std::string& p,mode_t m) { |
74 | struct stat st; | 88 | struct stat st; |
75 | std::string pp; | 89 | std::string pp; |
76 | for(std::string::size_type sl=p.find('/',1); | 90 | for(std::string::size_type sl=p.find('/',1); |
77 | sl!=std::string::npos; | 91 | sl!=std::string::npos; |
78 | sl=p.find('/',sl+1)) { | 92 | sl=p.find('/',sl+1)) { |