23 #ifndef TAO_CRYPT_FILE_HPP
24 #define TAO_CRYPT_FILE_HPP
39 explicit Source(word32 sz = 0) : buffer_(sz), current_(0) {}
40 Source(
const byte* b, word32 sz) : buffer_(b, sz), current_(0) {}
42 word32 remaining() {
if (GetError().What())
return 0;
43 else return buffer_.size() - current_; }
44 word32 size()
const {
return buffer_.size(); }
45 void grow(word32 sz) { buffer_.CleanGrow(sz); }
47 bool IsLeft(word32 sz) {
if (remaining() >= sz)
return true;
48 else { SetError(CONTENT_E);
return false; } }
50 const byte* get_buffer()
const {
return buffer_.get_buffer(); }
51 const byte* get_current()
const {
return &buffer_[current_]; }
52 word32 get_index()
const {
return current_; }
53 void set_index(word32
i) {
if (i < size()) current_ =
i; }
55 byte operator[] (word32 i) { current_ =
i;
return next(); }
56 byte next() {
if (IsLeft(1))
return buffer_[current_++];
else return 0; }
57 byte prev() {
if (current_)
return buffer_[--current_];
else return 0; }
59 void add(
const byte* data, word32 len)
62 memcpy(buffer_.get_buffer() + current_, data, len);
67 void advance(word32 i) {
if (IsLeft(i)) current_ +=
i; }
70 Error GetError() {
return error_; }
71 void SetError(ErrorNumber w) { error_.SetError(w); }
76 : buffer_(that.buffer_), current_(that.current_) {}
87 buffer_.Swap(other.buffer_);
88 STL::swap(current_, other.current_);
101 word32 size(
bool use_current =
false);
118 word32 size(
bool use_current =
false);
130 #endif // TAO_CRYPT_FILE_HPP