mariadb/extra/yassl/include/buffer.hpp
unknown f0aacbca63 Import latest version of yaSSL
- Replace SawTooth copyright header with MySQL's
 - Bug#19209 Test 'rpl_openssl' hangs on Windows
 - Spurious "2013 Connection to server lost" errors fixed
   yaSSL doesn't close socket anymore, that is left to the application 


extra/yassl/README:
  Import patch yassl.diff
extra/yassl/include/buffer.hpp:
  Import patch yassl.diff
extra/yassl/include/cert_wrapper.hpp:
  Import patch yassl.diff
extra/yassl/include/crypto_wrapper.hpp:
  Import patch yassl.diff
extra/yassl/include/factory.hpp:
  Import patch yassl.diff
extra/yassl/include/handshake.hpp:
  Import patch yassl.diff
extra/yassl/include/lock.hpp:
  Import patch yassl.diff
extra/yassl/include/log.hpp:
  Import patch yassl.diff
extra/yassl/include/openssl/ssl.h:
  Import patch yassl.diff
extra/yassl/include/socket_wrapper.hpp:
  Import patch yassl.diff
extra/yassl/include/timer.hpp:
  Import patch yassl.diff
extra/yassl/include/yassl.hpp:
  Import patch yassl.diff
extra/yassl/include/yassl_error.hpp:
  Import patch yassl.diff
extra/yassl/include/yassl_imp.hpp:
  Import patch yassl.diff
extra/yassl/include/yassl_int.hpp:
  Import patch yassl.diff
extra/yassl/include/yassl_types.hpp:
  Import patch yassl.diff
extra/yassl/src/buffer.cpp:
  Import patch yassl.diff
extra/yassl/src/cert_wrapper.cpp:
  Import patch yassl.diff
extra/yassl/src/crypto_wrapper.cpp:
  Import patch yassl.diff
extra/yassl/src/handshake.cpp:
  Import patch yassl.diff
extra/yassl/src/lock.cpp:
  Import patch yassl.diff
extra/yassl/src/log.cpp:
  Import patch yassl.diff
extra/yassl/src/socket_wrapper.cpp:
  Import patch yassl.diff
extra/yassl/src/ssl.cpp:
  Import patch yassl.diff
extra/yassl/src/template_instnt.cpp:
  Import patch yassl.diff
extra/yassl/src/timer.cpp:
  Import patch yassl.diff
extra/yassl/src/yassl.cpp:
  Import patch yassl.diff
extra/yassl/src/yassl_error.cpp:
  Import patch yassl.diff
extra/yassl/src/yassl_imp.cpp:
  Import patch yassl.diff
extra/yassl/src/yassl_int.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/aes.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/algebra.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/arc4.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/asn.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/block.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/blowfish.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/coding.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/des.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/dh.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/dsa.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/error.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/file.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/hash.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/hmac.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/integer.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/kernelc.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/md2.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/md4.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/md5.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/misc.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/modarith.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/modes.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/pwdbased.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/random.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/ripemd.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/rsa.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/runtime.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/sha.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/twofish.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/type_traits.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/include/types.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/mySTL/algorithm.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/mySTL/helpers.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/mySTL/list.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/mySTL/memory.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/mySTL/memory_array.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/mySTL/pair.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/mySTL/stdexcept.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/mySTL/vector.hpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/aes.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/aestables.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/algebra.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/arc4.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/asn.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/bftables.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/blowfish.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/coding.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/crypto.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/des.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/dh.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/dsa.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/file.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/hash.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/integer.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/md2.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/md4.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/md5.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/misc.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/random.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/ripemd.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/rsa.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/sha.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/template_instnt.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/tftables.cpp:
  Import patch yassl.diff
extra/yassl/taocrypt/src/twofish.cpp:
  Import patch yassl.diff
2007-01-29 16:54:40 +01:00

207 lines
5.5 KiB
C++

