Move publisherPublicKeyDigest and keyLocator from MetaInfo to Signature.
diff --git a/ndn-cpp/c/data.h b/ndn-cpp/c/data.h
index 0226919..0990d86 100644
--- a/ndn-cpp/c/data.h
+++ b/ndn-cpp/c/data.h
@@ -14,6 +14,9 @@
extern "C" {
#endif
+/**
+ * An ndn_Signature struct holds the signature bits and other info representing the signature in a data packet.
+ */
struct ndn_Signature {
unsigned char *digestAlgorithm; /**< pointer to pre-allocated buffer. 0 for none.
* If none, default is 2.16.840.1.101.3.4.2.1 (sha-256). */
@@ -22,15 +25,25 @@
unsigned int witnessLength; /**< length of witness. 0 for none */
unsigned char *signature;
unsigned int signatureLength;
+ struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
+ struct ndn_KeyLocator keyLocator;
};
-static inline void ndn_Signature_initialize(struct ndn_Signature *self) {
+/**
+ * Initialize the ndn_Signature struct with values for none and the default digestAlgorithm.
+ * @param self A pointer to the ndn_MetaInfo struct.
+ * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator.
+ * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
+ */
+static inline void ndn_Signature_initialize(struct ndn_Signature *self, struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents) {
self->digestAlgorithm = 0;
self->digestAlgorithmLength = 0;
self->witness = 0;
self->witnessLength = 0;
self->signature = 0;
self->signatureLength = 0;
+ ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
+ ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents);
}
typedef enum {
@@ -42,30 +55,27 @@
ndn_ContentType_NACK = 5
} ndn_ContentType;
+/**
+ * An ndn_MetaInfo struct holds the meta info which is signed inside the data packet.
+ */
struct ndn_MetaInfo {
- struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
double timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */
ndn_ContentType type; /**< default is ndn_ContentType_DATA. -1 for none */
int freshnessSeconds; /**< -1 for none */
unsigned char *finalBlockID; /**< pointer to pre-allocated buffer. 0 for none */
unsigned int finalBlockIDLength; /**< length of finalBlockID. 0 for none */
- struct ndn_KeyLocator keyLocator;
};
/**
* Initialize the ndn_MetaInfo struct with values for none and the type to the default ndn_ContentType_DATA.
* @param self A pointer to the ndn_MetaInfo struct.
- * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator.
- * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
*/
static inline void ndn_MetaInfo_initialize
- (struct ndn_MetaInfo *self, struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents) {
- ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
+ (struct ndn_MetaInfo *self) {
self->type = ndn_ContentType_DATA;
self->freshnessSeconds = -1;
self->finalBlockID = 0;
self->finalBlockIDLength = 0;
- ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents);
}
struct ndn_Data {
@@ -82,16 +92,16 @@
* @param self A pointer to the ndn_Data struct.
* @param nameComponents The pre-allocated array of ndn_NameComponent.
* @param maxNameComponents The number of elements in the allocated nameComponents array.
- * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the metaInfo.keyLocator.
+ * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the signature.keyLocator.
* @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
*/
static inline void ndn_Data_initialize
(struct ndn_Data *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents,
struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents)
{
- ndn_Signature_initialize(&self->signature);
+ ndn_Signature_initialize(&self->signature, keyNameComponents, maxKeyNameComponents);
ndn_Name_initialize(&self->name, nameComponents, maxNameComponents);
- ndn_MetaInfo_initialize(&self->metaInfo, keyNameComponents, maxKeyNameComponents);
+ ndn_MetaInfo_initialize(&self->metaInfo);
self->content = 0;
self->contentLength = 0;
}
diff --git a/ndn-cpp/c/encoding/binary-xml-data.c b/ndn-cpp/c/encoding/binary-xml-data.c
index ebc9987..b07b7a4 100644
--- a/ndn-cpp/c/encoding/binary-xml-data.c
+++ b/ndn-cpp/c/encoding/binary-xml-data.c
@@ -56,7 +56,7 @@
return NDN_ERROR_success;
}
-static ndn_Error encodeSignedInfo(struct ndn_MetaInfo *metaInfo, struct ndn_BinaryXmlEncoder *encoder)
+static ndn_Error encodeSignedInfo(struct ndn_Signature *signature, struct ndn_MetaInfo *metaInfo, struct ndn_BinaryXmlEncoder *encoder)
{
if (metaInfo->type < 0)
return NDN_ERROR_success;
@@ -66,7 +66,7 @@
return error;
// This will skip encoding if there is no publisherPublicKeyDigest.
- if ((error = ndn_encodeBinaryXmlPublisherPublicKeyDigest(&metaInfo->publisherPublicKeyDigest, encoder)))
+ if ((error = ndn_encodeBinaryXmlPublisherPublicKeyDigest(&signature->publisherPublicKeyDigest, encoder)))
return error;
if ((error = ndn_BinaryXmlEncoder_writeOptionalTimeMillisecondsDTagElement
@@ -104,7 +104,7 @@
return error;
// This will skip encoding if there is no key locator.
- if ((error = ndn_encodeBinaryXmlKeyLocator(&metaInfo->keyLocator, encoder)))
+ if ((error = ndn_encodeBinaryXmlKeyLocator(&signature->keyLocator, encoder)))
return error;
if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
@@ -113,13 +113,13 @@
return NDN_ERROR_success;
}
-static ndn_Error decodeSignedInfo(struct ndn_MetaInfo *metaInfo, struct ndn_BinaryXmlDecoder *decoder)
+static ndn_Error decodeSignedInfo(struct ndn_Signature *signature, struct ndn_MetaInfo *metaInfo, struct ndn_BinaryXmlDecoder *decoder)
{
ndn_Error error;
if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_SignedInfo)))
return error;
- if ((error = ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest(&metaInfo->publisherPublicKeyDigest, decoder)))
+ if ((error = ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest(&signature->publisherPublicKeyDigest, decoder)))
return error;
if (error= ndn_BinaryXmlDecoder_readOptionalTimeMillisecondsDTagElement
@@ -162,7 +162,7 @@
(decoder, ndn_BinaryXml_DTag_FinalBlockID, 0, &metaInfo->finalBlockID, &metaInfo->finalBlockIDLength)))
return error;
- if ((error = ndn_decodeOptionalBinaryXmlKeyLocator(&metaInfo->keyLocator, decoder)))
+ if ((error = ndn_decodeOptionalBinaryXmlKeyLocator(&signature->keyLocator, decoder)))
return error;
if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
@@ -186,7 +186,7 @@
if ((error = ndn_encodeBinaryXmlName(&data->name, encoder)))
return error;
- if ((error = encodeSignedInfo(&data->metaInfo, encoder)))
+ if ((error = encodeSignedInfo(&data->signature, &data->metaInfo, encoder)))
return error;
if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
@@ -216,7 +216,7 @@
return error;
}
else
- ndn_Signature_initialize(&data->signature);
+ ndn_Signature_initialize(&data->signature, data->signature.keyLocator.keyName.components, data->signature.keyLocator.keyName.maxComponents);
*signedFieldsBeginOffset = decoder->offset;
@@ -226,11 +226,11 @@
if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_SignedInfo, &gotExpectedTag)))
return error;
if (gotExpectedTag) {
- if ((error = decodeSignedInfo(&data->metaInfo, decoder)))
+ if ((error = decodeSignedInfo(&data->signature, &data->metaInfo, decoder)))
return error;
}
else
- ndn_MetaInfo_initialize(&data->metaInfo, data->metaInfo.keyLocator.keyName.components, data->metaInfo.keyLocator.keyName.maxComponents);
+ ndn_MetaInfo_initialize(&data->metaInfo);
// Require a Content element, but set allowNull to allow a missing BLOB.
if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement