Skip to content

Commit

Permalink
name: remove unused and redundant push_back(const T&)
Browse files Browse the repository at this point in the history
Change-Id: I88b9070eda34c31aea03d1772c14bdc596947b00
  • Loading branch information
Pesa committed Feb 9, 2024
1 parent 5d36a52 commit 334516a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 77 deletions.
80 changes: 36 additions & 44 deletions ndn-cxx/name.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ using PartialName = Name;
class Name : private boost::totally_ordered<Name>
{
public: // nested types
using Error = name::Component::Error;

using Component = name::Component;
using component_container = std::vector<Component>;
using Error = Component::Error;

// Name appears as a container of name components
// Name appears as an ordered sequence of name components
using value_type = Component;
using allocator_type = void;
using reference = Component&;
Expand All @@ -60,8 +58,8 @@ class Name : private boost::totally_ordered<Name>
using const_iterator = const Component*;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
using difference_type = component_container::difference_type;
using size_type = component_container::size_type;
using difference_type = std::vector<Component>::difference_type;
using size_type = std::vector<Component>::size_type;

public: // constructors, encoding, decoding
/**
Expand Down Expand Up @@ -344,13 +342,14 @@ class Name : private boost::totally_ordered<Name>
return append(Component(tlv::GenericNameComponent, value));
}

/** @brief Append a `NameComponent` of TLV-TYPE @p type, copying the TLV-VALUE from a range.
* @tparam Iterator an @c InputIterator dereferencing to a one-octet value type. More efficient
* implementation is available when it is a @c RandomAccessIterator.
* @param type the TLV-TYPE.
* @param first beginning of the range.
* @param last past-end of the range.
* @return A reference to this Name, to allow chaining.
/**
* @brief Append a `NameComponent` of TLV-TYPE @p type, copying the TLV-VALUE from a range.
* @tparam Iterator an @c InputIterator dereferencing to a one-octet value type. More efficient
* implementation is available when it is a @c RandomAccessIterator.
* @param type the TLV-TYPE.
* @param first beginning of the range.
* @param last past-end of the range.
* @return A reference to this Name, to allow chaining.
*/
template<class Iterator>
Name&
Expand All @@ -359,12 +358,13 @@ class Name : private boost::totally_ordered<Name>
return append(Component(type, first, last));
}

/** @brief Append a `GenericNameComponent`, copying the TLV-VALUE from a range.
* @tparam Iterator an @c InputIterator dereferencing to a one-octet value type. More efficient
* implementation is available when it is a @c RandomAccessIterator.
* @param first beginning of the range.
* @param last past-end of the range.
* @return A reference to this Name, to allow chaining.
/**
* @brief Append a `GenericNameComponent`, copying the TLV-VALUE from a range.
* @tparam Iterator an @c InputIterator dereferencing to a one-octet value type. More efficient
* implementation is available when it is a @c RandomAccessIterator.
* @param first beginning of the range.
* @param last past-end of the range.
* @return A reference to this Name, to allow chaining.
*/
template<class Iterator>
Name&
Expand All @@ -373,20 +373,22 @@ class Name : private boost::totally_ordered<Name>
return append(Component(tlv::GenericNameComponent, first, last));
}

/** @brief Append a `GenericNameComponent`, copying TLV-VALUE from a null-terminated string.
* @param str a null-terminated string. Bytes from the string are copied as is, and not
* interpreted as URI component.
* @return A reference to this Name, to allow chaining.
/**
* @brief Append a `GenericNameComponent`, copying the TLV-VALUE from a null-terminated string.
* @param str a null-terminated string. Bytes from the string are copied as is, and not
* interpreted as a URI component.
* @return A reference to this Name, to allow chaining.
*/
Name&
append(const char* str)
{
return append(Component(str));
}

/** @brief Append a PartialName.
* @param name the components to append
* @return A reference to this Name, to allow chaining.
/**
* @brief Append a PartialName.
* @param name the components to append
* @return A reference to this Name, to allow chaining.
*/
Name&
append(const PartialName& name);
Expand All @@ -402,15 +404,16 @@ class Name : private boost::totally_ordered<Name>
return append(Component::fromNumber(number));
}

