libkeepass 0.2.0
KeePass key database importer/exporter library
Loading...
Searching...
No Matches
binary_source.hh
Go to the documentation of this file.
1/*
2 * libkeepass - KeePass key database importer/exporter
3 * Copyright (C) 2014 Christian Kindahl
4 * Copyright (C) 2024 Dominik Krümpelmann
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
23#pragma once
24
25#include <cstddef>
26#include <memory>
27#include <ostream>
28
29#include "libkeepass/export.hh"
30#include "libkeepass/secure.hh"
31
32namespace keepass {
33namespace detail {
34
44public:
45 virtual ~BinarySource() = default;
46
48 virtual std::size_t size() const noexcept = 0;
49
51
54 virtual void Read(std::size_t offset, void* dst, std::size_t size) const = 0;
55
57
60 virtual void WriteTo(std::ostream& dst) const = 0;
61};
62
67public:
74 BufferBinarySource(std::shared_ptr<const SecureBytes> buffer, std::size_t offset,
75 std::size_t size);
76
77 std::size_t size() const noexcept override { return size_; }
78
79 void Read(std::size_t offset, void* dst, std::size_t size) const override;
80 void WriteTo(std::ostream& dst) const override;
81
82private:
83 std::shared_ptr<const SecureBytes> buffer_;
84 std::size_t offset_ = 0;
85 std::size_t size_ = 0;
86};
87
88} // namespace detail
89} // namespace keepass
Read-only source for an attachment payload.
Definition binary_source.hh:43
virtual std::size_t size() const noexcept=0
Returns the payload size in bytes.
Binary source backed by a shared secure byte buffer.
Definition binary_source.hh:66
void Read(std::size_t offset, void *dst, std::size_t size) const override
Copies size bytes starting at offset into dst.
std::size_t size() const noexcept override
Returns the payload size in bytes.
Definition binary_source.hh:77
void WriteTo(std::ostream &dst) const override
Writes the whole payload to dst without materializing a copy.
BufferBinarySource(std::shared_ptr< const SecureBytes > buffer, std::size_t offset, std::size_t size)
Visibility/export macro for the shared library.
#define LIBKEEPASS_API
Marks a class, function or variable as part of the public ABI.
Definition export.hh:43
Secure memory handling: zeroization, locked allocations and sensitive value containers.