1
// specification file for an unlimited queue for storing bytes
3
#ifndef CRYPTOPP_QUEUE_H
4
#define CRYPTOPP_QUEUE_H
9
NAMESPACE_BEGIN(CryptoPP)
11
/** The queue is implemented as a linked list of byte arrays, but you don't need to
12
know about that. So just ignore this next line. :) */
16
class CRYPTOPP_DLL ByteQueue : public Bufferless<BufferedTransformation>
19
ByteQueue(size_t nodeSize=0);
20
ByteQueue(const ByteQueue ©);
23
lword MaxRetrievable() const
24
{return CurrentSize();}
25
bool AnyRetrievable() const
28
void IsolatedInitialize(const NameValuePairs ¶meters);
29
byte * CreatePutSpace(size_t &size);
30
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
32
size_t Get(byte &outByte);
33
size_t Get(byte *outString, size_t getMax);
35
size_t Peek(byte &outByte) const;
36
size_t Peek(byte *outString, size_t peekMax) const;
38
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
39
size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
41
// these member functions are not inherited
42
void SetNodeSize(size_t nodeSize);
44
lword CurrentSize() const;
49
void Unget(byte inByte);
50
void Unget(const byte *inString, size_t length);
52
const byte * Spy(size_t &contiguousSize) const;
54
void LazyPut(const byte *inString, size_t size);
55
void LazyPutModifiable(byte *inString, size_t size);
56
void UndoLazyPut(size_t size);
57
void FinalizeLazyPut();
59
ByteQueue & operator=(const ByteQueue &rhs);
60
bool operator==(const ByteQueue &rhs) const;
61
byte operator[](lword i) const;
62
void swap(ByteQueue &rhs);
64
class Walker : public InputRejecting<BufferedTransformation>
67
Walker(const ByteQueue &queue)
68
: m_queue(queue) {Initialize();}
70
lword GetCurrentPosition() {return m_position;}
72
lword MaxRetrievable() const
73
{return m_queue.CurrentSize() - m_position;}
75
void IsolatedInitialize(const NameValuePairs ¶meters);
77
size_t Get(byte &outByte);
78
size_t Get(byte *outString, size_t getMax);
80
size_t Peek(byte &outByte) const;
81
size_t Peek(byte *outString, size_t peekMax) const;
83
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
84
size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
87
const ByteQueue &m_queue;
88
const ByteQueueNode *m_node;
91
const byte *m_lazyString;
98
void CleanupUsedNodes();
99
void CopyFrom(const ByteQueue ©);
104
ByteQueueNode *m_head, *m_tail;
107
bool m_lazyStringModifiable;
110
//! use this to make sure LazyPut is finalized in event of exception
111
class CRYPTOPP_DLL LazyPutter
114
LazyPutter(ByteQueue &bq, const byte *inString, size_t size)
115
: m_bq(bq) {bq.LazyPut(inString, size);}
117
{try {m_bq.FinalizeLazyPut();} catch(...) {}}
119
LazyPutter(ByteQueue &bq) : m_bq(bq) {}
124
//! like LazyPutter, but does a LazyPutModifiable instead
125
class LazyPutterModifiable : public LazyPutter
128
LazyPutterModifiable(ByteQueue &bq, byte *inString, size_t size)
129
: LazyPutter(bq) {bq.LazyPutModifiable(inString, size);}
136
template<> inline void swap(CryptoPP::ByteQueue &a, CryptoPP::ByteQueue &b)