// SPDX-License-Identifier: BSD-3-Clause // SPDX-FileCopyrightText: 2020-2023 The Monero Project #pragma once #include #include #include "serialization.h" namespace openpgp { class packet_stream { public: packet_stream(const epee::span buffer) : packet_stream(deserializer>(buffer)) { } template < typename byte_container, typename = typename std::enable_if<(sizeof(typename byte_container::value_type) == 1)>::type> packet_stream(deserializer buffer) { while (!buffer.empty()) { packet_tag tag = buffer.read_packet_tag(); packets.push_back({std::move(tag), buffer.read(tag.length)}); } } const std::vector *find_first(packet_tag::type type) const { for (const auto &packet : packets) { if (packet.first.packet_type == type) { return &packet.second; } } return nullptr; } template void for_each(packet_tag::type type, Callback &callback) const { for (const auto &packet : packets) { if (packet.first.packet_type == type) { callback(packet.second); } } } private: std::vector>> packets; }; } // namespace openpgp