24 #include <boost/iostreams/read.hpp>
29 : m_keyChain(keyChain)
30 , m_signingInfo(signingInfo)
34 std::vector<std::shared_ptr<Data>>
38 if (maxSegmentSize == 0) {
39 NDN_THROW(std::invalid_argument(
"maxSegmentSize must be greater than 0"));
43 const uint64_t numSegments = 1 + (buffer.size() - !buffer.empty()) / maxSegmentSize;
46 std::vector<std::shared_ptr<Data>> segments;
47 segments.reserve(numSegments);
50 auto segLen = std::min(buffer.size(), maxSegmentSize);
52 auto data = std::make_shared<Data>();
53 data->setName(
Name(dataName).appendSegment(segments.size()));
54 data->setContentType(contentType);
55 data->setFreshnessPeriod(freshnessPeriod);
56 data->setFinalBlock(finalBlockId);
57 data->setContent(buffer.first(segLen));
59 m_keyChain.
sign(*data, m_signingInfo);
60 segments.push_back(std::move(data));
62 buffer = buffer.subspan(segLen);
63 }
while (!buffer.empty());
65 BOOST_ASSERT(segments.size() == numSegments);
69 std::vector<std::shared_ptr<Data>>
73 if (maxSegmentSize == 0) {
74 NDN_THROW(std::invalid_argument(
"maxSegmentSize must be greater than 0"));
77 std::vector<std::shared_ptr<Data>> segments;
80 auto buffer = std::make_shared<Buffer>(maxSegmentSize);
81 auto n = boost::iostreams::read(input, buffer->get<
char>(), buffer->size());
87 auto data = std::make_shared<Data>();
88 data->setName(
Name(dataName).appendSegment(segments.size()));
89 data->setContentType(contentType);
90 data->setFreshnessPeriod(freshnessPeriod);
91 data->setContent(std::move(buffer));
93 segments.push_back(std::move(data));
97 if (segments.empty()) {
98 auto data = std::make_shared<Data>();
99 data->setName(
Name(dataName).appendSegment(0));
100 data->setContentType(contentType);
101 data->setFreshnessPeriod(freshnessPeriod);
102 segments.push_back(std::move(data));
107 for (
const auto& data : segments) {
108 data->setFinalBlock(finalBlockId);
109 m_keyChain.
sign(*data, m_signingInfo);
Represents an absolute name.
Segmenter(KeyChain &keyChain, const security::SigningInfo &signingInfo)
Constructor.
std::vector< std::shared_ptr< Data > > segment(span< const uint8_t > buffer, const Name &dataName, size_t maxSegmentSize, time::milliseconds freshnessPeriod, uint32_t contentType=tlv::ContentType_Blob)
Splits a blob of bytes into one or more Data packets (segments).
static Component fromSegment(uint64_t segmentNo)
Create a segment number component using NDN naming conventions.
The main interface for signing key management.
void sign(Data &data, const SigningInfo ¶ms=SigningInfo())
Sign a Data packet according to the supplied signing information.
Signing parameters passed to KeyChain.
::boost::chrono::milliseconds milliseconds