Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00031
00032 #ifndef SECU_STRING_HPP
00033 #define SECU_STRING_HPP
00034
00035 #include "../my_config.h"
00036
00037 #include <string>
00038 #include "integers.hpp"
00039 #include "special_alloc.hpp"
00040
00041 namespace libdar
00042 {
00043
00046
00048
00056
00057 class secu_string
00058 {
00059 public:
00061
00066 static bool is_string_secured();
00067
00069
00072 secu_string(U_I size = 0) { init(size); };
00073
00075
00077 secu_string(const char *ptr, U_I size) { init(size); append(ptr, size); };
00078
00080 secu_string(const secu_string & ref) { copy_from(ref); };
00081
00082
00084 secu_string & operator = (const secu_string & ref) { clean_and_destroy(); copy_from(ref); return *this; };
00085
00086 bool operator != (const std::string & ref) const { return ! (*this == ref); };
00087 bool operator != (const secu_string & ref) const { return ! (*this == ref); };
00088 bool operator == (const std::string &ref) const { return compare_with(ref.c_str(),(U_I)(ref.size())); };
00089 bool operator == (const secu_string &ref) const { return compare_with(ref.mem, *ref.string_size); };
00090
00092 ~secu_string() { clean_and_destroy(); };
00093
00095
00100 void read(int fd, U_I size);
00101
00103
00110 void append(const char *ptr, U_I size);
00111
00113 void append(int fd, U_I size);
00114
00117 void reduce_string_size_to(U_I pos);
00118
00120 void clear() { clean_and_destroy(); init(0); };
00121
00123
00125 void clear_and_resize(U_I size) { clean_and_destroy(); init(size); };
00126
00127 void clear_and_not_resize() { string_size = 0; };
00128
00130
00134 const char*c_str() const { return mem == NULL ? throw SRC_BUG : mem; };
00135
00137
00140 U_I size() const { return *string_size; };
00141
00142 #ifdef LIBDAR_SPECIAL_ALLOC
00143 USE_SPECIAL_ALLOC(secu_string);
00144 #endif
00145 private:
00146 U_I *allocated_size;
00147 char *mem;
00148 U_I *string_size;
00149
00150 void init(U_I size);
00151 void copy_from(const secu_string & ref);
00152 bool compare_with(const char *ptr, U_I size) const;
00153 void clean_and_destroy();
00154 };
00155
00157
00158 }
00159
00160 #endif