security: Update Signature abstraction to match 0.1.1 spec
This commit removes intermediate SignatureWithPublicKey data
structure. All uses of such data structure should be replaced with just
Signature and check that KeyLocator is present (hasKeyLocator()).
Change-Id: I1157e05c6a717ea28df91c4bfd76c7145b520a15
Refs: #1750
diff --git a/tests/unit-tests/security/test-digest-sha256.cpp b/tests/unit-tests/security/test-digest-sha256.cpp
index 94ded5b..264078c 100644
--- a/tests/unit-tests/security/test-digest-sha256.cpp
+++ b/tests/unit-tests/security/test-digest-sha256.cpp
@@ -26,26 +26,25 @@
#include "boost-test.hpp"
-using namespace std;
namespace ndn {
BOOST_AUTO_TEST_SUITE(SecurityTestDigestSha256)
-string SHA256_RESULT("a883dafc480d466ee04e0d6da986bd78eb1fdd2178d04693723da3a8f95d42f4");
+std::string SHA256_RESULT("a883dafc480d466ee04e0d6da986bd78eb1fdd2178d04693723da3a8f95d42f4");
-BOOST_AUTO_TEST_CASE (Sha256)
+BOOST_AUTO_TEST_CASE(Sha256)
{
using namespace CryptoPP;
char content[6] = "1234\n";
ConstBufferPtr buf = crypto::sha256(reinterpret_cast<uint8_t*>(content), 5);
- string result;
+ std::string result;
StringSource(buf->buf(), buf->size(), true, new HexEncoder(new StringSink(result), false));
- BOOST_REQUIRE_EQUAL(SHA256_RESULT, result);
+ BOOST_CHECK_EQUAL(SHA256_RESULT, result);
}
-BOOST_AUTO_TEST_CASE (Signature)
+BOOST_AUTO_TEST_CASE(Signature)
{
using namespace CryptoPP;
@@ -63,7 +62,9 @@
DigestSha256 sig(testData.getSignature());
- BOOST_REQUIRE(Validator::verifySignature(testData, sig));
+ BOOST_CHECK(Validator::verifySignature(testData, sig));
+
+ BOOST_CHECK_THROW(sig.getKeyLocator(), ndn::SignatureInfo::Error);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/unit-tests/security/test-signature-sha256-ecdsa.cpp b/tests/unit-tests/security/test-signature-sha256-ecdsa.cpp
index bcf01be..34f25bf 100644
--- a/tests/unit-tests/security/test-signature-sha256-ecdsa.cpp
+++ b/tests/unit-tests/security/test-signature-sha256-ecdsa.cpp
@@ -57,17 +57,18 @@
Block sigValueBlock(sigValue, sizeof(sigValue));
Signature sig(sigInfoBlock, sigValueBlock);
- BOOST_REQUIRE_NO_THROW(SignatureSha256WithEcdsa(sig));
+ BOOST_CHECK_NO_THROW(SignatureSha256WithEcdsa(sig));
+ BOOST_CHECK_NO_THROW(sig.getKeyLocator());
}
BOOST_AUTO_TEST_CASE(Encoding)
{
- SignatureSha256WithEcdsa sig;
-
Name name("/test/key/locator");
KeyLocator keyLocator(name);
- sig.setKeyLocator(keyLocator);
+ SignatureSha256WithEcdsa sig(keyLocator);
+
+ BOOST_CHECK_NO_THROW(sig.getKeyLocator());
const Block& encodeSigInfoBlock = sig.getInfo();
diff --git a/tests/unit-tests/security/test-signature-sha256-rsa.cpp b/tests/unit-tests/security/test-signature-sha256-rsa.cpp
index e1ea73c..cd717d7 100644
--- a/tests/unit-tests/security/test-signature-sha256-rsa.cpp
+++ b/tests/unit-tests/security/test-signature-sha256-rsa.cpp
@@ -62,17 +62,18 @@
Block sigValueBlock(sigValue, sizeof(sigValue));
Signature sig(sigInfoBlock, sigValueBlock);
- BOOST_REQUIRE_NO_THROW(SignatureSha256WithRsa(sig));
+ BOOST_CHECK_NO_THROW(SignatureSha256WithRsa(sig));
+ BOOST_CHECK_NO_THROW(sig.getKeyLocator());
}
BOOST_AUTO_TEST_CASE(Encoding)
{
- SignatureSha256WithRsa sig;
-
Name name("/test/key/locator");
KeyLocator keyLocator(name);
- sig.setKeyLocator(keyLocator);
+ SignatureSha256WithRsa sig(keyLocator);
+
+ BOOST_CHECK_NO_THROW(sig.getKeyLocator());
const Block& encodeSigInfoBlock = sig.getInfo();