Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.8 KiB

  1. // specification file for an unlimited queue for storing bytes
  2. #ifndef CRYPTOPP_QUEUE_H
  3. #define CRYPTOPP_QUEUE_H
  4. #include "simple.h"
  5. //#include <algorithm>
  6. NAMESPACE_BEGIN(CryptoPP)
  7. /** The queue is implemented as a linked list of byte arrays, but you don't need to
  8. know about that. So just ignore this next line. :) */
  9. class ByteQueueNode;
  10. //! Byte Queue
  11. class CRYPTOPP_DLL ByteQueue : public Bufferless<BufferedTransformation>
  12. {
  13. public:
  14. ByteQueue(size_t nodeSize=0);
  15. ByteQueue(const ByteQueue &copy);
  16. ~ByteQueue();
  17. lword MaxRetrievable() const
  18. {return CurrentSize();}
  19. bool AnyRetrievable() const
  20. {return !IsEmpty();}
  21. void IsolatedInitialize(const NameValuePairs &parameters);
  22. byte * CreatePutSpace(size_t &size);
  23. size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
  24. size_t Get(byte &outByte);
  25. size_t Get(byte *outString, size_t getMax);
  26. size_t Peek(byte &outByte) const;
  27. size_t Peek(byte *outString, size_t peekMax) const;
  28. size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
  29. size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
  30. // these member functions are not inherited
  31. void SetNodeSize(size_t nodeSize);
  32. lword CurrentSize() const;
  33. bool IsEmpty() const;
  34. void Clear();
  35. void Unget(byte inByte);
  36. void Unget(const byte *inString, size_t length);
  37. const byte * Spy(size_t &contiguousSize) const;
  38. void LazyPut(const byte *inString, size_t size);
  39. void LazyPutModifiable(byte *inString, size_t size);
  40. void UndoLazyPut(size_t size);
  41. void FinalizeLazyPut();
  42. ByteQueue & operator=(const ByteQueue &rhs);
  43. bool operator==(const ByteQueue &rhs) const;
  44. byte operator[](lword i) const;
  45. void swap(ByteQueue &rhs);
  46. class Walker : public InputRejecting<BufferedTransformation>
  47. {
  48. public:
  49. Walker(const ByteQueue &queue)
  50. : m_queue(queue) {Initialize();}
  51. lword GetCurrentPosition() {return m_position;}
  52. lword MaxRetrievable() const
  53. {return m_queue.CurrentSize() - m_position;}
  54. void IsolatedInitialize(const NameValuePairs &parameters);
  55. size_t Get(byte &outByte);
  56. size_t Get(byte *outString, size_t getMax);
  57. size_t Peek(byte &outByte) const;
  58. size_t Peek(byte *outString, size_t peekMax) const;
  59. size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
  60. size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
  61. private:
  62. const ByteQueue &m_queue;
  63. const ByteQueueNode *m_node;
  64. lword m_position;
  65. size_t m_offset;
  66. const byte *m_lazyString;
  67. size_t m_lazyLength;
  68. };
  69. friend class Walker;
  70. private:
  71. void CleanupUsedNodes();
  72. void CopyFrom(const ByteQueue &copy);
  73. void Destroy();
  74. bool m_autoNodeSize;
  75. size_t m_nodeSize;
  76. ByteQueueNode *m_head, *m_tail;
  77. byte *m_lazyString;
  78. size_t m_lazyLength;
  79. bool m_lazyStringModifiable;
  80. };
  81. //! use this to make sure LazyPut is finalized in event of exception
  82. class CRYPTOPP_DLL LazyPutter
  83. {
  84. public:
  85. LazyPutter(ByteQueue &bq, const byte *inString, size_t size)
  86. : m_bq(bq) {bq.LazyPut(inString, size);}
  87. ~LazyPutter()
  88. {try {m_bq.FinalizeLazyPut();} catch(...) {}}
  89. protected:
  90. LazyPutter(ByteQueue &bq) : m_bq(bq) {}
  91. private:
  92. ByteQueue &m_bq;
  93. };
  94. //! like LazyPutter, but does a LazyPutModifiable instead
  95. class LazyPutterModifiable : public LazyPutter
  96. {
  97. public:
  98. LazyPutterModifiable(ByteQueue &bq, byte *inString, size_t size)
  99. : LazyPutter(bq) {bq.LazyPutModifiable(inString, size);}
  100. };
  101. NAMESPACE_END
  102. #ifndef __BORLANDC__
  103. NAMESPACE_BEGIN(std)
  104. template<> inline void swap(CryptoPP::ByteQueue &a, CryptoPP::ByteQueue &b)
  105. {
  106. a.swap(b);
  107. }
  108. NAMESPACE_END
  109. #endif
  110. #endif