Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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) override
| DataSource_Memory (const std::string &in)
| DataSource_Memory (const uint8_t in[], size_t length)
| DataSource_Memory (const secure_vector< uint8_t > &in)
| DataSource_Memory (const std::vector< uint8_t > &in)
size_t | discard_next (size_t N)
bool | end_of_data () const override
size_t | get_bytes_read () const override
virtual std::string | id () const
size_t | peek (uint8_t[], size_t, size_t) const override
size_t | peek_byte (uint8_t &out) const
size_t | read (uint8_t[], size_t) override
size_t | read_byte (uint8_t &out)

## Detailed Description

This class represents a Memory-Based DataSource

Definition at line 98 of file data_src.h.

## Constructor & Destructor Documentation

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

Construct a memory source that reads from a string

Parameters

  in | the string to read from

Definition at line 97 of file data_src.cpp.

97 :
98 m_source(reinterpret_cast<const uint8_t*>(in.data()),
99 reinterpret_cast<const uint8_t*>(in.data()) + in.length()),
100 m_offset(0)
101 {
102 }

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

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 117 of file data_src.h.

117 :
118 m_source(in, in + length), m_offset(0) {}

Botan::DataSource_Memory::DataSource_Memory | ( | const secure_vector< uint8_t > & | in | ) |
| inline explicit

Construct a memory source that reads from a secure_vector

Parameters

  in | the MemoryRegion to read from

Definition at line 124 of file data_src.h.

124 :
125 m_source(in), m_offset(0) {}

Botan::DataSource_Memory::DataSource_Memory | ( | const std::vector< uint8_t > & | in | ) |
| inline explicit

Construct a memory source that reads from a std::vector

Parameters

  in | the MemoryRegion to read from

Definition at line 131 of file data_src.h.

131 :
132 m_source(in.begin(), in.end()), m_offset(0) {}

## Member Function Documentation

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

Implements Botan::DataSource.

Definition at line 67 of file data_src.cpp.

68 {
69 return (n <= (m_source.size() - m_offset));
70 }

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 38 of file data_src.cpp.

References Botan::CT::min(), and Botan::DataSource::read().

39 {
40 uint8_t buf[64] = { 0 };
41 size_t discarded = 0;
42
43 while(n)
44 {
45 const size_t got = this->read(buf, std::min(n, sizeof(buf)));
46 discarded += got;
47 n -= got;
48
49 if(got == 0)
50 break;
51 }
52
53 return discarded;
54 }
Botan::DataSource::read
virtual size_t read(uint8_t out[], size_t length) BOTAN_WARN_UNUSED_RESULT=0
Botan::CT::min
T min(T a, T b)
Definition: ct_utils.h:180

bool Botan::DataSource_Memory::end_of_data | ( |  | ) | const
| override 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 89 of file data_src.cpp.

90 {
91 return (m_offset == m_source.size());
92 }

size_t Botan::DataSource_Memory::get_bytes_read | ( |  | ) | const
| inline override virtual

Returns
  number of bytes read so far.

Implements Botan::DataSource.

Definition at line 134 of file data_src.h.

134 { return m_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 59 of file data_src.h.

59 { return ""; }

size_t Botan::DataSource_Memory::peek | ( | uint8_t | out[],
|  | size_t | length,
|  | size_t | peek_offset
| ) |  | const
| override 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 75 of file data_src.cpp.

References Botan::copy_mem(), and Botan::CT::min().

77 {
78 const size_t bytes_left = m_source.size() - m_offset;
79 if(peek_offset >= bytes_left) return 0;
80
81 size_t got = std::min(bytes_left - peek_offset, length);
82 copy_mem(out, &m_source[m_offset + peek_offset], got);
83 return got;
84 }
Botan::copy_mem
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:68
Botan::CT::min
T min(T a, T b)
Definition: ct_utils.h:180

size_t Botan::DataSource::peek_byte | ( | uint8_t & | 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 30 of file data_src.cpp.

References Botan::DataSource::peek().

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

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

size_t Botan::DataSource_Memory::read | ( | uint8_t | out[],
|  | size_t | length
| ) |  |
| override 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 59 of file data_src.cpp.

References Botan::copy_mem().

60 {
61 size_t got = std::min<size_t>(m_source.size() - m_offset, length);
62 copy_mem(out, m_source.data() + m_offset, got);
63 m_offset += got;
64 return got;
65 }
Botan::copy_mem
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:68

size_t Botan::DataSource::read_byte | ( | uint8_t & | 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 22 of file data_src.cpp.

References Botan::DataSource::read().

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

23 {
24 return read(&out, 1);
25 }
Botan::DataSource::read
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:

- src/lib/utils/data_src.h
- src/lib/utils/data_src.cpp