Botan
1.11.15
|
#include <data_src.h>
Public Member Functions | |
DataSource_Memory (const std::string &in) | |
DataSource_Memory (const byte in[], size_t length) | |
DataSource_Memory (const secure_vector< byte > &in) | |
DataSource_Memory (const std::vector< byte > &in) | |
size_t | discard_next (size_t N) |
bool | end_of_data () const |
virtual size_t | get_bytes_read () const |
virtual std::string | id () const |
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) |
This class represents a Memory-Based DataSource
Definition at line 97 of file data_src.h.
Botan::DataSource_Memory::DataSource_Memory | ( | const std::string & | in | ) |
Construct a memory source that reads from a string
in | the string to read from |
Definition at line 80 of file data_src.cpp.
: source(reinterpret_cast<const byte*>(in.data()), reinterpret_cast<const byte*>(in.data()) + in.length()), offset(0) { offset = 0; }
Botan::DataSource_Memory::DataSource_Memory | ( | const byte | in[], |
size_t | length | ||
) | [inline] |
Construct a memory source that reads from a byte array
in | the byte array to read from |
length | the length of the byte array |
Definition at line 115 of file data_src.h.
: source(in, in + length), offset(0) {}
Botan::DataSource_Memory::DataSource_Memory | ( | const secure_vector< byte > & | in | ) | [inline] |
Construct a memory source that reads from a secure_vector
in | the MemoryRegion to read from |
Definition at line 122 of file data_src.h.
: source(in), offset(0) {}
Botan::DataSource_Memory::DataSource_Memory | ( | const std::vector< byte > & | in | ) | [inline] |
Construct a memory source that reads from a std::vector
in | the MemoryRegion to read from |
Definition at line 129 of file data_src.h.
: source(in.begin(), in.end()), offset(0) {}
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_Memory::end_of_data | ( | ) | const [virtual] |
Test whether the source still has data that can be read.
Implements Botan::DataSource.
Definition at line 72 of file data_src.cpp.
{
return (offset == source.size());
}
virtual size_t Botan::DataSource_Memory::get_bytes_read | ( | ) | const [inline, virtual] |
Implements Botan::DataSource.
Definition at line 132 of file data_src.h.
{ return offset; }
virtual std::string Botan::DataSource::id | ( | ) | const [inline, virtual, inherited] |
return the id of this data source
Reimplemented in Botan::DataSource_Stream.
Definition at line 58 of file data_src.h.
{ return ""; }
size_t Botan::DataSource_Memory::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 58 of file data_src.cpp.
References Botan::copy_mem().
{ const size_t bytes_left = source.size() - offset; if(peek_offset >= bytes_left) return 0; size_t got = std::min(bytes_left - peek_offset, length); copy_mem(out, &source[offset + peek_offset], got); 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_Memory::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 47 of file data_src.cpp.
References Botan::copy_mem().
{ size_t got = std::min<size_t>(source.size() - offset, length); copy_mem(out, &source[offset], got); offset += 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); }