32 #ifndef SECU_STRING_HPP
33 #define SECU_STRING_HPP
35 #include "../my_config.h"
91 bool operator != (
const std::string & ref)
const {
return ! (*
this == ref); };
92 bool operator != (
const secu_string & ref)
const {
return ! (*
this == ref); };
93 bool operator == (
const std::string &ref)
const {
return compare_with(ref.c_str(),(U_I)(ref.size())); };
94 bool operator == (
const secu_string &ref)
const {
return compare_with(ref.mem, *(ref.string_size)); };
104 void set(
int fd, U_I size);
115 void append_at(U_I offset,
const char *ptr, U_I size);
118 void append_at(U_I offset,
int fd, U_I size);
141 void resize(U_I size) { clean_and_destroy(); init(size); };
152 const char*
c_str()
const {
return mem ==
nullptr ?
throw SRC_BUG : mem; };
153 char*
c_str() {
return mem ==
nullptr ?
throw SRC_BUG : mem; };
154 void set_size(U_I size);
157 char *
get_array() {
return mem ==
nullptr ?
throw SRC_BUG : mem; };
163 char operator[](U_I index)
const {
return (const_cast<secu_string *>(
this))->operator[](index); };
166 U_I
get_size()
const {
if(string_size ==
nullptr)
throw SRC_BUG;
return *string_size; };
169 bool empty()
const {
if(string_size ==
nullptr)
throw SRC_BUG;
return *string_size == 0; };
179 void nullifyptr() noexcept { allocated_size = string_size =
nullptr; mem =
nullptr; };
182 void move_from(
secu_string && ref) noexcept { std::swap(allocated_size, ref.allocated_size); std::swap(mem, ref.mem); std::swap(string_size, ref.string_size); };
183 bool compare_with(
const char *ptr, U_I size)
const;
184 void clean_and_destroy();
secu_string(const char *ptr, U_I size)
constructor 2
U_I get_allocated_size() const
get the size of the allocated secure space
are defined here basic integer types that tend to be portable
char * get_array()
non constant flavor of direct secure memory access
void randomize(U_I size)
set the string to randomize string of given size
void append(const char *ptr, U_I size)
append some data at the end of the string
secu_string(const secu_string &ref)
the copy constructor
static bool is_string_secured()
to know if secure memory is available
secu_string & operator=(const secu_string &ref)
the assignment operator
void reduce_string_size_to(U_I pos)
void expand_string_size_to(U_I size)
set the string size within the allocated secure memory
void clear()
clear the string (set to an empty string)
void set(int fd, U_I size)
fill the object with data
contains all the excetion class thrown by libdar
secu_string(secu_string &&ref) noexcept
the move constructor
char & operator[](U_I index)
get access to the secure string by index
bool empty() const
tell whether string is empty
~secu_string() noexcept
the destructor (set memory to zero before releasing it)
secu_string(U_I storage_size=0)
constructor 1
void append(int fd, U_I size)
append some data at the end of the string
U_I get_size() const
get the size of the string
void resize(U_I size)
clear and resize the string to the defined allocated size
void append_at(U_I offset, const char *ptr, U_I size)
append some data to the string at a given offset
const char * c_str() const
get access to the secure string
libdar namespace encapsulate all libdar symbols