/** @brief Append a component with a marked number.
* @param marker 1-octet marker
* @param number the number
/**
* @brief Append a component with a marked number.
* @param marker 1-octet marker
* @param number the number
*
* The component is encoded as a 1-octet marker, followed by a NonNegativeInteger.
* The component is encoded as a 1-octet marker, followed by a NonNegativeInteger.
*
* @return A reference to this Name, to allow chaining.
* @sa NDN Naming Conventions revision 1 (obsolete)
* https://named-data.net/wp-content/uploads/2014/08/ndn-tr-22-ndn-memo-naming-conventions.pdf
* @return A reference to this Name, to allow chaining.
* @sa NDN Naming Conventions revision 1 (obsolete)
* https://named-data.net/wp-content/uploads/2014/08/ndn-tr-22-ndn-memo-naming-conventions.pdf
*/
Name&
appendNumberWithMarker(uint8_t marker, uint64_t number)
Expand Down Expand Up @@ -543,17 +546,6 @@ class Name : private boost::totally_ordered<Name>
{reinterpret_cast<const uint8_t*>(keyword.data()), keyword.size()}));
}

/**
* @brief Append a name component.
* @note This makes push_back() an alias of append(), giving Name a similar API as `std::vector`.
*/
template<class T>
void
push_back(const T& component)
{
append(component);
}

