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