Offline Transaction Signing (OTS) 0.1.0
Loading...
Searching...
No Matches
ots::WipeableString Class Reference

String class that wipes its memory on destruction. More...

#include <ots.hpp>

Public Member Functions

 WipeableString () noexcept=default
 Default constructor.
 
 WipeableString (const std::string &s)
 Construct from std::string.
 
 WipeableString (const char *s)
 Construct from C-string.
 
 WipeableString (const char *s, size_t n)
 Construct from string and length.
 
 WipeableString (const WipeableString &other)
 Copy constructor.
 
 WipeableString (WipeableString &&other) noexcept
 Move constructor.
 
WipeableStringoperator= (const WipeableString &other)
 Copy assignment operator.
 
WipeableStringoperator= (WipeableString &&other) noexcept
 Move assignment operator.
 
WipeableStringoperator= (const char *s)
 Assignment operator for C-string.
 
 ~WipeableString ()
 Destructor that wipes memory.
 
std::string insecure () const noexcept
 Create an insecure std::string copy.
 
const char * c_str () const noexcept
 Get C-string representation.
 
const char * data () const noexcept
 Get string data.
 
size_t size () const noexcept
 Get string length.
 
bool empty () const noexcept
 Check if string is empty.
 
void clear () noexcept
 Clear string content.
 
size_t capacity () const noexcept
 Get string capacity.
 
void reserve (size_t n)
 Reserve memory for string.
 
WipeableString substr (size_t pos=0, size_t len=std::string::npos) const
 Get substring.
 
size_t find (const WipeableString &str, size_t pos=0) const noexcept
 Find substring.
 
size_t find (const char *s, size_t pos=0) const noexcept
 Find C-string.
 
WipeableStringappend (const WipeableString &str)
 Append string.
 
WipeableStringappend (const char *s)
 Append C-string.
 
WipeableStringoperator+= (const WipeableString &str)
 Append operator.
 
WipeableStringoperator+= (const char *s)
 Append C-string operator.
 
bool operator== (const WipeableString &other) const noexcept
 Compare with another WipeableString.
 
bool operator!= (const WipeableString &other) const noexcept
 Compare inequality with another WipeableString.
 
 operator std::string () const
 Conversion to std::string is explicitly prevented.
 
int compare (const WipeableString &other) const noexcept
 Compare strings.
 

Static Public Attributes

static constexpr size_t npos = std::string::npos
 Static npos value.
 

Friends

std::ostream & operator<< (std::ostream &os, const WipeableString &str)
 Stream output operator.
 

Detailed Description

String class that wipes its memory on destruction.

Note
This class helps prevent sensitive data from remaining in memory, but does not guarantee complete memory security

Constructor & Destructor Documentation

◆ WipeableString() [1/6]

ots::WipeableString::WipeableString ( )
defaultnoexcept

Default constructor.

◆ WipeableString() [2/6]

ots::WipeableString::WipeableString ( const std::string &  s)
inlineexplicit

Construct from std::string.

◆ WipeableString() [3/6]

ots::WipeableString::WipeableString ( const char *  s)
explicit

Construct from C-string.

◆ WipeableString() [4/6]

ots::WipeableString::WipeableString ( const char *  s,
size_t  n 
)

Construct from string and length.

◆ WipeableString() [5/6]

ots::WipeableString::WipeableString ( const WipeableString other)

Copy constructor.

◆ WipeableString() [6/6]

ots::WipeableString::WipeableString ( WipeableString &&  other)
noexcept

Move constructor.

◆ ~WipeableString()

ots::WipeableString::~WipeableString ( )

Destructor that wipes memory.

Member Function Documentation

◆ append() [1/2]

WipeableString & ots::WipeableString::append ( const char *  s)

Append C-string.

◆ append() [2/2]

WipeableString & ots::WipeableString::append ( const WipeableString str)

Append string.

◆ c_str()

const char * ots::WipeableString::c_str ( ) const
noexcept

Get C-string representation.

◆ capacity()

size_t ots::WipeableString::capacity ( ) const
noexcept

Get string capacity.

◆ clear()

void ots::WipeableString::clear ( )
noexcept

Clear string content.

◆ compare()

int ots::WipeableString::compare ( const WipeableString other) const
noexcept

Compare strings.

◆ data()

const char * ots::WipeableString::data ( ) const
noexcept

Get string data.

◆ empty()

bool ots::WipeableString::empty ( ) const
noexcept

Check if string is empty.

◆ find() [1/2]

size_t ots::WipeableString::find ( const char *  s,
size_t  pos = 0 
) const
noexcept

Find C-string.

◆ find() [2/2]

size_t ots::WipeableString::find ( const WipeableString str,
size_t  pos = 0 
) const
noexcept

Find substring.

◆ insecure()

std::string ots::WipeableString::insecure ( ) const
noexcept

Create an insecure std::string copy.

Warning
The returned string will not be wiped from memory automatically. Use only if you are sure what you are and why you are doing.

◆ operator std::string()

ots::WipeableString::operator std::string ( ) const

Conversion to std::string is explicitly prevented.

Exceptions
ots::exception::wipeablestring::UnsafeConversion
Warning
This is done to prevent accidental insecure conversions of sensitive data. Use insecure() method to get an insecure copy of the string if you really need it.

◆ operator!=()

bool ots::WipeableString::operator!= ( const WipeableString other) const
noexcept

Compare inequality with another WipeableString.

◆ operator+=() [1/2]

WipeableString & ots::WipeableString::operator+= ( const char *  s)

Append C-string operator.

◆ operator+=() [2/2]

WipeableString & ots::WipeableString::operator+= ( const WipeableString str)

Append operator.

◆ operator=() [1/3]

WipeableString & ots::WipeableString::operator= ( const char *  s)

Assignment operator for C-string.

◆ operator=() [2/3]

WipeableString & ots::WipeableString::operator= ( const WipeableString other)

Copy assignment operator.

◆ operator=() [3/3]

WipeableString & ots::WipeableString::operator= ( WipeableString &&  other)
noexcept

Move assignment operator.

◆ operator==()

bool ots::WipeableString::operator== ( const WipeableString other) const
noexcept

Compare with another WipeableString.

◆ reserve()

void ots::WipeableString::reserve ( size_t  n)

Reserve memory for string.

◆ size()

size_t ots::WipeableString::size ( ) const
noexcept

Get string length.

◆ substr()

WipeableString ots::WipeableString::substr ( size_t  pos = 0,
size_t  len = std::string::npos 
) const

Get substring.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const WipeableString str 
)
friend

Stream output operator.

Member Data Documentation

◆ npos

constexpr size_t ots::WipeableString::npos = std::string::npos
staticconstexpr

Static npos value.


The documentation for this class was generated from the following files: