model-wire: Adding partial compliance to CCNb format in Signature block
Now digest algorithm is specified as NOP and SignatureBits are padded to
16 bits
Refs #1021 (http://redmine.named-data.net/issues/1021)
diff --git a/model/wire/ccnb/wire-ccnb-data.cc b/model/wire/ccnb/wire-ccnb-data.cc
index e625e06..fb87899 100644
--- a/model/wire/ccnb/wire-ccnb-data.cc
+++ b/model/wire/ccnb/wire-ccnb-data.cc
@@ -190,7 +190,8 @@
// {
// Ccnb::AppendString (start, CcnbParser::CCN_DTAG_DigestAlgorithm, GetSignature ().GetDigestAlgorithm ());
// }
- Ccnb::AppendTaggedBlob (start, CcnbParser::CCN_DTAG_SignatureBits, m_data->GetSignature ()); // <SignatureBits />
+ Ccnb::AppendString (start, CcnbParser::CCN_DTAG_DigestAlgorithm, "NOP");
+ Ccnb::AppendTaggedBlobWithPadding (start, CcnbParser::CCN_DTAG_SignatureBits, 16, m_data->GetSignature ()); // <SignatureBits />
Ccnb::AppendCloser (start); // </Signature>
Ccnb::AppendBlockHeader (start, CcnbParser::CCN_DTAG_Name, CcnbParser::CCN_DTAG); // <Name>
@@ -269,8 +270,10 @@
// {
// written += Ccnb::EstimateString (CcnbParser::CCN_DTAG_DigestAlgorithm, GetSignature ().GetDigestAlgorithm ());
// }
- written += Ccnb::EstimateTaggedBlob (CcnbParser::CCN_DTAG_SignatureBits,
- sizeof (m_data->GetSignature ())); // <SignatureBits />
+ written += Ccnb::EstimateString (CcnbParser::CCN_DTAG_DigestAlgorithm, "NOP");
+ // "signature" will be always padded to 16 octets
+ written += Ccnb::EstimateTaggedBlob (CcnbParser::CCN_DTAG_SignatureBits, 16); // <SignatureBits />
+ // written += Ccnb::EstimateTaggedBlob (CcnbParser::CCN_DTAG_SignatureBits, sizeof (m_data->GetSignature ())); // <SignatureBits />
written += 1; // </Signature>
written += Ccnb::EstimateBlockHeader (CcnbParser::CCN_DTAG_Name); // <Name>
diff --git a/model/wire/ccnb/wire-ccnb.cc b/model/wire/ccnb/wire-ccnb.cc
index e3a9ef1..7b92408 100644
--- a/model/wire/ccnb/wire-ccnb.cc
+++ b/model/wire/ccnb/wire-ccnb.cc
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
#include "wire-ccnb.h"
@@ -92,7 +92,7 @@
os << number;
return EstimateBlockHeader (os.str ().size ()) + os.str ().size ();
}
-
+
size_t
Ccnb::AppendCloser (Buffer::Iterator &start)
{
@@ -110,7 +110,7 @@
intmax_t ts = time.ToInteger (Time::S) >> 4;
for (; required_bytes < 7 && ts != 0; ts >>= 8) // not more than 6 bytes?
required_bytes++;
-
+
size_t len = AppendBlockHeader(start, required_bytes, CcnbParser::CCN_BLOB);
// write part with seconds
@@ -123,7 +123,7 @@
(((time.ToInteger (Time::NS) % 1000000000) / 5 * 8 + 195312) / 390625);
for (int i = required_bytes - 2; i < required_bytes; i++)
start.WriteU8 ( ts >> (8 * (required_bytes - 1 - i)) );
-
+
return len + required_bytes;
}
@@ -158,6 +158,35 @@
}
size_t
+Ccnb::AppendTaggedBlobWithPadding (Buffer::Iterator &start, uint32_t dtag,
+ uint32_t length,
+ const uint8_t *data, size_t size)
+{
+ if (size > length)
+ {
+ // no padding required
+ return AppendTaggedBlob (start, dtag, data, size);
+ }
+
+
+ size_t written = AppendBlockHeader (start, dtag, CcnbParser::CCN_DTAG);
+
+ /* 2 */
+ if (length>0)
+ {
+ written += AppendBlockHeader (start, length, CcnbParser::CCN_BLOB);
+ start.Write (data, size);
+ start.WriteU8 (0, length - size);
+ written += length;
+ /* size */
+ }
+ written += AppendCloser (start);
+ /* 1 */
+
+ return written;
+}
+
+size_t
Ccnb::EstimateTaggedBlob (uint32_t dtag, size_t size)
{
if (size>0)
diff --git a/model/wire/ccnb/wire-ccnb.h b/model/wire/ccnb/wire-ccnb.h
index 91d3d9e..bb1eef6 100644
--- a/model/wire/ccnb/wire-ccnb.h
+++ b/model/wire/ccnb/wire-ccnb.h
@@ -121,6 +121,24 @@
const uint8_t *data, size_t size);
/**
+ * Append a tagged BLOB, adding 0-byte padding if necessary
+ *
+ * This is a ccnb-encoded element with containing the BLOB as content
+ *
+ * @param start start iterator of the buffer to append to.
+ * @param dtag is the element's dtab
+ * @param length minimum required length of the added field (padding added if necessary)
+ * @param data points to the binary data
+ * @param size is the size of the data, in bytes
+ *
+ * @returns written length
+ */
+ static size_t
+ AppendTaggedBlobWithPadding (Buffer::Iterator &start, uint32_t dtag,
+ uint32_t length,
+ const uint8_t *data, size_t size);
+
+ /**
* @brief Estimate size of a tagged BLOB in CCNB enconding
* @param dtag is the element's dtab
* @param size is the size of the data, in bytes
@@ -147,6 +165,24 @@
AppendTaggedBlob (Buffer::Iterator &start, uint32_t dtag, const T &data);
/**
+ * Append value as a tagged BLOB (templated version), add 0-padding if necessary
+ *
+ * This is a ccnb-encoded element with containing the BLOB as content
+ *
+ * Data will be reinterpret_cast<const uint8_t*> and size will be obtained using sizeof
+ *
+ * @param start start iterator of the buffer to append to.
+ * @param dtag is the element's dtab
+ * @param length minimum required length of the field
+ * @param data a value to add
+ *
+ * @returns written length
+ */
+ template<class T>
+ static inline size_t
+ AppendTaggedBlobWithPadding (Buffer::Iterator &start, uint32_t dtag, uint32_t length, const T &data);
+
+ /**
* Append a tagged string (should be a valid UTF-8 coded string)
*
* This is a ccnb-encoded element with containing UDATA as content
@@ -203,12 +239,19 @@
template<class T>
-size_t
+inline size_t
Ccnb::AppendTaggedBlob (Buffer::Iterator &start, uint32_t dtag, const T &data)
{
return AppendTaggedBlob (start, dtag, reinterpret_cast<const uint8_t*> (&data), sizeof (data));
}
+template<class T>
+inline size_t
+Ccnb::AppendTaggedBlobWithPadding (Buffer::Iterator &start, uint32_t dtag, uint32_t length, const T &data)
+{
+ return AppendTaggedBlobWithPadding (start, dtag, length, reinterpret_cast<const uint8_t*> (&data), sizeof (data));
+}
+
} // wire
NDN_NAMESPACE_END