Make Signature an abstract base class and added subclass Sha256WithRsaSignature. Change Data.signature to a pointer to a Signature.
diff --git a/ndn-cpp/data.hpp b/ndn-cpp/data.hpp
index bca4507..cb0e559 100644
--- a/ndn-cpp/data.hpp
+++ b/ndn-cpp/data.hpp
@@ -8,82 +8,41 @@
#include "common.hpp"
#include "name.hpp"
-#include "publisher-public-key-digest.hpp"
#include "key.hpp"
#include "c/data.h"
namespace ndn {
/**
- * A Signature holds the signature bits and other info representing the signature in a data packet.
+ * A Signature is an abstract base class providing an methods to work with the signature information in a Data packet.
*/
class Signature {
public:
/**
+ * Return a pointer to a new Signature which is a copy of this signature.
+ * This is pure virtual, the subclass must implement it.
+ */
+ virtual ptr_lib::shared_ptr<Signature> clone() const = 0;
+
+ /**
+ * The virtual destructor.
+ */
+ virtual ~Signature();
+
+ /**
* Set the signatureStruct to point to the values in this signature object, without copying any memory.
* WARNING: The resulting pointers in signatureStruct are invalid after a further use of this object which could reallocate memory.
+ * This is pure virtual, the subclass must implement it.
* @param signatureStruct a C ndn_Signature struct where the name components array is already allocated.
*/
- void get(struct ndn_Signature& signatureStruct) const;
+ virtual void get(struct ndn_Signature& signatureStruct) const = 0;
/**
* Clear this signature, and set the values by copying from the ndn_Signature struct.
+ * This is pure virtual, the subclass must implement it.
* @param signatureStruct a C ndn_Signature struct
*/
- void set(const struct ndn_Signature& signatureStruct);
-
- const Blob& getDigestAlgorithm() const { return digestAlgorithm_; }
-
- const Blob& getWitness() const { return witness_; }
-
- const Blob& getSignature() const { return signature_; }
-
- const PublisherPublicKeyDigest& getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
- PublisherPublicKeyDigest& getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
-
- const KeyLocator& getKeyLocator() const { return keyLocator_; }
- KeyLocator& getKeyLocator() { return keyLocator_; }
-
- void setDigestAlgorithm(const std::vector<unsigned char>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; }
- void setDigestAlgorithm(const unsigned char *digestAlgorithm, unsigned int digestAlgorithmLength)
- {
- digestAlgorithm_ = Blob(digestAlgorithm, digestAlgorithmLength);
- }
-
- void setWitness(const std::vector<unsigned char>& witness) { witness_ = witness; }
- void setWitness(const unsigned char *witness, unsigned int witnessLength)
- {
- witness_ = Blob(witness, witnessLength);
- }
-
- void setSignature(const std::vector<unsigned char>& signature) { signature_ = signature; }
- void setSignature(const unsigned char *signature, unsigned int signatureLength)
- {
- signature_ = Blob(signature, signatureLength);
- }
-
- void setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; }
-
- void setKeyLocator(const KeyLocator& keyLocator) { keyLocator_ = keyLocator; }
-
- /**
- * Clear all the fields.
- */
- void clear()
- {
- digestAlgorithm_.reset();
- witness_.reset();
- signature_.reset();
- publisherPublicKeyDigest_.clear();
- keyLocator_.clear();
- }
-
-private:
- Blob digestAlgorithm_; /**< if empty, the default is 2.16.840.1.101.3.4.2.1 (sha-256) */
- Blob witness_;
- Blob signature_;
- PublisherPublicKeyDigest publisherPublicKeyDigest_;
- KeyLocator keyLocator_;
+ virtual void set(const struct ndn_Signature& signatureStruct) = 0;
};
/**
@@ -139,14 +98,16 @@
class Data {
public:
- Data()
- {
- }
-
- Data(const Name& name)
- : name_(name)
- {
- }
+ /**
+ * Create a new Data object with default values and where the signature is a blank Sha256WithRsaSignature.
+ */
+ Data();
+
+ /**
+ * Create a new Data object with the given name and default values and where the signature is a blank Sha256WithRsaSignature.
+ * @param name A reference to the name which is copied.
+ */
+ Data(const Name& name);
Blob wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
{
@@ -174,8 +135,8 @@
*/
void set(const struct ndn_Data& dataStruct);
- const Signature& getSignature() const { return signature_; }
- Signature& getSignature() { return signature_; }
+ const Signature* getSignature() const { return signature_.get(); }
+ Signature* getSignature() { return signature_.get(); }
const Name& getName() const { return name_; }
Name& getName() { return name_; }
@@ -185,7 +146,11 @@
const Blob& getContent() const { return content_; }
- void setSignature(const Signature& signature) { signature_ = signature; }
+ /**
+ * Set the signature to a copy of the given signature.
+ * @param signature The signature object which is cloned.
+ */
+ void setSignature(const Signature& signature) { signature_ = signature.clone(); }
void setName(const Name& name) { name_ = name; }
@@ -210,7 +175,7 @@
void setContent(const ptr_lib::shared_ptr<const std::vector<unsigned char> > &content) { content_ = content; }
private:
- Signature signature_;
+ ptr_lib::shared_ptr<Signature> signature_;
Name name_;
MetaInfo metaInfo_;
Blob content_;