libkeepass 0.2.0
KeePass key database importer/exporter library
Loading...
Searching...
No Matches
keepass::SecureBytes Class Reference

Dynamic byte buffer that is zeroized in best-effort locked memory. More...

#include <secure.hh>

Public Member Functions

 SecureBytes ()=default
 Default-constructs an empty buffer.
 
 SecureBytes (const uint8_t *data, std::size_t size)
 Constructs a buffer by copying the given bytes.
 
 SecureBytes (const std::vector< uint8_t > &data)
 Constructs a buffer by copying the given byte vector.
 
 ~SecureBytes ()
 Zeroizes and releases the stored bytes.
 
 SecureBytes (const SecureBytes &)=delete
 No implicit copies of key material.
 
SecureBytes & operator= (const SecureBytes &)=delete
 No implicit copies of key material.
 
 SecureBytes (SecureBytes &&other) noexcept
 Move-constructs by transferring the bytes and wiping the source.
 
SecureBytes & operator= (SecureBytes &&other) noexcept
 
SecureBytes & operator= (const std::vector< uint8_t > &data)
 Replaces the content with a copy of the given byte vector.
 
uint8_t * data () noexcept
 Returns a pointer to the raw bytes.
 
const uint8_t * data () const noexcept
 Returns a const pointer to the raw bytes.
 
std::size_t size () const noexcept
 Returns the size of the buffer in bytes.
 
bool empty () const noexcept
 Returns whether the buffer is empty.
 
uint8_t * begin () noexcept
 Returns an iterator to the first byte.
 
uint8_t * end () noexcept
 Returns an iterator past the last byte.
 
const uint8_t * begin () const noexcept
 Returns a const iterator to the first byte.
 
const uint8_t * end () const noexcept
 Returns a const iterator past the last byte.
 
uint8_t & operator[] (std::size_t index) noexcept
 Returns the byte at the given index.
 
const uint8_t & operator[] (std::size_t index) const noexcept
 Returns the byte at the given index.
 
void Assign (const uint8_t *data, std::size_t size)
 Replaces the content with a copy of the given bytes.
 
void Assign (const std::vector< uint8_t > &data)
 Replaces the content with a copy of the given byte vector.
 
void Clear () noexcept
 Erases and releases the stored bytes.
 
SecureBytes Clone () const
 Returns an explicit deep copy of the buffer.
 
bool operator== (const SecureBytes &other) const
 Returns whether two buffers hold the same bytes.
 
bool operator!= (const SecureBytes &other) const
 Returns whether two buffers hold different bytes.
 

Detailed Description

Dynamic byte buffer that is zeroized in best-effort locked memory.

SecureBytes stores an arbitrary number of seed or key-material bytes in a separately allocated, zeroized (and best-effort locked, see secure_alloc()) heap buffer. The content is erased when the buffer is destroyed, moved-from, assigned over or cleared. SecureBytes is move-only; use Clone() to create an explicit deep copy.

Constructor & Destructor Documentation

◆ SecureBytes()

keepass::SecureBytes::SecureBytes ( const uint8_t *  data,
std::size_t  size 
)

Constructs a buffer by copying the given bytes.

Parameters
dataPointer to the source bytes (ignored if size is zero).
sizeNumber of bytes to copy.

Member Function Documentation

◆ operator=()

SecureBytes & keepass::SecureBytes::operator= ( SecureBytes &&  other)
noexcept

Move-assigns by transferring the bytes and wiping the previous and the source content.


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