encoding: convert to span
Change-Id: I8bd73284fbd5acc0ff8ad2626af9b4324e9df7a1
diff --git a/tests/unit/data.t.cpp b/tests/unit/data.t.cpp
index 2ab660e..153c471 100644
--- a/tests/unit/data.t.cpp
+++ b/tests/unit/data.t.cpp
@@ -284,7 +284,7 @@
BOOST_AUTO_TEST_CASE(Full)
{
- d.wireDecode(Block(DATA1, sizeof(DATA1)));
+ d.wireDecode(Block(DATA1));
BOOST_CHECK_EQUAL(d.getName(), "/local/ndn/prefix");
BOOST_CHECK_EQUAL(d.getContentType(), tlv::ContentType_Blob);
BOOST_CHECK_EQUAL(d.getFreshnessPeriod(), 10_s);
@@ -415,7 +415,7 @@
d.setFreshnessPeriod(100_s); // invalidates FullName
BOOST_CHECK_THROW(d.getFullName(), Data::Error);
- Data d1(Block(DATA1, sizeof(DATA1)));
+ Data d1(Block{DATA1});
BOOST_CHECK_EQUAL(d1.getFullName(),
"/local/ndn/prefix/"
"sha256digest=28bad4b5275bd392dbb670c75cf0b66f13f7942b21e80f55c0e86b374753a548");
@@ -518,7 +518,7 @@
// Block overload, nested inside Content element
const uint8_t nested[] = {0x99, 0x02, 0xca, 0xfe};
- d.setContent(Block(nested, sizeof(nested)));
+ d.setContent(Block(nested));
BOOST_CHECK_EQUAL(d.hasContent(), true);
BOOST_CHECK_EQUAL(d.getContent().type(), tlv::Content);
BOOST_CHECK_EQUAL_COLLECTIONS(d.getContent().value_begin(), d.getContent().value_end(),
@@ -597,8 +597,7 @@
0x17, 0x00, // SignatureValue
0xAA, 0x00 // Unrecognized non-critical element
};
- Block wire2(WIRE, sizeof(WIRE));
- Data d2(wire2);
+ Data d2(Block{WIRE});
auto ranges2 = d2.extractSignedRanges();
BOOST_REQUIRE_EQUAL(ranges2.size(), 1);
BOOST_CHECK_EQUAL_COLLECTIONS(ranges2.front().begin(), ranges2.front().end(), &WIRE[2], &WIRE[9]);
@@ -651,7 +650,7 @@
BOOST_AUTO_TEST_CASE(Print)
{
- Data d1(Block(DATA1, sizeof(DATA1)));
+ Data d1(Block{DATA1});
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(d1),
"Name: /local/ndn/prefix\n"
"MetaInfo: [ContentType: 0, FreshnessPeriod: 10000 milliseconds]\n"
diff --git a/tests/unit/encoding/block-helpers.t.cpp b/tests/unit/encoding/block-helpers.t.cpp
index 2ca1e02..9325851 100644
--- a/tests/unit/encoding/block-helpers.t.cpp
+++ b/tests/unit/encoding/block-helpers.t.cpp
@@ -108,18 +108,43 @@
std::list<uint8_t> buf3{1, 1, 1, 1};
Block b1 = makeBinaryBlock(100, buf1.data(), buf1.size()); // char* overload
- Block b2 = makeBinaryBlock(100, buf2, sizeof(buf2)); // uint8_t* overload
- Block b3 = makeBinaryBlock(100, buf2); // span overload
- Block b4 = makeBinaryBlock(100, buf1.begin(), buf1.end()); // fast encoding (random access iterator)
- Block b5 = makeBinaryBlock(100, buf3.begin(), buf3.end()); // slow encoding (general iterator)
+ Block b2 = makeBinaryBlock(100, buf2); // span overload
+ Block b3 = makeBinaryBlock(100, buf1.begin(), buf1.end()); // fast encoding (random access iterator)
+ Block b4 = makeBinaryBlock(100, buf3.begin(), buf3.end()); // slow encoding (general iterator)
BOOST_CHECK_EQUAL(b1, b2);
BOOST_CHECK_EQUAL(b1, b3);
BOOST_CHECK_EQUAL(b1, b4);
- BOOST_CHECK_EQUAL(b1, b5);
BOOST_CHECK_EQUAL(b1.type(), 100);
BOOST_CHECK_EQUAL(b1.value_size(), buf1.size());
BOOST_CHECK_EQUAL_COLLECTIONS(b1.value_begin(), b1.value_end(), buf2, buf2 + sizeof(buf2));
+
+ EncodingEstimator estimator;
+ size_t length = prependBinaryBlock(estimator, 100, buf2);
+ BOOST_CHECK_EQUAL(length, 6);
+
+ EncodingBuffer encoder(length, 0);
+ BOOST_CHECK_EQUAL(prependBinaryBlock(encoder, 100, buf2), 6);
+ BOOST_CHECK_EQUAL(encoder.block(), b1);
+}
+
+BOOST_AUTO_TEST_CASE(PrependBlock)
+{
+ EncodingEstimator estimator;
+ Block b1({0x01, 0x03, 0x00, 0x00, 0x00});
+ size_t length = prependBlock(estimator, b1);
+ BOOST_CHECK_EQUAL(length, 5);
+ Block b2(100, b1);
+ length += prependBlock(estimator, b2);
+ BOOST_CHECK_EQUAL(length, 12);
+
+ EncodingBuffer encoder(length, 0);
+ BOOST_CHECK_EQUAL(prependBlock(encoder, b1), 5);
+ BOOST_CHECK_EQUAL(prependBlock(encoder, b2), 7);
+ BOOST_CHECK_EQUAL(encoder.size(), 12);
+ encoder.prependVarNumber(encoder.size());
+ encoder.prependVarNumber(200);
+ BOOST_CHECK_EQUAL(encoder.block(), "C80C 64050103000000 0103000000"_block);
}
BOOST_AUTO_TEST_CASE(Nested)
diff --git a/tests/unit/encoding/block.t.cpp b/tests/unit/encoding/block.t.cpp
index b6a841b..a39df87 100644
--- a/tests/unit/encoding/block.t.cpp
+++ b/tests/unit/encoding/block.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -68,7 +68,7 @@
BOOST_CHECK_THROW(Block{encoder}, tlv::Error);
const uint8_t VALUE[] = {0x11, 0x12, 0x13, 0x14};
- size_t length = encoder.prependByteArray(VALUE, sizeof(VALUE));
+ size_t length = encoder.prependBytes(VALUE);
encoder.prependVarNumber(length);
encoder.prependVarNumber(0xe0);
@@ -87,18 +87,18 @@
BOOST_AUTO_TEST_CASE(FromBlock)
{
- const uint8_t BUFFER[] = {0x80, 0x06, 0x81, 0x01, 0x01, 0x82, 0x01, 0x01};
- Block block(BUFFER, sizeof(BUFFER));
+ const uint8_t buf[] = {0x80, 0x06, 0x81, 0x01, 0x01, 0x82, 0x01, 0x01};
+ Block block(buf);
Block derivedBlock(block, block.begin(), block.end());
BOOST_CHECK_EQUAL(derivedBlock.wire(), block.wire()); // pointers should match
- BOOST_CHECK(derivedBlock == block); // blocks should match
+ BOOST_CHECK_EQUAL(derivedBlock, block); // blocks should match
derivedBlock = Block(block, block.begin() + 2, block.begin() + 5);
BOOST_CHECK(derivedBlock.begin() == block.begin() + 2);
- BOOST_CHECK(derivedBlock == Block(BUFFER + 2, 3));
+ BOOST_CHECK_EQUAL(derivedBlock, Block(make_span(buf + 2, 3)));
- Buffer otherBuffer(BUFFER, sizeof(BUFFER));
+ Buffer otherBuffer(buf, sizeof(buf));
BOOST_CHECK_THROW(Block(block, otherBuffer.begin(), block.end()), std::invalid_argument);
BOOST_CHECK_THROW(Block(block, block.begin(), otherBuffer.end()), std::invalid_argument);
BOOST_CHECK_THROW(Block(block, otherBuffer.begin(), otherBuffer.end()), std::invalid_argument);
@@ -106,11 +106,11 @@
BOOST_AUTO_TEST_CASE(FromBlockCopyOnWriteModifyOriginal)
{
- const uint8_t BUFFER[] = {
+ const uint8_t buf[] = {
0x05, 0x0b, 0x07, 0x03, 0x01, 0x02, 0x03, 0x0a, 0x04, 0x04, 0x05, 0x06, 0x07,
};
- Block b1(BUFFER, sizeof(BUFFER));
+ Block b1(buf);
Block b2(b1, b1.begin(), b1.end());
auto buf2 = b2.getBuffer();
@@ -121,17 +121,17 @@
b2.parse();
- BOOST_CHECK_EQUAL_COLLECTIONS(b2.begin(), b2.end(), BUFFER, BUFFER + sizeof(BUFFER));
+ BOOST_CHECK_EQUAL_COLLECTIONS(b2.begin(), b2.end(), buf, buf + sizeof(buf));
BOOST_CHECK_EQUAL(buf2, b2.getBuffer());
}
BOOST_AUTO_TEST_CASE(FromBlockCopyOnWriteModifyCopy)
{
- const uint8_t BUFFER[] = {
+ const uint8_t buf[] = {
0x05, 0x0b, 0x07, 0x03, 0x01, 0x02, 0x03, 0x0a, 0x04, 0x04, 0x05, 0x06, 0x07,
};
- Block b1(BUFFER, sizeof(BUFFER));
+ Block b1(buf);
auto buf1 = b1.getBuffer();
Block b2(b1, b1.begin(), b1.end());
@@ -141,7 +141,7 @@
b2.encode();
b1.parse();
- BOOST_CHECK_EQUAL_COLLECTIONS(b1.begin(), b1.end(), BUFFER, BUFFER + sizeof(BUFFER));
+ BOOST_CHECK_EQUAL_COLLECTIONS(b1.begin(), b1.end(), buf, buf + sizeof(buf));
BOOST_CHECK_EQUAL(buf1, b1.getBuffer());
}
@@ -177,7 +177,7 @@
BOOST_AUTO_TEST_CASE(FromTypeAndBuffer)
{
const uint8_t VALUE[] = {0x11, 0x12, 0x13, 0x14};
- auto bufferPtr = make_shared<Buffer>(VALUE, sizeof(VALUE));
+ auto bufferPtr = std::make_shared<Buffer>(VALUE, sizeof(VALUE));
Block b1(42, std::move(bufferPtr));
BOOST_CHECK_EQUAL(b1.isValid(), true);
@@ -188,7 +188,7 @@
BOOST_CHECK(b1.value() != nullptr);
// empty buffer as TLV-VALUE
- Block b2(63, make_shared<Buffer>());
+ Block b2(63, std::make_shared<Buffer>());
BOOST_CHECK_EQUAL(b2.isValid(), true);
BOOST_CHECK_EQUAL(b2.type(), 63);
BOOST_CHECK_EQUAL(b2.size(), 2);
@@ -199,15 +199,15 @@
BOOST_AUTO_TEST_CASE(FromTypeAndBlock)
{
- const uint8_t BUFFER[] = {0x80, 0x06, 0x81, 0x01, 0x01, 0x82, 0x01, 0x01};
- Block nested(BUFFER, sizeof(BUFFER));
+ const uint8_t buf[] = {0x80, 0x06, 0x81, 0x01, 0x01, 0x82, 0x01, 0x01};
+ Block nested(buf);
Block b(84, nested);
BOOST_CHECK_EQUAL(b.isValid(), true);
BOOST_CHECK_EQUAL(b.type(), 84);
BOOST_CHECK_EQUAL(b.size(), 10);
BOOST_CHECK_EQUAL(b.hasValue(), true);
- BOOST_CHECK_EQUAL(b.value_size(), sizeof(BUFFER));
+ BOOST_CHECK_EQUAL(b.value_size(), sizeof(buf));
BOOST_CHECK(b.value() != nullptr);
}
@@ -322,19 +322,18 @@
BOOST_AUTO_TEST_CASE(FromWireBuffer)
{
- auto buffer = make_shared<Buffer>(TEST_BUFFER, sizeof(TEST_BUFFER));
+ auto buffer = std::make_shared<Buffer>(TEST_BUFFER, sizeof(TEST_BUFFER));
- size_t offset = 0;
bool isOk = false;
Block b;
- std::tie(isOk, b) = Block::fromBuffer(buffer, offset);
+ std::tie(isOk, b) = Block::fromBuffer(buffer);
BOOST_CHECK(isOk);
BOOST_CHECK_EQUAL(b.type(), 66);
BOOST_CHECK_EQUAL(b.size(), 3);
BOOST_CHECK_EQUAL(b.value_size(), 1);
BOOST_CHECK_EQUAL(*b.wire(), 0x42);
BOOST_CHECK_EQUAL(*b.value(), 0xfa);
- offset += b.size();
+ size_t offset = b.size();
std::tie(isOk, b) = Block::fromBuffer(buffer, offset);
BOOST_CHECK(isOk);
@@ -356,19 +355,18 @@
BOOST_AUTO_TEST_CASE(FromRawBuffer)
{
- size_t offset = 0;
bool isOk = false;
Block b;
- std::tie(isOk, b) = Block::fromBuffer(TEST_BUFFER + offset, sizeof(TEST_BUFFER) - offset);
+ std::tie(isOk, b) = Block::fromBuffer(TEST_BUFFER);
BOOST_CHECK(isOk);
BOOST_CHECK_EQUAL(b.type(), 66);
BOOST_CHECK_EQUAL(b.size(), 3);
BOOST_CHECK_EQUAL(b.value_size(), 1);
BOOST_CHECK_EQUAL(*b.wire(), 0x42);
BOOST_CHECK_EQUAL(*b.value(), 0xfa);
- offset += b.size();
+ auto offset = b.size();
- std::tie(isOk, b) = Block::fromBuffer(TEST_BUFFER + offset, sizeof(TEST_BUFFER) - offset);
+ std::tie(isOk, b) = Block::fromBuffer(make_span(TEST_BUFFER).subspan(offset));
BOOST_CHECK(isOk);
BOOST_CHECK_EQUAL(b.type(), 1);
BOOST_CHECK_EQUAL(b.size(), 3);
@@ -377,7 +375,7 @@
BOOST_CHECK_EQUAL(*b.value(), 0xfb);
offset += b.size();
- std::tie(isOk, b) = Block::fromBuffer(TEST_BUFFER + offset, sizeof(TEST_BUFFER) - offset);
+ std::tie(isOk, b) = Block::fromBuffer(make_span(TEST_BUFFER).subspan(offset));
BOOST_CHECK(isOk);
BOOST_CHECK_EQUAL(b.type(), 0xffffffff);
BOOST_CHECK_EQUAL(b.size(), 6);
@@ -395,8 +393,8 @@
BOOST_DATA_TEST_CASE(Malformed, MalformedInputs)
{
- // constructor from raw buffer
- BOOST_CHECK_THROW(Block(sample.data(), sample.size()), tlv::Error);
+ // constructor from span
+ BOOST_CHECK_THROW(Block{sample}, tlv::Error);
// fromStream()
std::stringstream stream;
@@ -405,15 +403,15 @@
BOOST_CHECK_THROW(Block::fromStream(stream), tlv::Error);
// fromBuffer(), ConstBufferPtr overload
- auto buf = make_shared<Buffer>(sample.begin(), sample.end());
+ auto buf = std::make_shared<Buffer>(sample.begin(), sample.end());
bool isOk;
Block b;
- std::tie(isOk, b) = Block::fromBuffer(buf, 0);
+ std::tie(isOk, b) = Block::fromBuffer(buf);
BOOST_CHECK(!isOk);
BOOST_CHECK(!b.isValid());
- // fromBuffer(), raw buffer overload
- std::tie(isOk, b) = Block::fromBuffer(sample.data(), sample.size());
+ // fromBuffer(), span overload
+ std::tie(isOk, b) = Block::fromBuffer(sample);
BOOST_CHECK(!isOk);
BOOST_CHECK(!b.isValid());
}
@@ -427,7 +425,7 @@
return e.what() == "Cannot construct block from empty TLV-VALUE"s;
});
- Block b2(302, make_shared<Buffer>());
+ Block b2(302, std::make_shared<Buffer>());
BOOST_CHECK_EXCEPTION(b2.blockFromValue(), Block::Error, [] (const auto& e) {
return e.what() == "Cannot construct block from empty TLV-VALUE"s;
});
@@ -459,7 +457,7 @@
0x1c, 0x00, // KeyLocator empty
0x17, 0x00 // SignatureValue empty
};
- Block data(PACKET, sizeof(PACKET));
+ Block data(PACKET);
data.parse();
BOOST_CHECK_EQUAL(data.elements_size(), 5);
@@ -478,7 +476,7 @@
// TLV-LENGTH of nested element is greater than TLV-LENGTH of enclosing element
0x05, 0x05, 0x07, 0x07, 0x08, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f
};
- Block bad(MALFORMED, sizeof(MALFORMED));
+ Block bad(MALFORMED);
BOOST_CHECK_EXCEPTION(bad.parse(), Block::Error, [] (const auto& e) {
return e.what() == "TLV-LENGTH of sub-element of type 7 exceeds TLV-VALUE boundary of parent block"s;
});
@@ -634,20 +632,20 @@
BOOST_AUTO_TEST_CASE(Equality)
{
const uint8_t one[] = {0x08, 0x00};
- Block a(one, sizeof(one));
- Block b(one, sizeof(one));
+ Block a(one);
+ Block b(one);
BOOST_CHECK_EQUAL(a == b, true);
BOOST_CHECK_EQUAL(a != b, false);
const uint8_t two[] = {0x06, 0x00};
- Block c(two, sizeof(two));
- Block d(one, sizeof(one));
+ Block c(two);
+ Block d(one);
BOOST_CHECK_EQUAL(c == d, false);
BOOST_CHECK_EQUAL(c != d, true);
const uint8_t three[] = {0x06, 0x01, 0xcc};
- Block e(two, sizeof(two));
- Block f(three, sizeof(three));
+ Block e(two);
+ Block f(three);
BOOST_CHECK_EQUAL(e == f, false);
BOOST_CHECK_EQUAL(e != f, true);
}
diff --git a/tests/unit/encoding/encoder.t.cpp b/tests/unit/encoding/encoder.t.cpp
index 3f5fe8e..57a1f3d 100644
--- a/tests/unit/encoding/encoder.t.cpp
+++ b/tests/unit/encoding/encoder.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -41,14 +41,16 @@
Encoder e2(100, 100);
BOOST_CHECK_EQUAL(e2.capacity(), 100);
- BOOST_CHECK_EQUAL(e.prependByte(1), 1);
- BOOST_CHECK_EQUAL(e.appendByte(1), 1);
+ BOOST_CHECK_EQUAL(e.prependBytes({1}), 1);
+ BOOST_CHECK_EQUAL(e.appendBytes({1}), 1);
- uint8_t buf1[] = {'t', 'e', 's', 't', '1'};
- BOOST_CHECK_EQUAL(e1.prependByteArray(buf1, sizeof(buf1)), 5);
- BOOST_CHECK_EQUAL(e1.appendByteArray(buf1, sizeof(buf1)), 5);
+ const uint8_t buf1[] = {'t', 'e', 's', 't', '1'};
+ BOOST_CHECK_EQUAL(e1.prependBytes(buf1), 5);
+ BOOST_CHECK_EQUAL(e1.appendBytes(buf1), 5);
std::vector<uint8_t> buf2 = {'t', 'e', 's', 't', '2'};
+ BOOST_CHECK_EQUAL(e2.prependBytes(buf2), 5);
+ BOOST_CHECK_EQUAL(e2.appendBytes(buf2), 5);
BOOST_CHECK_EQUAL(e1.prependRange(buf2.begin(), buf2.end()), 5);
BOOST_CHECK_EQUAL(e1.appendRange(buf2.begin(), buf2.end()), 5);
@@ -56,17 +58,16 @@
BOOST_CHECK_EQUAL(e2.prependRange(buf3.begin(), buf3.end()), 5);
BOOST_CHECK_EQUAL(e2.appendRange(buf3.begin(), buf3.end()), 5);
- uint8_t expected1[] = {1, 1};
- BOOST_CHECK_EQUAL_COLLECTIONS(e.buf(), e.buf() + e.size(),
+ const uint8_t expected1[] = {1, 1};
+ BOOST_CHECK_EQUAL_COLLECTIONS(e.data(), e.data() + e.size(),
expected1, expected1 + sizeof(expected1));
const Encoder& constE = e;
- BOOST_CHECK_EQUAL_COLLECTIONS(constE.buf(), constE.buf() + constE.size(),
+ BOOST_CHECK_EQUAL_COLLECTIONS(constE.data(), constE.data() + constE.size(),
expected1, expected1 + sizeof(expected1));
- uint8_t expected2[] = {'t', 'e', 's', 't', '2',
- 't', 'e', 's', 't', '1', 't', 'e', 's', 't', '1',
- 't', 'e', 's', 't', '2'};
+ const uint8_t expected2[] = {'t', 'e', 's', 't', '2', 't', 'e', 's', 't', '1',
+ 't', 'e', 's', 't', '1', 't', 'e', 's', 't', '2'};
BOOST_CHECK_EQUAL_COLLECTIONS(e1.begin(), e1.end(),
expected2, expected2 + sizeof(expected2));
const Encoder& constE1 = e1;
@@ -129,19 +130,16 @@
//
- uint8_t buf[] = {0x01, 0x03, 0x00, 0x00, 0x00};
- Block block1(buf, sizeof(buf));
-
- BOOST_CHECK_EQUAL(e.prependByteArrayBlock(100, buf, sizeof(buf)), 7);
- BOOST_CHECK_EQUAL(e.appendByteArrayBlock(100, buf, sizeof(buf)), 7);
-
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+ Block block1({0x01, 0x03, 0x00, 0x00, 0x00});
BOOST_CHECK_EQUAL(e.prependBlock(block1), 5);
BOOST_CHECK_EQUAL(e.appendBlock(block1), 5);
Block block2(100, block1);
-
BOOST_CHECK_EQUAL(e.prependBlock(block2), 7);
BOOST_CHECK_EQUAL(e.appendBlock(block2), 7);
+#pragma GCC diagnostic pop
}
BOOST_AUTO_TEST_CASE(Reserve)
diff --git a/tests/unit/encoding/estimator.t.cpp b/tests/unit/encoding/estimator.t.cpp
index f5e4392..d4ecbaf 100644
--- a/tests/unit/encoding/estimator.t.cpp
+++ b/tests/unit/encoding/estimator.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -34,14 +34,16 @@
{
Estimator e;
- BOOST_CHECK_EQUAL(e.prependByte(1), 1);
- BOOST_CHECK_EQUAL(e.appendByte(1), 1);
+ BOOST_CHECK_EQUAL(e.prependBytes({1}), 1);
+ BOOST_CHECK_EQUAL(e.appendBytes({1}), 1);
- uint8_t buf1[] = {'t', 'e', 's', 't', '1'};
- BOOST_CHECK_EQUAL(e.prependByteArray(buf1, sizeof(buf1)), 5);
- BOOST_CHECK_EQUAL(e.appendByteArray(buf1, sizeof(buf1)), 5);
+ const uint8_t buf1[] = {'t', 'e', 's', 't', '1'};
+ BOOST_CHECK_EQUAL(e.prependBytes(buf1), 5);
+ BOOST_CHECK_EQUAL(e.appendBytes(buf1), 5);
std::vector<uint8_t> buf2 = {'t', 'e', 's', 't', '2'};
+ BOOST_CHECK_EQUAL(e.prependBytes(buf2), 5);
+ BOOST_CHECK_EQUAL(e.appendBytes(buf2), 5);
BOOST_CHECK_EQUAL(e.prependRange(buf2.begin(), buf2.end()), 5);
BOOST_CHECK_EQUAL(e.appendRange(buf2.begin(), buf2.end()), 5);
@@ -97,19 +99,16 @@
//
- uint8_t buf[] = {0x01, 0x03, 0x00, 0x00, 0x00};
- Block block1(buf, sizeof(buf));
-
- BOOST_CHECK_EQUAL(e.prependByteArrayBlock(100, buf, sizeof(buf)), 7);
- BOOST_CHECK_EQUAL(e.appendByteArrayBlock(100, buf, sizeof(buf)), 7);
-
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+ Block block1({0x01, 0x03, 0x00, 0x00, 0x00});
BOOST_CHECK_EQUAL(e.prependBlock(block1), 5);
BOOST_CHECK_EQUAL(e.appendBlock(block1), 5);
Block block2(100, block1);
-
BOOST_CHECK_EQUAL(e.prependBlock(block2), 7);
BOOST_CHECK_EQUAL(e.appendBlock(block2), 7);
+#pragma GCC diagnostic pop
}
BOOST_AUTO_TEST_SUITE_END() // TestEstimator
diff --git a/tests/unit/interest.t.cpp b/tests/unit/interest.t.cpp
index d36e0a9..ff50e8a 100644
--- a/tests/unit/interest.t.cpp
+++ b/tests/unit/interest.t.cpp
@@ -241,7 +241,7 @@
si.setNonce(nonce);
Block sv("2E20 12471AE0F8723AC1156C370A38711EBEBF2817DE9B2DD94E9B7E62F117B876C1"_block);
- Interest i1(Block(WIRE, sizeof(WIRE)));
+ Interest i1(Block{WIRE});
BOOST_CHECK_EQUAL(i1.getName(),
"/local/ndn/prefix/params-sha256=6f29586053ee9fccd8a422122925287c0a18435f4074c40abb0d5b30e4aa6220");
BOOST_CHECK_EQUAL(i1.getCanBePrefix(), false);
@@ -319,7 +319,7 @@
si.setNonce(nonce);
Block sv("2E20 12471AE0F8723AC1156C370A38711EBEBF2817DE9B2DD94E9B7E62F117B876C1"_block);
- Interest i1(Block(WIRE, sizeof(WIRE)));
+ Interest i1(Block{WIRE});
BOOST_CHECK_EQUAL(i1.getName(),
"/local/ndn/prefix/params-sha256=bc3630a4d65e0db5483dfa0d28b3312fcac1d441ec8961d4175e61751778108e");
BOOST_CHECK_EQUAL(i1.getCanBePrefix(), false);
@@ -1125,7 +1125,7 @@
0xbf, 0x28, 0x17, 0xde, 0x9b, 0x2d, 0xd9, 0x4e,
0x9b, 0x7e, 0x62, 0xf1, 0x17, 0xb8, 0x76, 0xc1,
};
- Block wire3(WIRE, sizeof(WIRE));
+ Block wire3(WIRE);
Interest i2(wire3);
auto ranges3 = i2.extractSignedRanges();
BOOST_REQUIRE_EQUAL(ranges3.size(), 2);
diff --git a/tests/unit/link.t.cpp b/tests/unit/link.t.cpp
index 2d7fa9c..fe4b45c 100644
--- a/tests/unit/link.t.cpp
+++ b/tests/unit/link.t.cpp
@@ -77,7 +77,7 @@
BOOST_AUTO_TEST_CASE(Decode)
{
- Link link(Block(GOOD_LINK, sizeof(GOOD_LINK)));
+ Link link(Block{GOOD_LINK});
BOOST_CHECK_EQUAL(link.getName(), Name("/local/ndn/prefix"));
BOOST_TEST(link.getDelegationList() == std::vector<Name>({"/local", "/ndn"}),
boost::test_tools::per_element());
@@ -85,11 +85,11 @@
BOOST_AUTO_TEST_CASE(DecodeBadContentType)
{
- Data linkData(Block(GOOD_LINK, sizeof(GOOD_LINK)));
+ Data linkData(Block{GOOD_LINK});
linkData.setContentType(tlv::ContentType_Key);
Block badLink = linkData.wireEncode();
- BOOST_CHECK_THROW((Link(badLink)), Link::Error);
+ BOOST_CHECK_THROW(Link{badLink}, Link::Error);
Link link;
BOOST_CHECK_THROW(link.wireDecode(badLink), Link::Error);
}
diff --git a/tests/unit/lp/cache-policy.t.cpp b/tests/unit/lp/cache-policy.t.cpp
index 78c1548..8b27a6c 100644
--- a/tests/unit/lp/cache-policy.t.cpp
+++ b/tests/unit/lp/cache-policy.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -38,10 +38,10 @@
policy.setPolicy(CachePolicyType::NO_CACHE);
Block wire;
- BOOST_REQUIRE_NO_THROW(wire = policy.wireEncode());
+ BOOST_CHECK_NO_THROW(wire = policy.wireEncode());
// Sample encoded value obtained with:
- // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+ // for (auto it = wire.begin(); it != wire.end(); ++it) {
// printf("0x%02x, ", *it);
// }
@@ -53,40 +53,31 @@
BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
wire.begin(), wire.end());
- BOOST_REQUIRE_NO_THROW(policy.wireDecode(wire));
+ BOOST_CHECK_NO_THROW(policy.wireDecode(wire));
}
BOOST_AUTO_TEST_CASE(DecodeUnknownPolicyError)
{
- static const uint8_t expectedBlock[] = {
- 0xfd, 0x03, 0x34, 0x08, 0xfd, 0x03, 0x35, 0x04, 0xff, 0xff, 0xff, 0xff
- };
+ const Block wire({0xfd, 0x03, 0x34, 0x08, 0xfd, 0x03, 0x35, 0x04, 0x1f, 0xff, 0xff, 0xff});
CachePolicy policy;
- Block wire(expectedBlock, sizeof(expectedBlock));
- BOOST_REQUIRE_THROW(policy.wireDecode(wire), CachePolicy::Error);
+ BOOST_CHECK_THROW(policy.wireDecode(wire), CachePolicy::Error);
}
BOOST_AUTO_TEST_CASE(DecodeMissingPolicyError)
{
- static const uint8_t inputBlock[] = {
- 0xfd, 0x03, 0x34, 0x00
- };
+ const Block wire({0xfd, 0x03, 0x34, 0x00});
CachePolicy policy;
- Block wire(inputBlock, sizeof(inputBlock));
- BOOST_REQUIRE_THROW(policy.wireDecode(wire), CachePolicy::Error);
+ BOOST_CHECK_THROW(policy.wireDecode(wire), CachePolicy::Error);
}
BOOST_AUTO_TEST_CASE(DecodeInvalidPolicyError)
{
- static const uint8_t inputBlock[] = {
- 0xfd, 0x03, 0x34, 0x05, 0xfd, 0x03, 0x35, 0x01, 0x00
- };
+ const Block wire({0xfd, 0x03, 0x34, 0x05, 0xfd, 0x03, 0x35, 0x01, 0x00});
CachePolicy policy;
- Block wire(inputBlock, sizeof(inputBlock));
- BOOST_REQUIRE_THROW(policy.wireDecode(wire), CachePolicy::Error);
+ BOOST_CHECK_THROW(policy.wireDecode(wire), CachePolicy::Error);
}
BOOST_AUTO_TEST_CASE(Policy)
diff --git a/tests/unit/lp/nack-header.t.cpp b/tests/unit/lp/nack-header.t.cpp
index 4670608..c914eb0 100644
--- a/tests/unit/lp/nack-header.t.cpp
+++ b/tests/unit/lp/nack-header.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -50,10 +50,10 @@
header.setReason(NackReason::DUPLICATE);
Block wire;
- BOOST_REQUIRE_NO_THROW(wire = header.wireEncode());
+ BOOST_CHECK_NO_THROW(wire = header.wireEncode());
// Sample encoded value obtained with:
- // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+ // for (auto it = wire.begin(); it != wire.end(); ++it) {
// printf("0x%02x, ", *it);
// }
@@ -65,20 +65,20 @@
BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
wire.begin(), wire.end());
- BOOST_REQUIRE_NO_THROW(header.wireDecode(wire));
+ BOOST_CHECK_NO_THROW(header.wireDecode(wire));
}
BOOST_AUTO_TEST_CASE(DecodeUnknownReasonCode)
{
static const uint8_t expectedBlock[] = {
- 0xfd, 0x03, 0x20, 0x08, 0xfd, 0x03, 0x21, 0x04, 0xff, 0xff, 0xff, 0xff,
+ 0xfd, 0x03, 0x20, 0x08, 0xfd, 0x03, 0x21, 0x04, 0x1f, 0xff, 0xff, 0xff,
};
NackHeader header;
- Block wire(expectedBlock, sizeof(expectedBlock));
- BOOST_REQUIRE_NO_THROW(header.wireDecode(wire));
+ Block wire(expectedBlock);
+ BOOST_CHECK_NO_THROW(header.wireDecode(wire));
Block wireEncoded;
- BOOST_REQUIRE_NO_THROW(wireEncoded = header.wireEncode());
+ BOOST_CHECK_NO_THROW(wireEncoded = header.wireEncode());
BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
wireEncoded.begin(), wireEncoded.end());
BOOST_CHECK_EQUAL(header.getReason(), NackReason::NONE);
@@ -91,10 +91,10 @@
};
NackHeader header;
- Block wire(expectedBlock, sizeof(expectedBlock));
- BOOST_REQUIRE_NO_THROW(header.wireDecode(wire));
+ Block wire(expectedBlock);
+ BOOST_CHECK_NO_THROW(header.wireDecode(wire));
Block wireEncoded;
- BOOST_REQUIRE_NO_THROW(wireEncoded = header.wireEncode());
+ BOOST_CHECK_NO_THROW(wireEncoded = header.wireEncode());
BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
wireEncoded.begin(), wireEncoded.end());
BOOST_CHECK_EQUAL(header.getReason(), NackReason::NONE);
diff --git a/tests/unit/lp/packet.t.cpp b/tests/unit/lp/packet.t.cpp
index 5f750c3..7763f06 100644
--- a/tests/unit/lp/packet.t.cpp
+++ b/tests/unit/lp/packet.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -197,7 +197,7 @@
};
Packet packet;
- Block wire(inputBlock, sizeof(inputBlock));
+ Block wire(inputBlock);
packet.wireDecode(wire);
BOOST_CHECK_EQUAL(packet.count<FragIndexField>(), 1);
@@ -231,7 +231,7 @@
};
Packet packet;
- Block wire(inputBlock, sizeof(inputBlock));
+ Block wire(inputBlock);
packet.wireDecode(wire);
BOOST_CHECK_EQUAL(0, packet.count<FragmentField>());
BOOST_CHECK_EQUAL(1, packet.count<FragIndexField>());
@@ -249,7 +249,7 @@
};
Packet packet;
- Block wire(inputBlock, sizeof(inputBlock));
+ Block wire(inputBlock);
packet.wireDecode(wire);
BOOST_CHECK_EQUAL(1, packet.count<FragmentField>());
BOOST_CHECK_EQUAL(0, packet.count<FragIndexField>());
@@ -268,7 +268,7 @@
};
Packet packet;
- Block wire(inputBlock, sizeof(inputBlock));
+ Block wire(inputBlock);
packet.wireDecode(wire);
BOOST_CHECK_EQUAL(true, packet.has<NonDiscoveryField>());
packet.get<NonDiscoveryField>();
@@ -281,7 +281,7 @@
};
Packet packet;
- Block wire(inputBlock, sizeof(inputBlock));
+ Block wire(inputBlock);
packet.wireDecode(wire);
BOOST_CHECK_EQUAL(0, packet.count<FragmentField>());
BOOST_CHECK_EQUAL(0, packet.count<FragIndexField>());
@@ -299,7 +299,7 @@
};
Packet packet;
- Block wire(inputBlock, sizeof(inputBlock));
+ Block wire(inputBlock);
BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
}
@@ -314,7 +314,7 @@
};
Packet packet;
- Block wire(inputBlock, sizeof(inputBlock));
+ Block wire(inputBlock);
BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
}
@@ -331,7 +331,7 @@
};
Packet packet;
- Block wire(inputBlock, sizeof(inputBlock));
+ Block wire(inputBlock);
BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
}
@@ -348,7 +348,7 @@
};
Packet packet;
- Block wire(inputBlock, sizeof(inputBlock));
+ Block wire(inputBlock);
BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
}
@@ -365,7 +365,7 @@
};
Packet packet;
- Block wire(inputBlock, sizeof(inputBlock));
+ Block wire(inputBlock);
packet.wireDecode(wire);
BOOST_CHECK_EQUAL(1, packet.count<FragmentField>());
BOOST_CHECK_EQUAL(1, packet.count<FragIndexField>());
@@ -384,7 +384,7 @@
};
Packet packet;
- Block wire(inputBlock, sizeof(inputBlock));
+ Block wire(inputBlock);
BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
}
@@ -399,7 +399,7 @@
};
Packet packet;
- Block wire(inputBlock, sizeof(inputBlock));
+ Block wire(inputBlock);
packet.wireDecode(wire);
BOOST_CHECK_EQUAL(1, packet.count<FragmentField>());
@@ -423,7 +423,7 @@
BOOST_AUTO_TEST_CASE(DecodeUnrecognizedTlvType)
{
Packet packet;
- Block wire = encoding::makeEmptyBlock(ndn::tlv::Name);
+ Block wire = makeEmptyBlock(ndn::tlv::Name);
BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
}
diff --git a/tests/unit/meta-info.t.cpp b/tests/unit/meta-info.t.cpp
index e5229bf..87add29 100644
--- a/tests/unit/meta-info.t.cpp
+++ b/tests/unit/meta-info.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2019 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -124,11 +124,11 @@
0x6c, 0x65, 0x78, 0x2c, 0x20, 0x49, 0x20, 0x61, 0x6d, 0x20, 0x58,
0x69, 0x61, 0x6f, 0x6b, 0x65, 0x20, 0x4a, 0x69, 0x61, 0x6e, 0x67};
- BOOST_REQUIRE_EQUAL_COLLECTIONS(info1.wireEncode().begin(), info1.wireEncode().end(),
- METAINFO, METAINFO + sizeof(METAINFO));
+ BOOST_CHECK_EQUAL_COLLECTIONS(info1.wireEncode().begin(), info1.wireEncode().end(),
+ METAINFO, METAINFO + sizeof(METAINFO));
MetaInfo info2;
- info2.wireDecode(Block(METAINFO, sizeof(METAINFO)));
+ info2.wireDecode(Block(METAINFO));
for (size_t i = 0; i < 5; i++) {
uint32_t tlvType = 128 + i * 10;
diff --git a/tests/unit/mgmt/control-response.t.cpp b/tests/unit/mgmt/control-response.t.cpp
index 74b1b03..c23f7f0 100644
--- a/tests/unit/mgmt/control-response.t.cpp
+++ b/tests/unit/mgmt/control-response.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -48,7 +48,7 @@
BOOST_AUTO_TEST_CASE(Decode)
{
- ControlResponse cr(Block(WIRE, sizeof(WIRE)));
+ ControlResponse cr(Block{WIRE});
BOOST_CHECK_EQUAL(cr.getCode(), 404);
BOOST_CHECK_EQUAL(cr.getText(), "Nothing not found");
}
diff --git a/tests/unit/mgmt/dispatcher.t.cpp b/tests/unit/mgmt/dispatcher.t.cpp
index 7827516..30b5853 100644
--- a/tests/unit/mgmt/dispatcher.t.cpp
+++ b/tests/unit/mgmt/dispatcher.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -245,7 +245,7 @@
Block
wireEncode() const final
{
- return Block();
+ return {};
}
void
@@ -298,8 +298,7 @@
BOOST_AUTO_TEST_CASE(StatusDataset)
{
- const uint8_t smallBuf[] = {0x81, 0x01, 0x01};
- const Block smallBlock(smallBuf, sizeof(smallBuf));
+ const Block smallBlock({0x81, 0x01, 0x01});
const Block largeBlock = [] {
Block b(129, std::make_shared<const Buffer>(3000));
b.encode();
@@ -399,10 +398,10 @@
content = [&dataInStorage] () -> Block {
EncodingBuffer encoder;
- size_t valueLength = encoder.prependByteArray(dataInStorage[1].getContent().value(),
- dataInStorage[1].getContent().value_size());
- valueLength += encoder.prependByteArray(dataInStorage[0].getContent().value(),
- dataInStorage[0].getContent().value_size());
+ size_t valueLength = encoder.prependBytes({dataInStorage[1].getContent().value(),
+ dataInStorage[1].getContent().value_size()});
+ valueLength += encoder.prependBytes({dataInStorage[0].getContent().value(),
+ dataInStorage[0].getContent().value_size()});
encoder.prependVarNumber(valueLength);
encoder.prependVarNumber(tlv::Content);
return encoder.block();
@@ -427,8 +426,7 @@
BOOST_AUTO_TEST_CASE(NotificationStream)
{
- const uint8_t buf[] = {0x82, 0x01, 0x02};
- const Block block(buf, sizeof(buf));
+ const Block block({0x82, 0x01, 0x02});
auto post = dispatcher.addNotificationStream("test");
post(block);
diff --git a/tests/unit/mgmt/nfd/status-dataset.t.cpp b/tests/unit/mgmt/nfd/status-dataset.t.cpp
index 21fb288..2c8c7f7 100644
--- a/tests/unit/mgmt/nfd/status-dataset.t.cpp
+++ b/tests/unit/mgmt/nfd/status-dataset.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -70,12 +70,12 @@
BOOST_CONCEPT_ASSERT((WireEncodable<T1>));
BOOST_CONCEPT_ASSERT((WireEncodable<T2>));
- ndn::encoding::EncodingBuffer buffer;
+ EncodingBuffer buffer;
payload2.wireEncode(buffer);
payload1.wireEncode(buffer);
auto data = this->prepareDatasetReply(prefix);
- data->setContent(buffer.buf(), buffer.size());
+ data->setContent(buffer);
face.receive(*signData(data));
}
diff --git a/tests/unit/mgmt/status-dataset-context.t.cpp b/tests/unit/mgmt/status-dataset-context.t.cpp
index 6d1e0b9..4192337 100644
--- a/tests/unit/mgmt/status-dataset-context.t.cpp
+++ b/tests/unit/mgmt/status-dataset-context.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -67,7 +67,7 @@
size_t valueLength = 0;
for (const auto& args : sendDataHistory) {
const auto& content = args.content;
- valueLength += encoder.appendByteArray(content.value(), content.value_size());
+ valueLength += encoder.appendBytes({content.value(), content.value_size()});
}
encoder.prependVarNumber(valueLength);
encoder.prependVarNumber(tlv::Content);
@@ -237,7 +237,7 @@
BOOST_AUTO_TEST_CASE(AppendReject)
{
const uint8_t buf[] = {0x82, 0x01, 0x02};
- BOOST_CHECK_NO_THROW(context.append(Block(buf, sizeof(buf))));
+ BOOST_CHECK_NO_THROW(context.append(Block(buf)));
BOOST_CHECK_EXCEPTION(context.reject(), std::logic_error, [] (const auto& e) {
return e.what() == "cannot call reject() after append/end"s;
});
@@ -246,7 +246,7 @@
BOOST_AUTO_TEST_CASE(AppendEndReject)
{
const uint8_t buf[] = {0x82, 0x01, 0x02};
- BOOST_CHECK_NO_THROW(context.append(Block(buf, sizeof(buf))));
+ BOOST_CHECK_NO_THROW(context.append(Block(buf)));
BOOST_CHECK_NO_THROW(context.end());
BOOST_CHECK_EXCEPTION(context.reject(), std::logic_error, [] (const auto& e) {
return e.what() == "cannot call reject() after append/end"s;
@@ -257,7 +257,7 @@
{
BOOST_CHECK_NO_THROW(context.end());
const uint8_t buf[] = {0x82, 0x01, 0x02};
- BOOST_CHECK_EXCEPTION(context.append(Block(buf, sizeof(buf))), std::logic_error, [] (const auto& e) {
+ BOOST_CHECK_EXCEPTION(context.append(Block(buf)), std::logic_error, [] (const auto& e) {
return e.what() == "cannot call append() on a finalized context"s;
});
}
@@ -282,7 +282,7 @@
{
BOOST_CHECK_NO_THROW(context.reject());
const uint8_t buf[] = {0x82, 0x01, 0x02};
- BOOST_CHECK_EXCEPTION(context.append(Block(buf, sizeof(buf))), std::logic_error, [] (const auto& e) {
+ BOOST_CHECK_EXCEPTION(context.append(Block(buf)), std::logic_error, [] (const auto& e) {
return e.what() == "cannot call append() on a finalized context"s;
});
}
diff --git a/tests/unit/name.t.cpp b/tests/unit/name.t.cpp
index fccb838..4e8d104 100644
--- a/tests/unit/name.t.cpp
+++ b/tests/unit/name.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -257,11 +257,14 @@
name.append("xKh");
BOOST_CHECK_EQUAL(name.wireEncode(), "070B 080428F0A36B 0803784B68"_block);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
name.append("0100"_block);
BOOST_CHECK_EQUAL(name.wireEncode(), "070F 080428F0A36B 0803784B68 08020100"_block);
name.append("080109"_block);
BOOST_CHECK_EQUAL(name.wireEncode(), "0712 080428F0A36B 0803784B68 08020100 080109"_block);
+#pragma GCC diagnostic pop
}
BOOST_AUTO_TEST_CASE(AppendPartialName)
diff --git a/tests/unit/security/additional-description.t.cpp b/tests/unit/security/additional-description.t.cpp
index 657870f..56a9090 100644
--- a/tests/unit/security/additional-description.t.cpp
+++ b/tests/unit/security/additional-description.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -30,7 +30,7 @@
BOOST_AUTO_TEST_SUITE(Security)
BOOST_AUTO_TEST_SUITE(TestAdditionalDescription)
-const uint8_t description[] = {
+const uint8_t DESC[] = {
0xfd, 0x01, 0x02, 0x28,
0xfd, 0x02, 0x00, 0x10, // DescriptionEntry
0xfd, 0x02, 0x01, 0x04, // DescriptionKey
@@ -44,8 +44,6 @@
0x76, 0x61, 0x6c, 0x32, // "val2"
};
-const std::string text = "[(key1:val1), (key2:val2)]";
-
BOOST_AUTO_TEST_CASE(Basic)
{
AdditionalDescription aDescription;
@@ -76,12 +74,10 @@
BOOST_CHECK_EQUAL_COLLECTIONS(aDescription.wireEncode().wire(),
aDescription.wireEncode().wire() + aDescription.wireEncode().size(),
- description,
- description + sizeof(description));
+ DESC,
+ DESC + sizeof(DESC));
- BOOST_REQUIRE_NO_THROW(AdditionalDescription(Block(description, sizeof(description))));
- AdditionalDescription aDescription2(Block(description, sizeof(description)));
-
+ AdditionalDescription aDescription2(Block{DESC});
BOOST_CHECK_EQUAL(aDescription2, aDescription);
AdditionalDescription aDescription3;
@@ -92,7 +88,7 @@
std::ostringstream os;
os << aDescription;
- BOOST_CHECK_EQUAL(os.str(), text);
+ BOOST_CHECK_EQUAL(os.str(), "[(key1:val1), (key2:val2)]");
}
BOOST_AUTO_TEST_SUITE_END() // TestAdditionalDescription
diff --git a/tests/unit/security/certificate.t.cpp b/tests/unit/security/certificate.t.cpp
index 7626e04..63b29a6 100644
--- a/tests/unit/security/certificate.t.cpp
+++ b/tests/unit/security/certificate.t.cpp
@@ -126,7 +126,7 @@
static void
generateFakeSignature(Data& data)
{
- SignatureInfo signatureInfo(Block(SIG_INFO, sizeof(SIG_INFO)));
+ SignatureInfo signatureInfo(Block{SIG_INFO});
signatureInfo.setKeyLocator(KeyLocator(Name("/ndn/site1/KEY/ksk-2516425377094")));
signatureInfo.setValidityPeriod(ValidityPeriod(time::fromIsoString("20141111T050000"),
time::fromIsoString("20141111T060000")));
@@ -137,7 +137,7 @@
BOOST_AUTO_TEST_CASE(Construction)
{
- Block block(CERT, sizeof(CERT));
+ Block block(CERT);
Certificate certificate(block);
BOOST_CHECK_EQUAL(certificate.getName(), "/ndn/site1/KEY/ksk-1416425377094/0123/%FD%00%00%01I%C9%8B");
@@ -201,7 +201,7 @@
public:
InvalidCertFixture()
{
- Certificate certBase(Block(CERT, sizeof(CERT)));
+ Certificate certBase(Block{CERT});
BOOST_CHECK_NO_THROW((Certificate(certBase)));
m_certBase = Data(certBase);
@@ -267,7 +267,7 @@
Key Locator: Name=/ndn/site1/KEY/ksk-2516425377094
)INFO").substr(1);
- Certificate certificate(Block(CERT, sizeof(CERT)));
+ Certificate certificate(Block{CERT});
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(certificate), expectedCertificateInfo);
// TODO: Check output formats of other certificates
diff --git a/tests/unit/security/detail/certificate-bundle-decoder.t.cpp b/tests/unit/security/detail/certificate-bundle-decoder.t.cpp
index ae81c82..630aaec 100644
--- a/tests/unit/security/detail/certificate-bundle-decoder.t.cpp
+++ b/tests/unit/security/detail/certificate-bundle-decoder.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -99,7 +99,7 @@
{
// First segment contains first 250 bytes of cert1
Data d;
- d.setContent(certBlock1.wire(), 250);
+ d.setContent(make_span(certBlock1.wire(), 250));
// Second segment contains the rest of cert1 and the first 100 bytes of cert2
auto buf = std::make_shared<Buffer>(certBlock1.begin() + 250, certBlock1.end());
@@ -145,7 +145,7 @@
};
// Second segment contains non-Certificate data
Data d2;
- d2.setContent(buf, sizeof(buf));
+ d2.setContent(buf);
// Third segment contains all of cert2
Data d3;
diff --git a/tests/unit/security/pib/pib-data-fixture.cpp b/tests/unit/security/pib/pib-data-fixture.cpp
index d27c742..37e1e6d 100644
--- a/tests/unit/security/pib/pib-data-fixture.cpp
+++ b/tests/unit/security/pib/pib-data-fixture.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -360,15 +360,15 @@
};
PibDataFixture::PibDataFixture()
- : id1Key1Cert1(Block(ID1_KEY1_CERT1, sizeof(ID1_KEY1_CERT1)))
- , id1Key1Cert2(Block(ID1_KEY1_CERT2, sizeof(ID1_KEY1_CERT2)))
- , id1Key2Cert1(Block(ID1_KEY2_CERT1, sizeof(ID1_KEY2_CERT1)))
- , id1Key2Cert2(Block(ID1_KEY2_CERT2, sizeof(ID1_KEY2_CERT2)))
+ : id1Key1Cert1(Block(ID1_KEY1_CERT1))
+ , id1Key1Cert2(Block(ID1_KEY1_CERT2))
+ , id1Key2Cert1(Block(ID1_KEY2_CERT1))
+ , id1Key2Cert2(Block(ID1_KEY2_CERT2))
- , id2Key1Cert1(Block(ID2_KEY1_CERT1, sizeof(ID2_KEY1_CERT1)))
- , id2Key1Cert2(Block(ID2_KEY1_CERT2, sizeof(ID2_KEY1_CERT2)))
- , id2Key2Cert1(Block(ID2_KEY2_CERT1, sizeof(ID2_KEY2_CERT1)))
- , id2Key2Cert2(Block(ID2_KEY2_CERT2, sizeof(ID2_KEY2_CERT2)))
+ , id2Key1Cert1(Block(ID2_KEY1_CERT1))
+ , id2Key1Cert2(Block(ID2_KEY1_CERT2))
+ , id2Key2Cert1(Block(ID2_KEY2_CERT1))
+ , id2Key2Cert2(Block(ID2_KEY2_CERT2))
, id1(id1Key1Cert1.getIdentity())
, id2(id2Key1Cert1.getIdentity())
diff --git a/tests/unit/security/safe-bag.t.cpp b/tests/unit/security/safe-bag.t.cpp
index c3cc7c2..5d24112 100644
--- a/tests/unit/security/safe-bag.t.cpp
+++ b/tests/unit/security/safe-bag.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -121,10 +121,10 @@
BOOST_AUTO_TEST_CASE(Constructor)
{
- Data data(Block(CERT, sizeof(CERT)));
- SafeBag safeBag1(data, ENCRYPTED_KEY);
- SafeBag safeBag2(Block(SAFE_BAG, sizeof(SAFE_BAG)));
+ Data data(Block{CERT});
auto encKey = make_span(ENCRYPTED_KEY);
+ SafeBag safeBag1(data, encKey);
+ SafeBag safeBag2(Block{SAFE_BAG});
BOOST_CHECK(safeBag1.getCertificate() == data);
BOOST_CHECK_EQUAL_COLLECTIONS(safeBag1.getEncryptedKey().begin(), safeBag1.getEncryptedKey().end(),
@@ -136,13 +136,12 @@
BOOST_AUTO_TEST_CASE(EncoderAndDecoder)
{
- Block dataBlock(CERT, sizeof(CERT));
- Data data(dataBlock);
+ Data data(Block{CERT});
SafeBag safeBag(data, ENCRYPTED_KEY);
// wire encode
- Block wireBlock = safeBag.wireEncode();
- Block block(SAFE_BAG, sizeof(SAFE_BAG));
+ const auto& wireBlock = safeBag.wireEncode();
+ Block block(SAFE_BAG);
// check safe bag block
BOOST_CHECK_EQUAL(wireBlock, block);
diff --git a/tests/unit/security/validation-policy-command-interest.t.cpp b/tests/unit/security/validation-policy-command-interest.t.cpp
index 478b2d5..4fe05b7 100644
--- a/tests/unit/security/validation-policy-command-interest.t.cpp
+++ b/tests/unit/security/validation-policy-command-interest.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -176,7 +176,7 @@
{
auto i1 = makeCommandInterest(identity);
KeyLocator kl;
- kl.setKeyDigest(makeBinaryBlock(tlv::KeyDigest, "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD", 8));
+ kl.setKeyDigest(makeBinaryBlock(tlv::KeyDigest, {0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD}));
SignatureInfo sigInfo(tlv::SignatureSha256WithRsa);
sigInfo.setKeyLocator(kl);
setNameComponent(i1, command_interest::POS_SIG_INFO,
diff --git a/tests/unit/security/validity-period.t.cpp b/tests/unit/security/validity-period.t.cpp
index 1dc7740..5dc8d9d 100644
--- a/tests/unit/security/validity-period.t.cpp
+++ b/tests/unit/security/validity-period.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -87,15 +87,11 @@
{
time::system_clock::TimePoint notBefore = time::getUnixEpoch();
time::system_clock::TimePoint notAfter = notBefore + 1_day;
-
ValidityPeriod v1(notBefore, notAfter);
-
BOOST_CHECK_EQUAL_COLLECTIONS(v1.wireEncode().begin(), v1.wireEncode().end(),
VP1, VP1 + sizeof(VP1));
- BOOST_REQUIRE_NO_THROW(ValidityPeriod(Block(VP1, sizeof(VP1))));
- Block block(VP1, sizeof(VP1));
- ValidityPeriod v2(block);
+ ValidityPeriod v2(Block{VP1});
BOOST_CHECK(v1.getPeriod() == v2.getPeriod());
}
@@ -159,21 +155,17 @@
0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
};
-
BOOST_AUTO_TEST_CASE(DecodingError)
{
- BOOST_CHECK_THROW(ValidityPeriod(Block(VP_E1, sizeof(VP_E1))), ValidityPeriod::Error);
-
- BOOST_CHECK_THROW(ValidityPeriod(Block(VP_E2, sizeof(VP_E2))), ValidityPeriod::Error);
- BOOST_CHECK_THROW(ValidityPeriod(Block(VP_E3, sizeof(VP_E3))), ValidityPeriod::Error);
-
- BOOST_CHECK_THROW(ValidityPeriod(Block(VP_E4, sizeof(VP_E4))), ValidityPeriod::Error);
- BOOST_CHECK_THROW(ValidityPeriod(Block(VP_E5, sizeof(VP_E5))), ValidityPeriod::Error);
+ BOOST_CHECK_THROW(ValidityPeriod(Block{VP_E1}), ValidityPeriod::Error);
+ BOOST_CHECK_THROW(ValidityPeriod(Block{VP_E2}), ValidityPeriod::Error);
+ BOOST_CHECK_THROW(ValidityPeriod(Block{VP_E3}), ValidityPeriod::Error);
+ BOOST_CHECK_THROW(ValidityPeriod(Block{VP_E4}), ValidityPeriod::Error);
+ BOOST_CHECK_THROW(ValidityPeriod(Block{VP_E5}), ValidityPeriod::Error);
+ BOOST_CHECK_THROW(ValidityPeriod(Block{VP_E6}), ValidityPeriod::Error);
Block emptyBlock;
- BOOST_CHECK_THROW((ValidityPeriod(emptyBlock)), ValidityPeriod::Error);
-
- BOOST_CHECK_THROW(ValidityPeriod(Block(VP_E6, sizeof(VP_E6))), ValidityPeriod::Error);
+ BOOST_CHECK_THROW(ValidityPeriod{emptyBlock}, ValidityPeriod::Error);
}
BOOST_AUTO_TEST_CASE(Comparison)
diff --git a/tests/unit/security/verification-helpers.t.cpp b/tests/unit/security/verification-helpers.t.cpp
index 479a655..5e313ec 100644
--- a/tests/unit/security/verification-helpers.t.cpp
+++ b/tests/unit/security/verification-helpers.t.cpp
@@ -49,7 +49,7 @@
// };
// auto print = [] (const std::string& name, const uint8_t* buf, size_t size) {
-// std::cout << " std::vector<uint8_t> " + name + " = {\n ";
+// std::cout << " const Block " + name + "{{\n ";
// std::string hex = toHex(buf, size);
@@ -63,7 +63,7 @@
// if ((i + 1) != hex.size())
// std::cout << ", ";
// }
-// std::cout << "\n };";
+// std::cout << "\n }};";
// };
// for (const auto& i : identities) {
@@ -130,7 +130,7 @@
struct EcdsaDataset
{
const std::string name = "Ecdsa";
- std::vector<uint8_t> cert = {
+ const Block cert{{
0x06, 0xFD, 0x01, 0x62, 0x07, 0x47, 0x08, 0x08, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79,
0x08, 0x17, 0x54, 0x65, 0x73, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69,
0x6F, 0x6E, 0x48, 0x65, 0x6C, 0x70, 0x65, 0x72, 0x73, 0x08, 0x02, 0x45, 0x43, 0x08, 0x03, 0x4B,
@@ -154,8 +154,8 @@
0x6B, 0x24, 0xF5, 0x7F, 0x02, 0x20, 0x1C, 0x88, 0xDE, 0x32, 0x3F, 0x1A, 0xE6, 0x60, 0xA2, 0x29,
0x94, 0xD9, 0x05, 0x8F, 0x57, 0x14, 0xD6, 0x17, 0x3C, 0x78, 0xBF, 0x85, 0xF5, 0x1D, 0xCC, 0x03,
0x35, 0x9E, 0xC9, 0xA9, 0x6B, 0x09
- };
- std::vector<uint8_t> goodData = {
+ }};
+ const Block goodData{{
0x06, 0xA2, 0x07, 0x13, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x04, 0x64, 0x61, 0x74, 0x61,
0x08, 0x05, 0x45, 0x63, 0x64, 0x73, 0x61, 0x14, 0x00, 0x15, 0x00, 0x16, 0x3D, 0x1B, 0x01, 0x03,
0x1C, 0x38, 0x07, 0x36, 0x08, 0x08, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x08, 0x17,
@@ -167,8 +167,8 @@
0xC3, 0x02, 0x21, 0x00, 0xB5, 0xA3, 0x87, 0xD8, 0x9B, 0xB6, 0x92, 0xAD, 0x19, 0x84, 0xAE, 0x4D,
0xF5, 0x64, 0xEC, 0x1C, 0xF2, 0xA0, 0xB7, 0x4D, 0x6B, 0x74, 0xFF, 0x39, 0x38, 0xFD, 0x5D, 0x9D,
0x46, 0xE0, 0xD2, 0xB4
- };
- std::vector<uint8_t> badSigData = {
+ }};
+ const Block badSigData{{
0x06, 0xA5, 0x07, 0x13, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x04, 0x64, 0x61, 0x74, 0x61,
0x08, 0x05, 0x45, 0x63, 0x64, 0x73, 0x61, 0x14, 0x00, 0x15, 0x00, 0x16, 0x40, 0x1B, 0x01, 0x03,
0x1C, 0x3B, 0x07, 0x39, 0x08, 0x08, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x08, 0x17,
@@ -180,8 +180,8 @@
0x13, 0xB4, 0xB8, 0x95, 0x02, 0x21, 0x00, 0xDA, 0x54, 0x99, 0xF8, 0xE5, 0xC1, 0x74, 0xAC, 0xE0,
0xF2, 0xDF, 0x0D, 0xC5, 0xE1, 0xCF, 0x99, 0x28, 0x6C, 0xB0, 0x2D, 0x55, 0xC8, 0x74, 0x63, 0x56,
0x2A, 0x1A, 0xB0, 0x00, 0xBD, 0xFF, 0xC5
- };
- std::vector<uint8_t> goodInterest = {
+ }};
+ const Block goodInterest{{
0x05, 0xCA, 0x07, 0x39, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x08, 0x69, 0x6E, 0x74, 0x65,
0x72, 0x65, 0x73, 0x74, 0x08, 0x05, 0x45, 0x63, 0x64, 0x73, 0x61, 0x02, 0x20, 0x8F, 0x41, 0x49,
0x40, 0xDA, 0x38, 0xC1, 0x0E, 0x75, 0x5A, 0x6D, 0x4A, 0xD4, 0xFC, 0xE2, 0xDF, 0xBA, 0x52, 0xAF,
@@ -195,8 +195,8 @@
0xDB, 0xEA, 0x3A, 0x71, 0x83, 0x0D, 0xC4, 0x26, 0xB7, 0x24, 0x02, 0x20, 0x0F, 0x14, 0x10, 0xDB,
0xDB, 0x24, 0xCB, 0xB3, 0xD2, 0x4B, 0x45, 0x6D, 0xA0, 0xBB, 0x4B, 0x87, 0xC1, 0x59, 0x9F, 0xC8,
0xBE, 0x75, 0xF5, 0xCC, 0xCB, 0xD2, 0x4F, 0xD8, 0x87, 0x26, 0x51, 0xBF
- };
- std::vector<uint8_t> badSigInterest = {
+ }};
+ const Block badSigInterest{{
0x05, 0xCF, 0x07, 0x39, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x08, 0x69, 0x6E, 0x74, 0x65,
0x72, 0x65, 0x73, 0x74, 0x08, 0x05, 0x45, 0x63, 0x64, 0x73, 0x61, 0x02, 0x20, 0x53, 0x14, 0x5E,
0xA3, 0x31, 0x41, 0xD8, 0xA1, 0x10, 0x06, 0x3C, 0x8E, 0xF3, 0x51, 0xA0, 0xC2, 0x8A, 0xBC, 0xFC,
@@ -211,8 +211,8 @@
0x00, 0xC7, 0x23, 0x25, 0xF7, 0xFA, 0x6A, 0x2D, 0x3D, 0xF4, 0xD8, 0xDB, 0xE9, 0x76, 0x6A, 0x63,
0xD4, 0x11, 0x17, 0x4A, 0xDB, 0x7F, 0x85, 0x52, 0x97, 0xFC, 0x5B, 0x0B, 0x1B, 0xBA, 0xE5, 0xED,
0x9A
- };
- std::vector<uint8_t> goodInterestOldFormat = {
+ }};
+ const Block goodInterestOldFormat{{
0x05, 0xCB, 0x07, 0x39, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x08, 0x69, 0x6E, 0x74, 0x65,
0x72, 0x65, 0x73, 0x74, 0x08, 0x05, 0x45, 0x63, 0x64, 0x73, 0x61, 0x02, 0x20, 0xDB, 0x6D, 0x5E,
0xA7, 0xBF, 0xAF, 0xEC, 0xA0, 0xC6, 0x20, 0x4E, 0xF2, 0x04, 0xF8, 0xFF, 0x39, 0x2A, 0x5F, 0xE6,
@@ -226,8 +226,8 @@
0x60, 0x63, 0x51, 0xB3, 0x52, 0xBC, 0x6D, 0x24, 0x0C, 0x6D, 0x38, 0x02, 0x20, 0x0E, 0x21, 0xF1,
0x51, 0x39, 0x2D, 0x4A, 0x45, 0x05, 0x45, 0xFA, 0x85, 0xA7, 0xCC, 0x00, 0xFE, 0x89, 0x8A, 0xD6,
0xD7, 0x34, 0x0D, 0x31, 0x6A, 0x94, 0xAE, 0x1F, 0xD8, 0x07, 0xF1, 0xDF, 0x80
- };
- std::vector<uint8_t> badSigInterestOldFormat = {
+ }};
+ const Block badSigInterestOldFormat{{
0x05, 0xFD, 0x01, 0x5B, 0x07, 0xC9, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x08, 0x69, 0x6E,
0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x08, 0x05, 0x45, 0x63, 0x64, 0x73, 0x61, 0x02, 0x20, 0xDB,
0x6D, 0x5E, 0xA7, 0xBF, 0xAF, 0xEC, 0xA0, 0xC6, 0x20, 0x4E, 0xF2, 0x04, 0xF8, 0xFF, 0x39, 0x2A,
@@ -250,13 +250,13 @@
0x64, 0xAA, 0x60, 0x63, 0x51, 0xB3, 0x52, 0xBC, 0x6D, 0x24, 0x0C, 0x6D, 0x38, 0x02, 0x20, 0x0E,
0x21, 0xF1, 0x51, 0x39, 0x2D, 0x4A, 0x45, 0x05, 0x45, 0xFA, 0x85, 0xA7, 0xCC, 0x00, 0xFE, 0x89,
0x8A, 0xD6, 0xD7, 0x34, 0x0D, 0x31, 0x6A, 0x94, 0xAE, 0x1F, 0xD8, 0x07, 0xF1, 0xDF, 0x80
- };
+ }};
};
struct RsaDataset
{
const std::string name = "Rsa";
- std::vector<uint8_t> cert = {
+ const Block cert{{
0x06, 0xFD, 0x02, 0xED, 0x07, 0x48, 0x08, 0x08, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79,
0x08, 0x17, 0x54, 0x65, 0x73, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69,
0x6F, 0x6E, 0x48, 0x65, 0x6C, 0x70, 0x65, 0x72, 0x73, 0x08, 0x03, 0x52, 0x53, 0x41, 0x08, 0x03,
@@ -305,8 +305,8 @@
0x3E, 0xFA, 0xE6, 0xB9, 0x8E, 0x08, 0x82, 0x50, 0xCA, 0xEE, 0x7F, 0x5D, 0x80, 0x65, 0xBA, 0x10,
0x1F, 0x24, 0xC1, 0x15, 0x78, 0xB7, 0x90, 0xE5, 0x3D, 0xDA, 0x0F, 0x0E, 0x03, 0x20, 0xC1, 0xEA,
0x85
- };
- std::vector<uint8_t> goodData = {
+ }};
+ const Block goodData{{
0x06, 0xFD, 0x01, 0x5B, 0x07, 0x11, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x04, 0x64, 0x61,
0x74, 0x61, 0x08, 0x03, 0x52, 0x73, 0x61, 0x14, 0x00, 0x15, 0x00, 0x16, 0x3E, 0x1B, 0x01, 0x01,
0x1C, 0x39, 0x07, 0x37, 0x08, 0x08, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x08, 0x17,
@@ -329,8 +329,8 @@
0x4F, 0xD9, 0xEB, 0xC1, 0x5D, 0x53, 0x15, 0xBF, 0x8C, 0x7C, 0x6B, 0x22, 0xB9, 0x24, 0x70, 0xAE,
0x63, 0x13, 0x96, 0x3B, 0x2A, 0xDA, 0x7F, 0x64, 0x0D, 0x9E, 0xA7, 0x90, 0x20, 0x2A, 0x2A, 0xAB,
0xA9, 0xA6, 0xC9, 0xB2, 0x37, 0x8E, 0xE3, 0x09, 0xFD, 0xA3, 0x68, 0x06, 0xCB, 0x96, 0x80
- };
- std::vector<uint8_t> badSigData = {
+ }};
+ const Block badSigData{{
0x06, 0xA2, 0x07, 0x11, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x04, 0x64, 0x61, 0x74, 0x61,
0x08, 0x03, 0x52, 0x73, 0x61, 0x14, 0x00, 0x15, 0x00, 0x16, 0x40, 0x1B, 0x01, 0x03, 0x1C, 0x3B,
0x07, 0x39, 0x08, 0x08, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x08, 0x17, 0x54, 0x65,
@@ -342,8 +342,8 @@
0x1E, 0x02, 0x21, 0x00, 0xA5, 0x62, 0xA5, 0x04, 0x60, 0xBC, 0x96, 0x54, 0x2C, 0x9E, 0x6F, 0xA8,
0x1B, 0xDB, 0xF9, 0xF0, 0x7E, 0xFF, 0xED, 0x92, 0x3A, 0x4B, 0xDE, 0x3D, 0x20, 0x02, 0x7B, 0xD7,
0x1C, 0xD0, 0xAA, 0xAB
- };
- std::vector<uint8_t> goodInterest = {
+ }};
+ const Block goodInterest{{
0x05, 0xFD, 0x01, 0x85, 0x07, 0x37, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x08, 0x69, 0x6E,
0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x08, 0x03, 0x52, 0x73, 0x61, 0x02, 0x20, 0x08, 0x39, 0xEE,
0x12, 0xF1, 0x10, 0xB7, 0x8B, 0x49, 0xF2, 0xE2, 0x54, 0x23, 0xFF, 0x66, 0xB3, 0x0F, 0xC6, 0x91,
@@ -369,8 +369,8 @@
0xE3, 0x11, 0x85, 0xCC, 0x0E, 0xAF, 0x56, 0x6B, 0xE1, 0xAC, 0xB3, 0x20, 0xF2, 0x47, 0xFE, 0x95,
0xC8, 0x71, 0x99, 0xCC, 0x52, 0x8A, 0x6F, 0xF1, 0x01, 0xD6, 0xE9, 0x2E, 0x6C, 0x27, 0xC3, 0xED,
0xE3, 0xF2, 0xDD, 0x78, 0xB4, 0x7F, 0xFA, 0xD0, 0xC2
- };
- std::vector<uint8_t> badSigInterest = {
+ }};
+ const Block badSigInterest{{
0x05, 0xCC, 0x07, 0x37, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x08, 0x69, 0x6E, 0x74, 0x65,
0x72, 0x65, 0x73, 0x74, 0x08, 0x03, 0x52, 0x73, 0x61, 0x02, 0x20, 0x64, 0xE3, 0x6F, 0xD5, 0x73,
0x21, 0xBC, 0xAB, 0xDE, 0xDE, 0x0F, 0x99, 0xCB, 0x49, 0x7F, 0x46, 0xE7, 0xF0, 0x7A, 0xF1, 0x2C,
@@ -384,8 +384,8 @@
0x4A, 0xBF, 0xC0, 0x5B, 0xA8, 0x05, 0xA2, 0xC8, 0x61, 0xC4, 0x2E, 0x64, 0x02, 0x20, 0x1F, 0x5E,
0xF5, 0x8E, 0xC9, 0xDC, 0x9E, 0x15, 0x1C, 0xFA, 0x58, 0x5F, 0xDF, 0xAE, 0xA0, 0xFD, 0xDA, 0x34,
0x21, 0xE0, 0xA8, 0x2D, 0x32, 0x47, 0x9E, 0x44, 0x83, 0x79, 0x23, 0x5F, 0xBE, 0x16
- };
- std::vector<uint8_t> goodInterestOldFormat = {
+ }};
+ const Block goodInterestOldFormat{{
0x05, 0xFD, 0x01, 0x85, 0x07, 0x37, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x08, 0x69, 0x6E,
0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x08, 0x03, 0x52, 0x73, 0x61, 0x02, 0x20, 0x08, 0x39, 0xEE,
0x12, 0xF1, 0x10, 0xB7, 0x8B, 0x49, 0xF2, 0xE2, 0x54, 0x23, 0xFF, 0x66, 0xB3, 0x0F, 0xC6, 0x91,
@@ -411,8 +411,8 @@
0xE3, 0x11, 0x85, 0xCC, 0x0E, 0xAF, 0x56, 0x6B, 0xE1, 0xAC, 0xB3, 0x20, 0xF2, 0x47, 0xFE, 0x95,
0xC8, 0x71, 0x99, 0xCC, 0x52, 0x8A, 0x6F, 0xF1, 0x01, 0xD6, 0xE9, 0x2E, 0x6C, 0x27, 0xC3, 0xED,
0xE3, 0xF2, 0xDD, 0x78, 0xB4, 0x7F, 0xFA, 0xD0, 0xC2
- };
- std::vector<uint8_t> badSigInterestOldFormat = {
+ }};
+ const Block badSigInterestOldFormat{{
0x05, 0xFD, 0x02, 0x15, 0x07, 0xC7, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x08, 0x69, 0x6E,
0x74, 0x65, 0x72, 0x65, 0x73, 0x74, 0x08, 0x03, 0x52, 0x73, 0x61, 0x02, 0x20, 0x08, 0x39, 0xEE,
0x12, 0xF1, 0x10, 0xB7, 0x8B, 0x49, 0xF2, 0xE2, 0x54, 0x23, 0xFF, 0x66, 0xB3, 0x0F, 0xC6, 0x91,
@@ -447,23 +447,22 @@
0xE3, 0x11, 0x85, 0xCC, 0x0E, 0xAF, 0x56, 0x6B, 0xE1, 0xAC, 0xB3, 0x20, 0xF2, 0x47, 0xFE, 0x95,
0xC8, 0x71, 0x99, 0xCC, 0x52, 0x8A, 0x6F, 0xF1, 0x01, 0xD6, 0xE9, 0x2E, 0x6C, 0x27, 0xC3, 0xED,
0xE3, 0xF2, 0xDD, 0x78, 0xB4, 0x7F, 0xFA, 0xD0, 0xC2
- };
+ }};
};
struct Sha256Dataset
{
const std::string name = "Sha256";
- std::vector<uint8_t> cert = {
-
- };
- std::vector<uint8_t> goodData = {
+ const Block cert{{
+ }};
+ const Block goodData{{
0x06, 0x41, 0x07, 0x14, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x04, 0x64, 0x61, 0x74, 0x61,
0x08, 0x06, 0x53, 0x68, 0x61, 0x32, 0x35, 0x36, 0x14, 0x00, 0x15, 0x00, 0x16, 0x03, 0x1B, 0x01,
0x00, 0x17, 0x20, 0xE2, 0xE2, 0x2F, 0x02, 0x70, 0xA7, 0xF7, 0x48, 0x70, 0x45, 0x29, 0x46, 0xBD,
0xD2, 0x62, 0x24, 0xA6, 0x1E, 0x1D, 0x75, 0x2A, 0x26, 0x98, 0x04, 0xAD, 0x9C, 0x47, 0x63, 0xF8,
0x98, 0x5A, 0x49
- };
- std::vector<uint8_t> badSigData = {
+ }};
+ const Block badSigData{{
0x06, 0xA6, 0x07, 0x14, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x04, 0x64, 0x61, 0x74, 0x61,
0x08, 0x06, 0x53, 0x68, 0x61, 0x32, 0x35, 0x36, 0x14, 0x00, 0x15, 0x00, 0x16, 0x40, 0x1B, 0x01,
0x03, 0x1C, 0x3B, 0x07, 0x39, 0x08, 0x08, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x08,
@@ -475,8 +474,8 @@
0x28, 0x19, 0x6C, 0x5C, 0xD6, 0x02, 0x21, 0x00, 0xF0, 0xD2, 0x23, 0xEA, 0xD9, 0x43, 0x6D, 0x8A,
0xD2, 0x02, 0x3F, 0xF1, 0x41, 0x12, 0xA6, 0xED, 0x87, 0xB3, 0xD5, 0x5A, 0x27, 0x5D, 0x4E, 0xEB,
0x13, 0x29, 0x01, 0xBC, 0x3C, 0xCC, 0x50, 0x61
- };
- std::vector<uint8_t> goodInterest = {
+ }};
+ const Block goodInterest{{
0x05, 0x6B, 0x07, 0x3A, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x08, 0x69, 0x6E, 0x74, 0x65,
0x72, 0x65, 0x73, 0x74, 0x08, 0x06, 0x53, 0x68, 0x61, 0x32, 0x35, 0x36, 0x02, 0x20, 0x8F, 0x03,
0x0B, 0x85, 0xA7, 0x05, 0xD8, 0x05, 0x31, 0x8E, 0x80, 0x81, 0xD3, 0xE2, 0xA8, 0x5E, 0x74, 0xD7,
@@ -484,8 +483,8 @@
0xF7, 0x2C, 0x8A, 0x4B, 0x24, 0x00, 0x2C, 0x03, 0x1B, 0x01, 0x00, 0x2E, 0x20, 0xEF, 0x45, 0x55,
0x75, 0xC8, 0x18, 0x5E, 0xE9, 0x2A, 0xAE, 0x52, 0x61, 0x0A, 0x94, 0x41, 0x03, 0x36, 0x4C, 0x13,
0x59, 0xD4, 0xC7, 0xA4, 0x3A, 0xA0, 0x40, 0x61, 0x44, 0x33, 0x93, 0x5E, 0x99
- };
- std::vector<uint8_t> badSigInterest = {
+ }};
+ const Block badSigInterest{{
0x05, 0xCE, 0x07, 0x3A, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x08, 0x69, 0x6E, 0x74, 0x65,
0x72, 0x65, 0x73, 0x74, 0x08, 0x06, 0x53, 0x68, 0x61, 0x32, 0x35, 0x36, 0x02, 0x20, 0x32, 0x3F,
0x2F, 0xA3, 0xDC, 0x15, 0x7E, 0x8C, 0xA9, 0x75, 0xF7, 0x66, 0xFF, 0xFD, 0x13, 0x42, 0x1B, 0xE1,
@@ -499,8 +498,8 @@
0x73, 0xB3, 0xA6, 0xD2, 0x99, 0x32, 0x26, 0xE2, 0x46, 0x3A, 0xE0, 0x69, 0xDF, 0xB2, 0x02, 0x20,
0x6A, 0x03, 0xCE, 0xB6, 0x85, 0x1E, 0x01, 0x5E, 0xF8, 0x48, 0xDE, 0x65, 0xB9, 0xE1, 0xEB, 0x9A,
0xF8, 0x47, 0x43, 0x5B, 0xBA, 0x63, 0xCB, 0xBA, 0xFB, 0x62, 0x1C, 0x38, 0xE8, 0x53, 0xF7, 0x29
- };
- std::vector<uint8_t> goodInterestOldFormat = {
+ }};
+ const Block goodInterestOldFormat{{
0x05, 0x6B, 0x07, 0x3A, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x08, 0x69, 0x6E, 0x74, 0x65,
0x72, 0x65, 0x73, 0x74, 0x08, 0x06, 0x53, 0x68, 0x61, 0x32, 0x35, 0x36, 0x02, 0x20, 0x8F, 0x03,
0x0B, 0x85, 0xA7, 0x05, 0xD8, 0x05, 0x31, 0x8E, 0x80, 0x81, 0xD3, 0xE2, 0xA8, 0x5E, 0x74, 0xD7,
@@ -508,8 +507,8 @@
0xF7, 0x2C, 0x8A, 0x4B, 0x24, 0x00, 0x2C, 0x03, 0x1B, 0x01, 0x00, 0x2E, 0x20, 0xEF, 0x45, 0x55,
0x75, 0xC8, 0x18, 0x5E, 0xE9, 0x2A, 0xAE, 0x52, 0x61, 0x0A, 0x94, 0x41, 0x03, 0x36, 0x4C, 0x13,
0x59, 0xD4, 0xC7, 0xA4, 0x3A, 0xA0, 0x40, 0x61, 0x44, 0x33, 0x93, 0x5E, 0x99
- };
- std::vector<uint8_t> badSigInterestOldFormat = {
+ }};
+ const Block badSigInterestOldFormat{{
0x05, 0xFA, 0x07, 0xC9, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x08, 0x69, 0x6E, 0x74, 0x65,
0x72, 0x65, 0x73, 0x74, 0x08, 0x06, 0x53, 0x68, 0x61, 0x32, 0x35, 0x36, 0x02, 0x20, 0x8F, 0x03,
0x0B, 0x85, 0xA7, 0x05, 0xD8, 0x05, 0x31, 0x8E, 0x80, 0x81, 0xD3, 0xE2, 0xA8, 0x5E, 0x74, 0xD7,
@@ -526,7 +525,7 @@
0x2C, 0x8A, 0x4B, 0x24, 0x00, 0x2C, 0x03, 0x1B, 0x01, 0x00, 0x2E, 0x20, 0xEF, 0x45, 0x55, 0x75,
0xC8, 0x18, 0x5E, 0xE9, 0x2A, 0xAE, 0x52, 0x61, 0x0A, 0x94, 0x41, 0x03, 0x36, 0x4C, 0x13, 0x59,
0xD4, 0xC7, 0xA4, 0x3A, 0xA0, 0x40, 0x61, 0x44, 0x33, 0x93, 0x5E, 0x99
- };
+ }};
};
// Note about the datasets:
@@ -547,18 +546,17 @@
BOOST_AUTO_TEST_CASE_TEMPLATE(VerifySignature, Dataset, SignatureDatasets)
{
const Dataset dataset;
- Certificate cert(Block(dataset.cert.data(), dataset.cert.size()));
- Buffer keyRaw = cert.getPublicKey();
+ Certificate cert(dataset.cert);
+ auto keyRaw = cert.getPublicKey();
transform::PublicKey key;
key.loadPkcs8(keyRaw);
- Data data(Block(dataset.goodData.data(), dataset.goodData.size()));
- Data badSigData(Block(dataset.badSigData.data(), dataset.badSigData.size()));
- Interest interest(Block(dataset.goodInterest.data(), dataset.goodInterest.size()));
- Interest badSigInterest(Block(dataset.badSigInterest.data(), dataset.badSigInterest.size()));
- Interest interestOldFormat(Block(dataset.goodInterestOldFormat.data(),
- dataset.goodInterestOldFormat.size()));
- Interest badSigInterestOldFormat(Block(dataset.badSigInterestOldFormat.data(),
- dataset.badSigInterestOldFormat.size()));
+
+ Data data(dataset.goodData);
+ Data badSigData(dataset.badSigData);
+ Interest interest(dataset.goodInterest);
+ Interest badSigInterest(dataset.badSigInterest);
+ Interest interestOldFormat(dataset.goodInterestOldFormat);
+ Interest badSigInterestOldFormat(dataset.badSigInterestOldFormat);
BOOST_CHECK(verifySignature(data, key));
BOOST_CHECK(verifySignature(data, keyRaw));
@@ -634,14 +632,12 @@
BOOST_AUTO_TEST_CASE_TEMPLATE(VerifyDigest, Dataset, DigestDatasets)
{
const Dataset dataset;
- Data data(Block(dataset.goodData.data(), dataset.goodData.size()));
- Data badSigData(Block(dataset.badSigData.data(), dataset.badSigData.size()));
- Interest interest(Block(dataset.goodInterest.data(), dataset.goodInterest.size()));
- Interest badSigInterest(Block(dataset.badSigInterest.data(), dataset.badSigInterest.size()));
- Interest interestOldFormat(Block(dataset.goodInterestOldFormat.data(),
- dataset.goodInterestOldFormat.size()));
- Interest badSigInterestOldFormat(Block(dataset.badSigInterestOldFormat.data(),
- dataset.badSigInterestOldFormat.size()));
+ Data data(dataset.goodData);
+ Data badSigData(dataset.badSigData);
+ Interest interest(dataset.goodInterest);
+ Interest badSigInterest(dataset.badSigInterest);
+ Interest interestOldFormat(dataset.goodInterestOldFormat);
+ Interest badSigInterestOldFormat(dataset.badSigInterestOldFormat);
BOOST_CHECK(verifySignature(data, nullopt));
BOOST_CHECK(verifySignature(interest, nullopt));
@@ -683,8 +679,8 @@
BOOST_AUTO_TEST_CASE(VerifyWithUnrecognizedElements) // Bug #4583
{
- Data data(Block(sha256DataUnrecognizedElements, sizeof(sha256DataUnrecognizedElements)));
- Interest interest(Block(sha256InterestUnrecognizedElements, sizeof(sha256InterestUnrecognizedElements)));
+ Data data(Block{sha256DataUnrecognizedElements});
+ Interest interest(Block{sha256InterestUnrecognizedElements});
BOOST_CHECK(verifySignature(data, nullopt));
BOOST_CHECK(verifySignature(interest, nullopt));
diff --git a/tests/unit/signature-info.t.cpp b/tests/unit/signature-info.t.cpp
index eb08285..11fdff1 100644
--- a/tests/unit/signature-info.t.cpp
+++ b/tests/unit/signature-info.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -243,8 +243,7 @@
encodedData.begin(), encodedData.end());
// Decode as (Data)SignatureInfo
- info = SignatureInfo(Block(sigInfoDataRsa, sizeof(sigInfoDataRsa)),
- SignatureInfo::Type::Data);
+ info = SignatureInfo(Block(sigInfoDataRsa), SignatureInfo::Type::Data);
BOOST_CHECK_EQUAL(info.getSignatureType(), tlv::SignatureSha256WithRsa);
BOOST_CHECK_EQUAL(info.hasKeyLocator(), true);
@@ -265,8 +264,7 @@
encodedInterest.begin(), encodedInterest.end());
// Decode as InterestSignatureInfo
- info = SignatureInfo(Block(sigInfoInterestRsa, sizeof(sigInfoInterestRsa)),
- SignatureInfo::Type::Interest);
+ info = SignatureInfo(Block(sigInfoInterestRsa), SignatureInfo::Type::Interest);
BOOST_CHECK_EQUAL(info.getSignatureType(), tlv::SignatureSha256WithRsa);
BOOST_CHECK_EQUAL(info.hasKeyLocator(), true);
@@ -285,8 +283,7 @@
encodedDataEcdsa.begin(), encodedDataEcdsa.end());
// Decode as (Data)SignatureInfo
- info = SignatureInfo(Block(sigInfoDataEcdsa, sizeof(sigInfoDataEcdsa)),
- SignatureInfo::Type::Data);
+ info = SignatureInfo(Block(sigInfoDataEcdsa), SignatureInfo::Type::Data);
BOOST_CHECK_EQUAL(info.getSignatureType(), tlv::SignatureSha256WithEcdsa);
BOOST_CHECK_EQUAL(info.hasKeyLocator(), true);
@@ -311,7 +308,7 @@
0x08, 0x07,
0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72
};
- Block errorBlock1(error1, sizeof(error1));
+ Block errorBlock1(error1);
BOOST_CHECK_THROW(SignatureInfo(errorBlock1, SignatureInfo::Type::Data), tlv::Error);
const uint8_t error2[] = {
@@ -320,13 +317,13 @@
0x01, // Sha256WithRsa
0x83, 0x00, // Unrecognized critical TLV
};
- Block errorBlock2(error2, sizeof(error2));
+ Block errorBlock2(error2);
BOOST_CHECK_THROW(SignatureInfo(errorBlock2, SignatureInfo::Type::Data), tlv::Error);
const uint8_t error3[] = {
0x16, 0x00 // Empty SignatureInfo
};
- Block errorBlock3(error3, sizeof(error3));
+ Block errorBlock3(error3);
BOOST_CHECK_THROW(SignatureInfo(errorBlock3, SignatureInfo::Type::Data), tlv::Error);
// Encoding is correct for SignatureInfo, but decoder is expecting InterestSignatureInfo
@@ -343,7 +340,7 @@
0x08, 0x07,
0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72
};
- Block errorBlock4(error4, sizeof(error4));
+ Block errorBlock4(error4);
BOOST_CHECK_THROW(SignatureInfo(errorBlock4, SignatureInfo::Type::Interest), tlv::Error);
// SignatureType and KeyLocator out-of-order
@@ -360,7 +357,7 @@
0x1b, 0x01, // SignatureType
0x01, // Sha256WithRsa
};
- Block errorBlock5(error5, sizeof(error5));
+ Block errorBlock5(error5);
BOOST_CHECK_THROW(SignatureInfo(errorBlock5, SignatureInfo::Type::Interest), tlv::Error);
// Repeated KeyLocator
@@ -385,7 +382,7 @@
0x08, 0x07,
0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72
};
- Block errorBlock6(error6, sizeof(error6));
+ Block errorBlock6(error6);
BOOST_CHECK_THROW(SignatureInfo(errorBlock6, SignatureInfo::Type::Interest), tlv::Error);
// Zero-length SignatureNonce
@@ -395,7 +392,7 @@
0x01, // Sha256WithRsa
0x26, 0x00 // SignatureNonce
};
- Block errorBlock7(error7, sizeof(error7));
+ Block errorBlock7(error7);
BOOST_CHECK_THROW(SignatureInfo(errorBlock7, SignatureInfo::Type::Interest), tlv::Error);
}
@@ -444,7 +441,7 @@
BOOST_CHECK_EQUAL(info.hasWire(), true);
// decode
- Block block(sigInfo, sizeof(sigInfo));
+ Block block(sigInfo);
SignatureInfo info2(block, SignatureInfo::Type::Data);
BOOST_CHECK_EQUAL(info2.getValidityPeriod(), vp1);
BOOST_CHECK_EQUAL(info2.hasWire(), true);
@@ -503,7 +500,7 @@
0x6a, 0x05, 0x54, 0x68, 0x69, 0x72, 0x64 // 106 "Third"
};
- SignatureInfo info3(Block(infoBytes, sizeof(infoBytes)), SignatureInfo::Type::Data);
+ SignatureInfo info3(Block(infoBytes), SignatureInfo::Type::Data);
BOOST_CHECK_EQUAL(info3, info1);
BOOST_CHECK_EQUAL_COLLECTIONS(infoBytes, infoBytes + sizeof(infoBytes),
info1.wireEncode().begin(), info1.wireEncode().end());
diff --git a/tests/unit/util/io.t.cpp b/tests/unit/util/io.t.cpp
index 8b19fe3..ebe5799 100644
--- a/tests/unit/util/io.t.cpp
+++ b/tests/unit/util/io.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -67,7 +67,7 @@
{
T t;
std::ostringstream os(std::ios_base::binary);
- io::saveBuffer(t.blob.data(), t.blob.size(), os, t.encoding);
+ io::saveBuffer(t.blob, os, t.encoding);
BOOST_CHECK_EQUAL(os.str(), t.stream.str());
}
@@ -86,7 +86,7 @@
NullStreambuf nullbuf;
std::ostream out(&nullbuf);
const Buffer buffer(1);
- BOOST_CHECK_THROW(io::saveBuffer(buffer.data(), buffer.size(), out, io::NO_ENCODING), io::Error);
+ BOOST_CHECK_THROW(io::saveBuffer(buffer, out, io::NO_ENCODING), io::Error);
}
BOOST_AUTO_TEST_CASE(UnknownIoEncoding)
@@ -94,7 +94,7 @@
std::stringstream ss;
BOOST_CHECK_THROW(io::loadTlv<Name>(ss, static_cast<io::IoEncoding>(5)), std::invalid_argument);
BOOST_CHECK_THROW(io::loadBuffer(ss, static_cast<io::IoEncoding>(5)), std::invalid_argument);
- BOOST_CHECK_THROW(io::saveBuffer(nullptr, 0, ss, static_cast<io::IoEncoding>(5)), std::invalid_argument);
+ BOOST_CHECK_THROW(io::saveBuffer({}, ss, static_cast<io::IoEncoding>(5)), std::invalid_argument);
}
class FileIoFixture
diff --git a/tests/unit/util/sha256.t.cpp b/tests/unit/util/sha256.t.cpp
index 501a015..3340204 100644
--- a/tests/unit/util/sha256.t.cpp
+++ b/tests/unit/util/sha256.t.cpp
@@ -134,7 +134,7 @@
auto expected = fromHex("b372edfd4d6a4db2cfeaeead6c34fdee9b9e759f7b8d799cf8067e39e7f2886c");
Sha256 statefulSha256;
- statefulSha256 << Block{input, sizeof(input)};
+ statefulSha256 << Block{input};
ConstBufferPtr digest = statefulSha256.computeDigest();
BOOST_CHECK_EQUAL(statefulSha256.empty(), false);
diff --git a/tests/unit/util/simple-notification.hpp b/tests/unit/util/simple-notification.hpp
index 280045a..acfa172 100644
--- a/tests/unit/util/simple-notification.hpp
+++ b/tests/unit/util/simple-notification.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2021 Regents of the University of California,
+ * Copyright (c) 2014-2022 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -28,7 +28,7 @@
#ifndef NDN_CXX_TESTS_UNIT_UTIL_SIMPLE_NOTIFICATION_HPP
#define NDN_CXX_TESTS_UNIT_UTIL_SIMPLE_NOTIFICATION_HPP
-#include "ndn-cxx/encoding/encoding-buffer.hpp"
+#include "ndn-cxx/encoding/block-helpers.hpp"
namespace ndn {
namespace util {
@@ -53,11 +53,7 @@
Block
wireEncode() const
{
- ndn::EncodingBuffer buffer;
- buffer.prependByteArrayBlock(0x8888,
- reinterpret_cast<const uint8_t*>(m_message.c_str()),
- m_message.size());
- return buffer.block();
+ return makeStringBlock(0x8888, m_message);
}
void