From dd056636dd2cd8c83822ebecfc2448cf8b4b713c Mon Sep 17 00:00:00 2001 From: Erwin Nindl Date: Wed, 7 Nov 2007 19:08:25 +0000 Subject: * 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TODO: * fix IV issues * add authentification --- buffer.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) (limited to 'buffer.cpp') diff --git a/buffer.cpp b/buffer.cpp index 6d16467..4bcb9b8 100644 --- a/buffer.cpp +++ b/buffer.cpp @@ -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; +} + -- cgit v1.2.3