summaryrefslogtreecommitdiffabout
path: root/src/eyetil.h
Unidiff
Diffstat (limited to 'src/eyetil.h') (more/less context) (ignore whitespace changes)
-rw-r--r--src/eyetil.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/eyetil.h b/src/eyetil.h
index d946e71..eff2c43 100644
--- a/src/eyetil.h
+++ b/src/eyetil.h
@@ -5,6 +5,7 @@
5#include <string> 5#include <string>
6#include <archive.h> 6#include <archive.h>
7#include <archive_entry.h> 7#include <archive_entry.h>
8#include "openssl/md5.h"
8 9
9class binary_t : public std::vector<unsigned char> { 10class binary_t : public std::vector<unsigned char> {
10 public: 11 public:
@@ -21,6 +22,42 @@ class binary_t : public std::vector<unsigned char> {
21 binary_t md5() const; 22 binary_t md5() const;
22}; 23};
23 24
25struct md5_digester {
26 MD5_CTX ctx;
27 md5_digester() { init(); }
28
29 void init();
30 void update(const void *d,size_t l);
31 binary_t final();
32
33 template<typename T>
34 void update(const T& x) { update(&x,sizeof(x)); }
35
36 template<typename T>
37 struct update_iterator : public std::iterator<std::output_iterator_tag,T,void,T*,T&> {
38 md5_digester *d;
39 update_iterator(md5_digester *d_) : d(d_) { }
40 update_iterator(const update_iterator& x) : d(x.d) { }
41
42 update_iterator& operator*() { return *this; }
43 update_iterator& operator++() { return *this; }
44 update_iterator& operator++(int) { return *this; }
45
46 update_iterator& operator=(const T& x) {
47 d->update(x); return *this;
48 }
49 };
50
51 template<typename T>
52 update_iterator<T> updater() {
53 return update_iterator<T>(this);
54 }
55
56};
57template<> inline void md5_digester::update<binary_t>(const binary_t& x) {
58 update((const unsigned char*)&(x.front()),x.size());
59}
60
24class tmpdir_t { 61class tmpdir_t {
25 public: 62 public:
26 std::string dir; 63 std::string dir;