In Signature, make digestAlgorithm, witness and signature a Blob.
diff --git a/ndn-cpp/data.cpp b/ndn-cpp/data.cpp
index 387d291..0fb13d6 100644
--- a/ndn-cpp/data.cpp
+++ b/ndn-cpp/data.cpp
@@ -14,19 +14,19 @@
{
signatureStruct.digestAlgorithmLength = digestAlgorithm_.size();
if (digestAlgorithm_.size() > 0)
- signatureStruct.digestAlgorithm = (unsigned char *)&digestAlgorithm_[0];
+ signatureStruct.digestAlgorithm = (unsigned char *)digestAlgorithm_.buf();
else
signatureStruct.digestAlgorithm = 0;
signatureStruct.witnessLength = witness_.size();
if (witness_.size() > 0)
- signatureStruct.witness = (unsigned char *)&witness_[0];
+ signatureStruct.witness = (unsigned char *)witness_.buf();
else
signatureStruct.witness = 0;
signatureStruct.signatureLength = signature_.size();
if (signature_.size() > 0)
- signatureStruct.signature = (unsigned char *)&signature_[0];
+ signatureStruct.signature = (unsigned char *)signature_.buf();
else
signatureStruct.signature = 0;
@@ -36,9 +36,9 @@
void Signature::set(const struct ndn_Signature& signatureStruct)
{
- setVector(digestAlgorithm_, signatureStruct.digestAlgorithm, signatureStruct.digestAlgorithmLength);
- setVector(witness_, signatureStruct.witness, signatureStruct.witnessLength);
- setVector(signature_, signatureStruct.signature, signatureStruct.signatureLength);
+ digestAlgorithm_ = Blob(signatureStruct.digestAlgorithm, signatureStruct.digestAlgorithmLength);
+ witness_ = Blob(signatureStruct.witness, signatureStruct.witnessLength);
+ signature_ = Blob(signatureStruct.signature, signatureStruct.signatureLength);
publisherPublicKeyDigest_.set(signatureStruct.publisherPublicKeyDigest);
keyLocator_.set(signatureStruct.keyLocator);
}
diff --git a/ndn-cpp/data.hpp b/ndn-cpp/data.hpp
index 59eb6a3..ad87674 100644
--- a/ndn-cpp/data.hpp
+++ b/ndn-cpp/data.hpp
@@ -32,14 +32,11 @@
*/
void set(const struct ndn_Signature& signatureStruct);
- const std::vector<unsigned char>& getDigestAlgorithm() const { return digestAlgorithm_; }
- std::vector<unsigned char>& getDigestAlgorithm() { return digestAlgorithm_; }
+ const Blob& getDigestAlgorithm() const { return digestAlgorithm_; }
- const std::vector<unsigned char>& getWitness() const { return witness_; }
- std::vector<unsigned char>& getWitness() { return witness_; }
+ const Blob& getWitness() const { return witness_; }
- const std::vector<unsigned char>& getSignature() const { return signature_; }
- std::vector<unsigned char>& getSignature() { return signature_; }
+ const Blob& getSignature() const { return signature_; }
const PublisherPublicKeyDigest& getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
PublisherPublicKeyDigest& getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
@@ -50,19 +47,19 @@
void setDigestAlgorithm(const std::vector<unsigned char>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; }
void setDigestAlgorithm(const unsigned char *digestAlgorithm, unsigned int digestAlgorithmLength)
{
- setVector(digestAlgorithm_, digestAlgorithm, digestAlgorithmLength);
+ digestAlgorithm_ = Blob(digestAlgorithm, digestAlgorithmLength);
}
void setWitness(const std::vector<unsigned char>& witness) { witness_ = witness; }
void setWitness(const unsigned char *witness, unsigned int witnessLength)
{
- setVector(witness_, witness, witnessLength);
+ witness_ = Blob(witness, witnessLength);
}
void setSignature(const std::vector<unsigned char>& signature) { signature_ = signature; }
void setSignature(const unsigned char *signature, unsigned int signatureLength)
{
- setVector(signature_, signature, signatureLength);
+ signature_ = Blob(signature, signatureLength);
}
void setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; }
@@ -74,17 +71,17 @@
*/
void clear()
{
- digestAlgorithm_.clear();
- witness_.clear();
- signature_.clear();
+ digestAlgorithm_.reset();
+ witness_.reset();
+ signature_.reset();
publisherPublicKeyDigest_.clear();
keyLocator_.clear();
}
private:
- std::vector<unsigned char> digestAlgorithm_; /**< if empty, the default is 2.16.840.1.101.3.4.2.1 (sha-256) */
- std::vector<unsigned char> witness_;
- std::vector<unsigned char> signature_;
+ 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_;
};
diff --git a/ndn-cpp/security/key-chain.cpp b/ndn-cpp/security/key-chain.cpp
index de7399e..5ba46ba 100644
--- a/ndn-cpp/security/key-chain.cpp
+++ b/ndn-cpp/security/key-chain.cpp
@@ -140,7 +140,7 @@
if (!publicKey)
throw std::runtime_error("Error decoding public key in d2i_RSAPublicKey");
int success = RSA_verify
- (NID_sha256, dataFieldsDigest, sizeof(dataFieldsDigest), &data.getSignature().getSignature().front(),
+ (NID_sha256, dataFieldsDigest, sizeof(dataFieldsDigest), (unsigned char *)data.getSignature().getSignature().buf(),
data.getSignature().getSignature().size(), publicKey);
// Free the public key before checking for success.
RSA_free(publicKey);
diff --git a/tests/test-encode-decode-data.cpp b/tests/test-encode-decode-data.cpp
index e8311cf..1e4c165 100644
--- a/tests/test-encode-decode-data.cpp
+++ b/tests/test-encode-decode-data.cpp
@@ -102,11 +102,11 @@
toHex(*data.getMetaInfo().getFinalBlockID().getValue()).c_str() : "<none>") << endl;
cout << "signature.digestAlgorithm: "
- << (data.getSignature().getDigestAlgorithm().size() > 0 ? toHex(data.getSignature().getDigestAlgorithm()).c_str() : "default (sha-256)") << endl;
+ << (data.getSignature().getDigestAlgorithm().size() > 0 ? toHex(*data.getSignature().getDigestAlgorithm()).c_str() : "default (sha-256)") << endl;
cout << "signature.witness: "
- << (data.getSignature().getWitness().size() > 0 ? toHex(data.getSignature().getWitness()).c_str() : "<none>") << endl;
+ << (data.getSignature().getWitness().size() > 0 ? toHex(*data.getSignature().getWitness()).c_str() : "<none>") << endl;
cout << "signature.signature: "
- << (data.getSignature().getSignature().size() > 0 ? toHex(data.getSignature().getSignature()).c_str() : "<none>") << endl;
+ << (data.getSignature().getSignature().size() > 0 ? toHex(*data.getSignature().getSignature()).c_str() : "<none>") << endl;
cout << "signature.publisherPublicKeyDigest: "
<< (data.getSignature().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() > 0 ?
toHex(*data.getSignature().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest()).c_str() : "<none>") << endl;