32#ifndef SECU_STRING_HPP
33#define SECU_STRING_HPP
35#include "//include/dar/libdar_my_config.h"
38#include "//include/dar/integers.hpp"
39#include "//include/dar/erreurs.hpp"
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)); };
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; };
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();
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
void append(int fd, U_I size)
append some data at the end of the string
bool empty() const
tell whether string is empty
const char * c_str() const
get access to the secure string
U_I get_allocated_size() const
get the size of the allocated secure space
void set(int fd, U_I size)
fill the object with data
secu_string(const secu_string &ref)
the copy constructor
void randomize(U_I size)
set the string to randomize string of given size
~secu_string() noexcept
the destructor (set memory to zero before releasing it)
secu_string(const char *ptr, U_I size)
constructor 2
U_I get_size() const
get the size of the string
secu_string & operator=(const secu_string &ref)
the assignment operator
void clear()
clear the string (set to an empty string)
char & operator[](U_I index)
get access to the secure string by index
secu_string(secu_string &&ref) noexcept
the move constructor
void append_at(U_I offset, int fd, U_I size)
append some data to the string
void expand_string_size_to(U_I size)
set the string size within the allocated secure memory
secu_string(U_I storage_size=0)
constructor 1
static bool is_string_secured()
to know if secure memory is available
char * get_array()
non constant flavor of direct secure memory access
void reduce_string_size_to(U_I pos)
void append(const char *ptr, U_I size)
append some data at the end of the string
libdar namespace encapsulate all libdar symbols