Botan  2.8.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::DataSource Class Referenceabstract

#include <data_src.h>

Inheritance diagram for Botan::DataSource:
Botan::DataSource_Memory Botan::DataSource_Stream Botan::Pipe Botan::SecureQueue

Public Member Functions

virtual bool check_available (size_t n)=0
 
 DataSource ()=default
 
 DataSource (const DataSource &)=delete
 
size_t discard_next (size_t N)
 
virtual bool end_of_data () const =0
 
virtual size_t get_bytes_read () const =0
 
virtual std::string id () const
 
DataSourceoperator= (const DataSource &)=delete
 
virtual size_t peek (uint8_t out[], size_t length, size_t peek_offset) const BOTAN_WARN_UNUSED_RESULT=0
 
size_t peek_byte (uint8_t &out) const
 
virtual size_t read (uint8_t out[], size_t length) BOTAN_WARN_UNUSED_RESULT=0
 
size_t read_byte (uint8_t &out)
 
virtual ~DataSource ()=default
 

Detailed Description

This class represents an abstract data source object.

Definition at line 21 of file data_src.h.

Constructor & Destructor Documentation

◆ DataSource() [1/2]

Botan::DataSource::DataSource ( )
default

◆ ~DataSource()

virtual Botan::DataSource::~DataSource ( )
virtualdefault

◆ DataSource() [2/2]

Botan::DataSource::DataSource ( const DataSource )
delete

Member Function Documentation

◆ check_available()

virtual bool Botan::DataSource::check_available ( size_t  n)
pure virtual

◆ discard_next()

size_t Botan::DataSource::discard_next ( size_t  N)

Discard the next N bytes of the data

Parameters
Nthe number of bytes to discard
Returns
number of bytes actually discarded

Definition at line 39 of file data_src.cpp.

References read().

40  {
41  uint8_t buf[64] = { 0 };
42  size_t discarded = 0;
43 
44  while(n)
45  {
46  const size_t got = this->read(buf, std::min(n, sizeof(buf)));
47  discarded += got;
48  n -= got;
49 
50  if(got == 0)
51  break;
52  }
53 
54  return discarded;
55  }
virtual size_t read(uint8_t out[], size_t length) BOTAN_WARN_UNUSED_RESULT=0

◆ end_of_data()

virtual bool Botan::DataSource::end_of_data ( ) const
pure virtual

Test whether the source still has data that can be read.

Returns
true if there is no more data to read, false otherwise

Implemented in Botan::Pipe, Botan::DataSource_Stream, Botan::DataSource_Memory, and Botan::SecureQueue.

Referenced by Botan::BER_Decoder::end_cons(), Botan::BER_Decoder::more_items(), Botan::BER_Decoder::verify_end(), and Botan::Pipe::write().

◆ get_bytes_read()

virtual size_t Botan::DataSource::get_bytes_read ( ) const
pure virtual
Returns
number of bytes read so far.

Implemented in Botan::Pipe, Botan::DataSource_Stream, Botan::DataSource_Memory, and Botan::SecureQueue.

◆ id()

virtual std::string Botan::DataSource::id ( ) const
inlinevirtual

return the id of this data source

Returns
std::string representing the id of this data source

Reimplemented in Botan::DataSource_Stream.

Definition at line 59 of file data_src.h.

59 { return ""; }

◆ operator=()

DataSource& Botan::DataSource::operator= ( const DataSource )
delete

◆ peek()

virtual size_t Botan::DataSource::peek ( uint8_t  out[],
size_t  length,
size_t  peek_offset 
) const
pure 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.

Parameters
outthe byte array to write the output to
lengththe length of the byte array out
peek_offsetthe offset into the stream to read at
Returns
length in bytes that was actually read and put into out

Implemented in Botan::Pipe, Botan::DataSource_Stream, Botan::DataSource_Memory, and Botan::SecureQueue.

Referenced by Botan::PEM_Code::matches(), and peek_byte().

◆ peek_byte()

size_t Botan::DataSource::peek_byte ( uint8_t &  out) const

Peek at one byte.

Parameters
outan output byte
Returns
length in bytes that was actually read and put into out

Definition at line 31 of file data_src.cpp.

References peek().

Referenced by Botan::ASN1::maybe_BER().

32  {
33  return peek(&out, 1, 0);
34  }
virtual size_t peek(uint8_t out[], size_t length, size_t peek_offset) const BOTAN_WARN_UNUSED_RESULT=0

◆ read()

virtual size_t Botan::DataSource::read ( uint8_t  out[],
size_t  length 
)
pure virtual

Read from the source. Moves the internal offset so that every call to read will return a new portion of the source.

Parameters
outthe byte array to write the result to
lengththe length of the byte array out
Returns
length in bytes that was actually read and put into out

Implemented in Botan::Pipe, Botan::DataSource_Stream, Botan::DataSource_Memory, and Botan::SecureQueue.

Referenced by discard_next(), Botan::BER_Decoder::get_next_object(), read_byte(), and Botan::Pipe::write().

◆ read_byte()

size_t Botan::DataSource::read_byte ( uint8_t &  out)

Read one byte.

Parameters
outthe byte to read to
Returns
length in bytes that was actually read and put into out

Definition at line 23 of file data_src.cpp.

References read().

Referenced by Botan::PEM_Code::decode(), Botan::BER_Decoder::discard_remaining(), and Botan::ASN1::maybe_BER().

24  {
25  return read(&out, 1);
26  }
virtual size_t read(uint8_t out[], size_t length) BOTAN_WARN_UNUSED_RESULT=0

The documentation for this class was generated from the following files: