diff options
author | Erwin Nindl <nine@wirdorange.org> | 2007-11-07 19:08:25 +0000 |
---|---|---|
committer | Erwin Nindl <nine@wirdorange.org> | 2007-11-07 19:08:25 +0000 |
commit | dd056636dd2cd8c83822ebecfc2448cf8b4b713c (patch) | |
tree | e2ca8e3f9565f7da7a7bbbd9a8d9ebd317b2e5b1 /buffer.cpp | |
parent | i bin da beste deshalb haut des jetzt endlich so hin (diff) |
* TunDevice: changed 'char* getTypeString()' to 'const char* getTypeString()'
to fix warning: deprecated conversion from string constant to ‘char*’
* removed libsrtp, use libgcrypt instead now
* added buffer funcitons
TODO:
* fix IV issues
* add authentification
Diffstat (limited to 'buffer.cpp')
-rw-r--r-- | buffer.cpp | 74 |
1 files changed, 73 insertions, 1 deletions
@@ -87,6 +87,43 @@ void Buffer::operator=(const Buffer &src) length_ = 0; } +void Buffer::operator=(const seq_nr_t &src) +{ + if(buf_) + delete[] buf_; + + length_ = sizeof(src); + + buf_ = new u_int8_t[length_]; + + if( buf_ ) + { + for( u_int32_t index = 0; index <= length_; index++ ) + buf_[index] = (src>>index) & 0xFF; + } + else + length_ = 0; +} + + +void Buffer::operator=(const sender_id_t &src) +{ + if(buf_) + delete[] buf_; + + length_ = sizeof(src); + + buf_ = new u_int8_t[length_]; + + if( buf_ ) + { + for( u_int32_t index = 0; index <= length_; index++ ) + buf_[index] = (src>>index) & 0xFF; + } + else + length_ = 0; +} + u_int32_t Buffer::resizeFront(u_int32_t new_length) { if(length_ == new_length) @@ -171,7 +208,42 @@ void Buffer::printHexDump() const for( u_int32_t index = 0; index < length_; index++ ) { - std::sprintf(text, "%#x", buf_[index]); + std::sprintf(text, "%#4x", buf_[index]); std::cout << text << " "; + if( ((index+1) % 10) == 0 ) + std::cout << std::endl; } } + +Buffer Buffer::operator^(const Buffer &xor_by) const +{ + Buffer res(length_); + if( xor_by.getLength() > length_ ) + throw std::out_of_range("buffer::operator^ const"); + + for( u_int32_t index = 0; index < xor_by.getLength(); index++ ) + res[index] = buf_[index] ^ xor_by[index]; + + return res; +} + +Buffer Buffer::leftByteShift(u_int32_t width) const +{ + Buffer res(length_+width); + + for( u_int32_t index = 0; index < length_; index++ ) + res[index+width] = buf_[index]; + + return res; +} + +Buffer Buffer::rightByteShift(u_int32_t width) const +{ + Buffer res(length_); + + for( u_int32_t index = 0; index < length_-width; index++ ) + res[index] = buf_[index+width]; + + return res; +} + |