Small extension of Digest. Now it supports adding other digests.
Basically, we're building a hash tree, where leaves as hash(data), next
levels are hash(hash(data)), next levels are hash(hash(hash(data))), etc.
(Though, right now we going to have a very limited and hard-coded number
of levels of this hash tree)
diff --git a/model/sync-digest.cc b/model/sync-digest.cc
index 65e3b44..863431e 100644
--- a/model/sync-digest.cc
+++ b/model/sync-digest.cc
@@ -24,6 +24,9 @@
#include <string.h>
#include "ns3/assert.h"
+#include <boost/exception/errinfo_at_line.hpp>
+
+using namespace boost;
namespace ns3 {
namespace Sync {
@@ -36,7 +39,7 @@
int ok = EVP_DigestInit_ex (m_context, EVP_sha1 (), 0);
if (!ok)
- throw DigestCalculationError ();
+ throw DigestCalculationError () << errinfo_at_line (__LINE__);
}
Digest::~Digest ()
@@ -57,7 +60,7 @@
int ok = EVP_DigestFinal_ex (m_context,
m_buffer, &m_hashLength);
if (!ok)
- throw DigestCalculationError ();
+ throw DigestCalculationError () << errinfo_at_line (__LINE__);
}
std::size_t
@@ -88,6 +91,20 @@
}
+Digest &
+Digest::operator << (const Digest &src)
+{
+ if (src.m_buffer == 0)
+ throw DigestCalculationError () << errinfo_at_line (__LINE__);
+
+ bool ok = EVP_DigestUpdate (m_context, src.m_buffer, src.m_hashLength);
+ if (!ok)
+ throw DigestCalculationError () << errinfo_at_line (__LINE__);
+
+ return *this;
+}
+
+
} // Sync
} // ns3
diff --git a/model/sync-digest.h b/model/sync-digest.h
index 2816b3e..0030b4a 100644
--- a/model/sync-digest.h
+++ b/model/sync-digest.h
@@ -49,9 +49,6 @@
*/
~Digest ();
- // Digest &
- // operator << (
-
/**
* @brief Obtain a short version of the hash (just first sizeof(size_t) bytes
*
@@ -68,6 +65,18 @@
bool
operator == (Digest &digest);
+ /**
+ * @brief Combine digests
+ * @param src digest to combine with
+ *
+ * The result of this combination is hash (hash (...))
+ */
+ Digest &
+ operator << (const Digest &src);
+
+
+
+
private:
/**
* @brief Finalize digest. All subsequent calls to "operator <<" will fire an exception