libkeepass 0.2.0
KeePass key database importer/exporter library
Loading...
Searching...
No Matches
io.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#include <istream>
25#include <memory>
26#include <ostream>
27#include <string>
28#include <vector>
29
30#include "exception.hh"
31#include "libkeepass/export.hh"
32#include "libkeepass/stream.hh"
33
34namespace keepass {
35
45template <typename T> inline T consume(std::istream& src) {
46 T val;
47 src.read(reinterpret_cast<char*>(&val), sizeof(T));
48 if (!src.good())
49 throw IoError("Read error.");
50
51 return val;
52}
53
62LIBKEEPASS_API std::streamsize RemainingBytes(std::istream& src);
63
65template <> LIBKEEPASS_API std::string consume<std::string>(std::istream& src);
66
68template <> LIBKEEPASS_API std::vector<char> consume<std::vector<char>>(std::istream& src);
69
71template <> LIBKEEPASS_API std::vector<uint8_t> consume<std::vector<uint8_t>>(std::istream& src);
72
81template <typename T> void conserve(std::ostream& dst, const T& val) {
82 dst.write(reinterpret_cast<const char*>(&val), sizeof(T));
83}
84
86template <> LIBKEEPASS_API void conserve<std::string>(std::ostream& dst, const std::string& val);
87
89template <>
90LIBKEEPASS_API void conserve<std::vector<char>>(std::ostream& dst, const std::vector<char>& val);
91
93template <>
94LIBKEEPASS_API void conserve<std::vector<uint8_t>>(std::ostream& dst,
95 const std::vector<uint8_t>& val);
96
105namespace io {
106
107using ::keepass::array_iostreambuf;
108using ::keepass::encrypt_ostreambuf;
109using ::keepass::gzip_istreambuf;
110using ::keepass::gzip_ostreambuf;
111using ::keepass::hashed_istreambuf;
112using ::keepass::hashed_ostreambuf;
113using ::keepass::hmac_istreambuf;
114using ::keepass::hmac_ostreambuf;
115
116} // namespace io
117
118} // namespace keepass
Thrown for input/output errors while reading or writing databases.
Definition exception.hh:147
Exception types thrown by the library.
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
LIBKEEPASS_API std::streamsize RemainingBytes(std::istream &src)
Returns the number of bytes available from the current position of the stream up to its end,...
T consume(std::istream &src)
Reads and returns a value of type T from the stream.
Definition io.hh:45
void conserve(std::ostream &dst, const T &val)
Writes a value of type T to the stream.
Definition io.hh:81
Stream buffer adapters for hashed, HMAC, and gzip I/O.