Botan 1.10.17

Public Member Functions | List of all members
Botan::DataSource_Memory Class Reference

`#include <data_src.h>`

Inheritance diagram for Botan::DataSource_Memory:

## Public Member Functions
bool | check_available (size_t n)
| DataSource_Memory (const std::string &in)
| DataSource_Memory (const byte in[], size_t length)
| DataSource_Memory (const MemoryRegion< byte > &in)
size_t | discard_next (size_t N)
bool | end_of_data () 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 94 of file data_src.h.

## Constructor & Destructor Documentation

## ◆ DataSource_Memory() [1/3]

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

Construct a memory source that reads from a string

Parameters

  in | the string to read from

Definition at line 98 of file data_src.cpp.

98 :
99 source(reinterpret_cast<const byte*>(in.data()), in.length())
100 {
101 offset = 0;
102 }

## ◆ DataSource_Memory() [2/3]

Botan::DataSource_Memory::DataSource_Memory | ( | const byte | in[],
|  | size_t | length
| ) |  |

Construct a memory source that reads from a byte array

Parameters

  in | the byte array to read from
  length | the length of the byte array

Definition at line 80 of file data_src.cpp.

80 :
81 source(in, length)
82 {
83 offset = 0;
84 }

## ◆ DataSource_Memory() [3/3]

Botan::DataSource_Memory::DataSource_Memory | ( | const MemoryRegion< byte > & | in | ) |

Construct a memory source that reads from a MemoryRegion

Parameters

  in | the MemoryRegion to read from

Definition at line 89 of file data_src.cpp.

89 :
90 source(in)
91 {
92 offset = 0;
93 }

## Member Function Documentation

## ◆ check_available()

bool Botan::DataSource_Memory::check_available | ( | size_t | n | ) |
| virtual

Implements Botan::DataSource.

Definition at line 104 of file data_src.cpp.

105 {
106 return (n <= (source.size() - offset));
107 }
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ discard_next()

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

Discard the next N bytes of the data

Parameters

  N | the number of bytes to discard

Returns
  number of bytes actually discarded

Definition at line 35 of file data_src.cpp.

36 {
37 size_t discarded = 0;
38 byte dummy;
39 for(size_t j = 0; j != n; ++j)
40 discarded += read_byte(dummy);
41 return discarded;
42 }
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::DataSource::read_byte
size_t read_byte(byte &out)
Definition: data_src.cpp:19

## ◆ end_of_data()

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.

References Botan::MemoryRegion< T >::size().

73 {
74 return (offset == source.size());
75 }
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ id()

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, and Botan::DataSource_Command.

Definition at line 57 of file data_src.h.

57 { return ""; }

## ◆ peek()

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

  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

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(), Botan::CT::min(), and Botan::MemoryRegion< T >::size().

60 {
61 const size_t bytes_left = source.size() - offset;
62 if(peek_offset >= bytes_left) return 0;
63
64 size_t got = std::min(bytes_left - peek_offset, length);
65 copy_mem(out, &source[offset + peek_offset], got);
66 return got;
67 }
Botan::copy_mem
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:22
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::CT::min
T min(T a, T b)
Definition: ct_utils.h:127

## ◆ peek_byte()

size_t Botan::DataSource::peek_byte | ( | byte & | out | ) | const
| inherited

Peek at one byte.

Parameters

  out | an 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().

28 {
29 return peek(&out, 1, 0);
30 }
Botan::DataSource::peek
virtual size_t peek(byte out[], size_t length, size_t peek_offset) const =0

## ◆ read()

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

  out | the byte array to write the result to
  length | the 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(), and Botan::MemoryRegion< T >::size().

48 {
49 size_t got = std::min<size_t>(source.size() - offset, length);
50 copy_mem(out, &source[offset], got);
51 offset += got;
52 return got;
53 }
Botan::copy_mem
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:22
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ read_byte()

size_t Botan::DataSource::read_byte | ( | byte & | out | ) |
| inherited

Read one byte.

Parameters

  out | the 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::BER_Decoder::discard_remaining(), Botan::PGP_decode(), and Botan::BER_Decoder::raw_bytes().

20 {
21 return read(&out, 1);
22 }
Botan::DataSource::read
virtual size_t read(byte out[], size_t length)=0

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

- src/filters/data_src.h
- src/filters/data_src.cpp