Botan  1.11.15
Public Member Functions
Botan::DataSource_Memory Class Reference

#include <data_src.h>

Inheritance diagram for Botan::DataSource_Memory:
Botan::DataSource

List of all members.

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)

Detailed Description

This class represents a Memory-Based DataSource

Definition at line 97 of file data_src.h.


Constructor & Destructor Documentation

Botan::DataSource_Memory::DataSource_Memory ( const std::string &  in)

Construct a memory source that reads from a string

Parameters:
inthe 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

Parameters:
inthe byte array to read from
lengththe 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

Parameters:
inthe 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

Parameters:
inthe MemoryRegion to read from

Definition at line 129 of file data_src.h.

                                                   :
         source(in.begin(), in.end()), offset(0) {}

Member Function Documentation

size_t Botan::DataSource::discard_next ( size_t  N) [inherited]

Discard the next N bytes of the data

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

Definition at line 35 of file data_src.cpp.

References n, and Botan::DataSource::read_byte().

   {
   size_t discarded = 0;
   byte dummy;
   for(size_t j = 0; j != n; ++j)
      discarded += read_byte(dummy);
   return discarded;
   }
bool Botan::DataSource_Memory::end_of_data ( ) const [virtual]

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

Returns:
true if there is still data to read, false otherwise

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]
Returns:
number of bytes read so far.

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

Returns:
std::string representing 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.

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

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.

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

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.

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

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.

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

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);
   }

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