libkeepass 0.2.0
KeePass key database importer/exporter library
Loading...
Searching...
No Matches
keepass::protect< T > Class Template Reference

Wrapper that marks a value as sensitive and tracks the protection flag of a KeePass field. More...

#include <security.hh>

Public Member Functions

 protect ()=default
 Default-constructs an empty protected wrapper.
 
 protect (const T &val, bool prot)
 Constructs a protected wrapper with an explicit protection flag.
 
 protect (T &&val, bool prot)
 Constructs a protected wrapper by moving a value in.
 
 protect (const protect< T > &other)
 Copy-constructs from another protected wrapper.
 
 protect (protect< T > &&other) noexcept
 Move-constructs from another protected wrapper.
 
bool is_protected () const
 Returns whether the value is marked as sensitive.
 
void set_protected (bool prot)
 Sets the protection flag.
 
const T & value () const
 Returns a const reference to the stored value.
 
void set_value (const T &val)
 Replaces the stored value.
 
protect< T > & operator= (const protect< T > &)=default
 Copy-assigns from another protected wrapper.
 
protect< T > & operator= (protect< T > &&other) noexcept
 Move-assigns from another protected wrapper.
 
 operator const T & () const
 Explicit conversion operator to the wrapped type.
 
const T * operator-> () const
 Arrow operator forwarding to the stored value.
 
const T & operator* () const
 Dereference operator forwarding to the stored value.
 
bool operator== (const protect< T > &other) const
 Equality comparison of two protected wrappers.
 
bool operator!= (const protect< T > &other) const
 Inequality comparison of two protected wrappers.
 

Detailed Description

template<typename T>
class keepass::protect< T >

Wrapper that marks a value as sensitive and tracks the protection flag of a KeePass field.

The wrapped value is stored in plaintext; protection here means that the value is flagged as sensitive (e.g. a password) and is written to the KDBX output obfuscated through the inner random stream (Salsa20/ChaCha20). For secret text fields prefer protect<secure_string>, which additionally keeps the value on a non-swappable, zeroized heap buffer.

Template Parameters
TThe wrapped value type.

Constructor & Destructor Documentation

◆ protect() [1/4]

template<typename T >
keepass::protect< T >::protect ( const T &  val,
bool  prot 
)
inline

Constructs a protected wrapper with an explicit protection flag.

Parameters
[in]valInitial value.
[in]protWhether the value is sensitive.

◆ protect() [2/4]

template<typename T >
keepass::protect< T >::protect ( T &&  val,
bool  prot 
)
inline

Constructs a protected wrapper by moving a value in.

Parameters
[in,out]valInitial value (moved from).
[in]protWhether the value is sensitive.

◆ protect() [3/4]

template<typename T >
keepass::protect< T >::protect ( const protect< T > &  other)
inline

Copy-constructs from another protected wrapper.

Parameters
[in]otherSource wrapper.

◆ protect() [4/4]

template<typename T >
keepass::protect< T >::protect ( protect< T > &&  other)
inlinenoexcept

Move-constructs from another protected wrapper.

Parameters
[in,out]otherSource wrapper (moved from).

Member Function Documentation

◆ is_protected()

template<typename T >
bool keepass::protect< T >::is_protected ( ) const
inline

Returns whether the value is marked as sensitive.

Returns
true if the value is protected, false otherwise.

◆ operator const T &()

template<typename T >
keepass::protect< T >::operator const T & ( ) const
inlineexplicit

Explicit conversion operator to the wrapped type.

Returns
Const reference to the value.

◆ operator!=()

template<typename T >
bool keepass::protect< T >::operator!= ( const protect< T > &  other) const
inline

Inequality comparison of two protected wrappers.

Parameters
[in]otherRight-hand side.
Returns
true if the wrappers are not equal.

◆ operator*()

template<typename T >
const T & keepass::protect< T >::operator* ( ) const
inline

Dereference operator forwarding to the stored value.

Returns
Const reference to the value.

◆ operator->()

template<typename T >
const T * keepass::protect< T >::operator-> ( ) const
inline

Arrow operator forwarding to the stored value.

Returns
Pointer to the value.

◆ operator=() [1/2]

template<typename T >
protect< T > & keepass::protect< T >::operator= ( const protect< T > &  )
default

Copy-assigns from another protected wrapper.

Parameters
[in]otherSource wrapper.
Returns
Reference to this object.

◆ operator=() [2/2]

template<typename T >
protect< T > & keepass::protect< T >::operator= ( protect< T > &&  other)
inlinenoexcept

Move-assigns from another protected wrapper.

Parameters
[in,out]otherSource wrapper (moved from).
Returns
Reference to this object.

◆ operator==()

template<typename T >
bool keepass::protect< T >::operator== ( const protect< T > &  other) const
inline

Equality comparison of two protected wrappers.

Parameters
[in]otherRight-hand side.
Returns
true if both value and protection flag are equal.

◆ set_protected()

template<typename T >
void keepass::protect< T >::set_protected ( bool  prot)
inline

Sets the protection flag.

Parameters
[in]protNew protection state.

◆ set_value()

template<typename T >
void keepass::protect< T >::set_value ( const T &  val)
inline

Replaces the stored value.

Parameters
[in]valNew value.

◆ value()

template<typename T >
const T & keepass::protect< T >::value ( ) const
inline

Returns a const reference to the stored value.

Returns
Const reference to the value.

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