9#include <botan/data_src.h>
11#include <botan/exceptn.h>
12#include <botan/mem_ops.h>
13#include <botan/internal/fmt.h>
17#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
34 return peek(&out, 1, 0);
41 uint8_t buf[64] = {0};
45 const size_t got = this->
read(buf, std::min(n,
sizeof(buf)));
61 const size_t got = std::min<size_t>(m_source.size() - m_offset, length);
62 copy_mem(out, m_source.data() + m_offset, got);
68 return (n <= (m_source.size() - m_offset));
75 const size_t bytes_left = m_source.size() - m_offset;
76 if(peek_offset >= bytes_left) {
80 const size_t got = std::min(bytes_left - peek_offset, length);
81 copy_mem(out, &m_source[m_offset + peek_offset], got);
89 return (m_offset == m_source.size());
107 const size_t got =
static_cast<size_t>(m_source.gcount());
113 const std::streampos orig_pos = m_source.tellg();
114 m_source.seekg(0, std::ios::end);
115 const size_t avail =
static_cast<size_t>(m_source.tellg() - orig_pos);
116 m_source.seekg(orig_pos);
125 throw Invalid_State(
"DataSource_Stream: Cannot peek when out of data");
136 got =
static_cast<size_t>(m_source.gcount());
144 got =
static_cast<size_t>(m_source.gcount());
150 m_source.seekg(m_total_read, std::ios::beg);
159 return (!m_source.good());
169#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
176 m_source_memory(std::make_unique<std::ifstream>(std::string(path), use_binary ? std::ios::binary : std::ios::in)),
177 m_source(*m_source_memory),
179 if(!m_source.good()) {
180 throw Stream_IO_Error(fmt(
"DataSource: Failure opening file '{}'", path));
190 m_identifier(
name), m_source(in), m_total_read(0) {}
size_t read(uint8_t[], size_t) override
DataSource_Memory(std::string_view in)
size_t peek(uint8_t[], size_t, size_t) const override
bool check_available(size_t n) override
bool end_of_data() const override
~DataSource_Stream() override
bool end_of_data() const override
size_t peek(uint8_t[], size_t, size_t) const override
DataSource_Stream(std::istream &, std::string_view id="<std::istream>")
bool check_available(size_t n) override
size_t read(uint8_t[], size_t) override
std::string id() const override
size_t peek_byte(uint8_t &out) const
size_t discard_next(size_t N)
size_t read_byte(uint8_t &out)
virtual size_t peek(uint8_t out[], size_t length, size_t peek_offset) const =0
virtual size_t read(uint8_t out[], size_t length)=0
const char * cast_uint8_ptr_to_char(const uint8_t *b)
std::vector< T, secure_allocator< T > > secure_vector
constexpr void copy_mem(T *out, const T *in, size_t n)
const uint8_t * cast_char_ptr_to_uint8(const char *s)