blob: 8333368f28abcd6cf02c268f459efbbcb327ccec [file] [log] [blame]
Yingdi Yu3168c302015-07-04 16:45:40 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento5d0b0102017-10-07 13:43:16 -04002/*
Davide Pesavento3fdb02f2023-04-12 02:32:38 -04003 * Copyright (c) 2013-2023 Regents of the University of California.
Yingdi Yu3168c302015-07-04 16:45:40 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
Davide Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/security/transform/buffer-source.hpp"
Yingdi Yu3168c302015-07-04 16:45:40 -070023
24namespace ndn {
25namespace security {
26namespace transform {
27
Davide Pesavento765abc92021-12-27 00:44:04 -050028BufferSource::BufferSource(span<const uint8_t> buffer)
29 : m_bufs({buffer})
30{
31}
32
Davide Pesavento3fdb02f2023-04-12 02:32:38 -040033BufferSource::BufferSource(std::string_view string)
Eric Newberry6d024ba2020-06-14 16:10:34 -070034 : m_bufs({{reinterpret_cast<const uint8_t*>(string.data()), string.size()}})
Yingdi Yu3168c302015-07-04 16:45:40 -070035{
36}
37
Eric Newberry6d024ba2020-06-14 16:10:34 -070038BufferSource::BufferSource(InputBuffers buffers)
39 : m_bufs(std::move(buffers))
Yingdi Yu3168c302015-07-04 16:45:40 -070040{
41}
42
43void
44BufferSource::doPump()
45{
46 BOOST_ASSERT(m_next != nullptr);
47
Davide Pesavento765abc92021-12-27 00:44:04 -050048 for (auto buffer : m_bufs) {
49 while (!buffer.empty()) {
50 size_t nBytesWritten = m_next->write(buffer);
Davide Pesaventoa3d809e2022-02-06 11:55:02 -050051 buffer = buffer.subspan(nBytesWritten);
Eric Newberry6d024ba2020-06-14 16:10:34 -070052 }
Yingdi Yu3168c302015-07-04 16:45:40 -070053 }
54
55 m_next->end();
56}
57
58} // namespace transform
59} // namespace security
60} // namespace ndn