/*
Copyright (C) 2000-2007 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA 02110-1301 USA.
*/
/* yaSSL buffer header defines input and output buffers to simulate streaming
* with SSL types and sockets
*/
#ifndef yaSSL_BUFFER_HPP
#define yaSSL_BUFFER_HPP
#include <assert.h> // assert
#include "yassl_types.hpp" // ysDelete
#include "memory.hpp" // mySTL::auto_ptr
#include STL_ALGORITHM_FILE
namespace STL = STL_NAMESPACE;
#ifdef _MSC_VER
// disable truncated debug symbols
#pragma warning(disable:4786)
#endif
namespace yaSSL {
typedef unsigned char byte;
typedef unsigned int uint;
const uint AUTO = 0xFEEDBEEF;
// Checking Policy should implement a check function that tests whether the
// index is within the size limit of the array
struct Check {
void check(uint i, uint limit);
};
struct NoCheck {
void check(uint, uint);
};
/* input_buffer operates like a smart c style array with a checking option,
* meant to be read from through [] with AUTO index or read().
* Should only write to at/near construction with assign() or raw (e.g., recv)
* followed by add_size with the number of elements added by raw write.
*
* Not using vector because need checked []access, offset, and the ability to
* write to the buffer bulk wise and have the correct size
*/
class input_buffer : public Check {
uint size_; // number of elements in buffer
uint current_; // current offset position in buffer
byte* buffer_; // storage for buffer
byte* end_; // end of storage marker
public:
input_buffer();
explicit input_buffer(uint s);
// with assign
input_buffer(uint s, const byte* t, uint len);
~input_buffer();
// users can pass defualt zero length buffer and then allocate
void allocate(uint s);
// for passing to raw writing functions at beginning, then use add_size
byte* get_buffer() const;
// after a raw write user can set new size
// if you know the size before the write use assign()
void add_size(uint i);
uint get_capacity() const;
uint get_current() const;
uint get_size() const;
uint get_remaining() const;
void set_current(uint i);
// read only access through [], advance current
// user passes in AUTO index for ease of use
const byte& operator[](uint i);
// end of input test
bool eof();
// peek ahead
byte peek() const;
// write function, should use at/near construction
void assign(const byte* t, uint s);
// use read to query input, adjusts current
void read(byte* dst, uint length);
private:
input_buffer(const input_buffer&); // hide copy
input_buffer& operator=(const input_buffer&); // and assign
};
/* output_buffer operates like a smart c style array with a checking option.
* Meant to be written to through [] with AUTO index or write().
* Size (current) counter increases when written to. Can be constructed with
* zero length buffer but be sure to allocate before first use.
* Don't use add write for a couple bytes, use [] instead, way less overhead.
*
* Not using vector because need checked []access and the ability to
* write to the buffer bulk wise and retain correct size
*/
class output_buffer : public Check {
uint current_; // current offset and elements in buffer
byte* buffer_; // storage for buffer
byte* end_; // end of storage marker
public:
// default
output_buffer();
// with allocate
explicit output_buffer(uint s);
// with assign
output_buffer(uint s, const byte* t, uint len);
~output_buffer();
uint get_size() const;
uint get_capacity() const;
void set_current(uint c);
// users can pass defualt zero length buffer and then allocate
void allocate(uint s);
// for passing to reading functions when finished
const byte* get_buffer() const;
// allow write access through [], update current
// user passes in AUTO as index for ease of use
byte& operator[](uint i);
// end of output test
bool eof();
void write(const byte* t, uint s);
private:
output_buffer(const output_buffer&); // hide copy
output_buffer& operator=(const output_buffer&); // and assign
};
// turn delete an incomplete type into comipler error instead of warning
template <typename T>
inline void checked_delete(T* p)
{
typedef char complete_type[sizeof(T) ? 1 : -1];
(void)sizeof(complete_type);
ysDelete(p);
}
// checked delete functor increases effeciency, no indirection on function call
// sets pointer to zero so safe for std conatiners
struct del_ptr_zero
{
template <typename T>
void operator()(T*& p) const
{
T* tmp = 0;
STL::swap(tmp, p);
checked_delete(tmp);
}
};
} // naemspace
#endif // yaSSL_BUUFER_HPP