/**
* @brief Erase the component at the specified index.
* @param i zero-based index of the component to erase;
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/name.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ BOOST_AUTO_TEST_CASE(IsPrefixOf)

BOOST_AUTO_TEST_CASE(CompareOp)
{
std::vector<Name> names = {
const std::vector<Name> names = {
Name("/"),
Name("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"),
Name("/sha256digest=0000000000000000000000000000000000000000000000000000000000000001"),
Expand Down Expand Up @@ -501,8 +501,10 @@ BOOST_AUTO_TEST_CASE(CompareOp)

for (size_t i = 0; i < names.size(); ++i) {
for (size_t j = 0; j < names.size(); ++j) {
Name lhs = names[i];
Name rhs = names[j];
const auto& lhs = names[i];
const auto& rhs = names[j];
BOOST_TEST_INFO_SCOPE("lhs = " << lhs);
BOOST_TEST_INFO_SCOPE("rhs = " << rhs);
BOOST_CHECK_EQUAL(lhs == rhs, i == j);
BOOST_CHECK_EQUAL(lhs != rhs, i != j);
BOOST_CHECK_EQUAL(lhs < rhs, i < j);
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/security/tpm/back-end.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2023 Regents of the University of California.
* Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
Expand Down Expand Up @@ -343,7 +343,8 @@ BOOST_AUTO_TEST_CASE(RandomKeyId)
for (int i = 0; i < 100; i++) {
auto key = tpm.createKey(identity, RsaKeyParams());
Name keyName = key->getKeyName();
BOOST_CHECK(keyNames.insert(keyName).second);
BOOST_TEST_INFO_SCOPE("KeyName = " << keyName);
BOOST_TEST(keyNames.insert(keyName).second);
}
}

Expand Down
49 changes: 25 additions & 24 deletions tests/unit/security/validator-config/checker.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class CheckerFixture : public KeyChainFixture
public:
CheckerFixture()
{
names.push_back("/foo/bar");
names.push_back("/foo/bar/bar");
names.push_back("/foo");
names.push_back("/other/prefix");
names.emplace_back("/foo/bar");
names.emplace_back("/foo/bar/bar");
names.emplace_back("/foo");
names.emplace_back("/other/prefix");
}

static Name
Expand All @@ -60,22 +60,6 @@ class CheckerFixture : public KeyChainFixture
return Name(name).append(suffix);
}

template<typename PktType, typename C>
static void
testChecker(C& checker, tlv::SignatureTypeValue sigType, const Name& pktName, const Name& klName, bool expectedOutcome)
{
BOOST_TEST_INFO_SCOPE("Packet = " << pktName);
BOOST_TEST_INFO_SCOPE("KeyLocator = " << klName);

auto state = PktType::makeState();
auto result = checker.check(PktType::getType(), sigType, pktName, klName, *state);
BOOST_CHECK_EQUAL(bool(result), expectedOutcome);
BOOST_CHECK(boost::logic::indeterminate(state->getOutcome()));
if (!result) {
BOOST_CHECK_NE(result.getErrorMessage(), "");
}
}

public:
std::vector<Name> names;
};
Expand Down Expand Up @@ -308,6 +292,23 @@ using Tests = boost::mp11::mp_product<
CheckerFixtures
>;

template<typename PktType, typename C>
static void
testChecker(C& checker, tlv::SignatureTypeValue sigType, const Name& pktName, const Name& klName, bool expectedOutcome)
{
BOOST_TEST_INFO_SCOPE("Packet = " << pktName);
BOOST_TEST_INFO_SCOPE("SignatureType = " << sigType);
BOOST_TEST_INFO_SCOPE("KeyLocator = " << klName);

auto state = PktType::makeState();
auto result = checker.check(PktType::getType(), sigType, pktName, klName, *state);
BOOST_TEST(bool(result) == expectedOutcome);
BOOST_TEST(boost::logic::indeterminate(state->getOutcome()));
if (!result) {
BOOST_TEST(!result.getErrorMessage().empty());
}
}

BOOST_FIXTURE_TEST_CASE_TEMPLATE(Checks, T, Tests, boost::mp11::mp_second<T>)
{
using PktType = boost::mp11::mp_first<T>;
Expand All @@ -321,12 +322,12 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(Checks, T, Tests, boost::mp11::mp_second<T>)
bool expectedOutcome = this->outcomes[i][j];

auto klName = this->makeKeyLocatorKeyName(this->names[j]);
this->template testChecker<PktType>(this->checker, tlv::SignatureSha256WithRsa, pktName, klName, expectedOutcome);
this->template testChecker<PktType>(this->checker, tlv::SignatureSha256WithEcdsa, pktName, klName, false);
testChecker<PktType>(this->checker, tlv::SignatureSha256WithRsa, pktName, klName, expectedOutcome);
testChecker<PktType>(this->checker, tlv::SignatureSha256WithEcdsa, pktName, klName, false);

klName = this->makeKeyLocatorCertName(this->names[j]);
this->template testChecker<PktType>(this->checker, tlv::SignatureSha256WithRsa, pktName, klName, expectedOutcome);
this->template testChecker<PktType>(this->checker, tlv::SignatureSha256WithEcdsa, pktName, klName, false);
testChecker<PktType>(this->checker, tlv::SignatureSha256WithRsa, pktName, klName, expectedOutcome);
testChecker<PktType>(this->checker, tlv::SignatureSha256WithEcdsa, pktName, klName, false);
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/util/sha256.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2023 Regents of the University of California.
* Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
Expand All @@ -25,6 +25,8 @@
#include "tests/boost-test.hpp"

#include <boost/endian/conversion.hpp>

#include <array>
#include <sstream>

namespace ndn::tests {
Expand Down Expand Up @@ -114,12 +116,12 @@ BOOST_AUTO_TEST_CASE(InsertionOperatorString)

BOOST_AUTO_TEST_CASE(InsertionOperatorUnsignedInt)
{
const uint64_t input[] = {1, 2, 3, 4};
const std::array input{1, 2, 3, 4};
auto expected = fromHex("7236c00c170036c6de133a878210ddd58567aa1d0619a0f70f69e38ae6f916e9");

Sha256 statefulSha256;
for (size_t i = 0; i < sizeof(input) / sizeof(uint64_t); ++i) {
statefulSha256 << boost::endian::native_to_big(input[i]);
for (auto i : input) {
statefulSha256 << boost::endian::native_to_big(static_cast<uint64_t>(i));
}
ConstBufferPtr digest = statefulSha256.computeDigest();

Expand Down

0 comments on commit 334516a

Please sign in to comment.