Botan
1.11.15
|
#include <data_src.h>
Public Member Functions | |
DataSource_Stream (std::istream &, const std::string &id="<std::istream>") | |
DataSource_Stream (const std::string &file, bool use_binary=false) | |
DataSource_Stream (const DataSource_Stream &) | |
size_t | discard_next (size_t N) |
bool | end_of_data () const |
virtual size_t | get_bytes_read () const |
std::string | id () const |
DataSource_Stream & | operator= (const DataSource_Stream &) |
size_t | peek (byte[], size_t, size_t) const |
size_t | peek_byte (byte &out) const |
size_t | read (byte[], size_t) |
size_t | read_byte (byte &out) |
~DataSource_Stream () |
This class represents a Stream-Based DataSource.
Definition at line 141 of file data_src.h.
Botan::DataSource_Stream::DataSource_Stream | ( | std::istream & | in, |
const std::string & | id = "<std::istream>" |
||
) |
Definition at line 174 of file data_src.cpp.
:
identifier(name),
source_p(nullptr),
source(in),
total_read(0)
{
}
Botan::DataSource_Stream::DataSource_Stream | ( | const std::string & | file, |
bool | use_binary = false |
||
) |
Construct a Stream-Based DataSource from file
file | the name of the file |
use_binary | whether to treat the file as binary or not |
Definition at line 155 of file data_src.cpp.
: identifier(path), source_p(new std::ifstream( path.c_str(), use_binary ? std::ios::binary : std::ios::in)), source(*source_p), total_read(0) { if(!source.good()) { delete source_p; throw Stream_IO_Error("DataSource: Failure opening file " + path); } }
Definition at line 186 of file data_src.cpp.
{
delete source_p;
}
size_t Botan::DataSource::discard_next | ( | size_t | N | ) | [inherited] |
Discard the next N bytes of the data
N | the number of bytes to discard |
Definition at line 35 of file data_src.cpp.
References n, and Botan::DataSource::read_byte().
bool Botan::DataSource_Stream::end_of_data | ( | ) | const [virtual] |
Test whether the source still has data that can be read.
Implements Botan::DataSource.
Definition at line 139 of file data_src.cpp.
Referenced by peek().
{
return (!source.good());
}
virtual size_t Botan::DataSource_Stream::get_bytes_read | ( | ) | const [inline, virtual] |
Implements Botan::DataSource.
Definition at line 165 of file data_src.h.
{ return total_read; }
std::string Botan::DataSource_Stream::id | ( | ) | const [virtual] |
return the id of this data source
Reimplemented from Botan::DataSource.
Definition at line 147 of file data_src.cpp.
{
return identifier;
}
DataSource_Stream& Botan::DataSource_Stream::operator= | ( | const DataSource_Stream & | ) |
size_t Botan::DataSource_Stream::peek | ( | byte | out[], |
size_t | length, | ||
size_t | peek_offset | ||
) | const [virtual] |
Read from the source but do not modify the internal offset. Consecutive calls to peek() will return portions of the source starting at the same position.
out | the byte array to write the output to |
length | the length of the byte array out |
peek_offset | the offset into the stream to read at |
Implements Botan::DataSource.
Definition at line 105 of file data_src.cpp.
References end_of_data().
{ if(end_of_data()) throw Invalid_State("DataSource_Stream: Cannot peek when out of data"); size_t got = 0; if(offset) { secure_vector<byte> buf(offset); source.read(reinterpret_cast<char*>(&buf[0]), buf.size()); if(source.bad()) throw Stream_IO_Error("DataSource_Stream::peek: Source failure"); got = source.gcount(); } if(got == offset) { source.read(reinterpret_cast<char*>(out), length); if(source.bad()) throw Stream_IO_Error("DataSource_Stream::peek: Source failure"); got = source.gcount(); } if(source.eof()) source.clear(); source.seekg(total_read, std::ios::beg); return got; }
size_t Botan::DataSource::peek_byte | ( | byte & | out | ) | const [inherited] |
Peek at one byte.
out | an output byte |
Definition at line 27 of file data_src.cpp.
References Botan::DataSource::peek().
Referenced by Botan::ASN1::maybe_BER().
{ return peek(&out, 1, 0); }
size_t Botan::DataSource_Stream::read | ( | byte | out[], |
size_t | length | ||
) | [virtual] |
Read from the source. Moves the internal offset so that every call to read will return a new portion of the source.
out | the byte array to write the result to |
length | the length of the byte array out |
Implements Botan::DataSource.
Definition at line 91 of file data_src.cpp.
{ source.read(reinterpret_cast<char*>(out), length); if(source.bad()) throw Stream_IO_Error("DataSource_Stream::read: Source failure"); size_t got = source.gcount(); total_read += got; return got; }
size_t Botan::DataSource::read_byte | ( | byte & | out | ) | [inherited] |
Read one byte.
out | the byte to read to |
Definition at line 19 of file data_src.cpp.
References Botan::DataSource::read().
Referenced by Botan::PEM_Code::decode(), Botan::DataSource::discard_next(), Botan::BER_Decoder::discard_remaining(), Botan::PGP_decode(), and Botan::BER_Decoder::raw_bytes().
{ return read(&out, 1); }