StormByte 3.0.0
C++26 foundation of the StormByte suite
Loading...
Searching...
No Matches
StormByte::Safe::Binary Class Reference

Owned contiguous sequence of std::byte, stored in a Vector. More...

#include <StormByte/safe/binary.hxx>

Inheritance diagram for StormByte::Safe::Binary:

Public Types

using value_type = std::byte
 Element type.
using size_type = Size
 Count typedef. size() returns ByteSize.
using difference_type = std::ptrdiff_t
 Iterator difference.
using reference = std::byte&
 Mutable element reference.
using const_reference = const std::byte&
 Read-only element reference.
using pointer = std::byte*
 Mutable pointer.
using const_pointer = const std::byte*
 Read-only pointer.
using iterator = std::byte*
 Contiguous mutable iterator.
using const_iterator = const std::byte*
 Contiguous read-only iterator.
using reverse_iterator = std::reverse_iterator<iterator>
 Reverse iterator.
using const_reverse_iterator = std::reverse_iterator<const_iterator>
 Read-only reverse iterator.

Public Member Functions

 Binary () noexcept
 Construct an empty sequence.
 Binary (const ByteSize &count, std::byte value)
 Construct count bytes filled with value.
 Binary (const ByteSize &count)
 Construct count zeroed bytes.
 Binary (std::span< const std::byte > bytes)
 Copy bytes from a contiguous span.
 Binary (const std::byte *bytes, const ByteSize &count)
 Copy count bytes starting at bytes.
 Binary (std::initializer_list< std::byte > list)
 Copy from an initializer list.
 Binary (std::string_view text)
 Copy character bytes from a string view.
 Binary (const char *text)
 Copy character bytes from a C string.
STORMBYTE_FORCE_INLINE Binary (const std::vector< std::byte > &bytes)
 Copy bytes from a caller-owned vector.
STORMBYTE_FORCE_INLINE Binary (std::vector< std::byte > &&bytes)
 Copy bytes from a caller-owned vector, then empty it.
template<Type::ByteInputRange R>
 Binary (const R &range)
 Copy from an input range of byte-convertible values.
template<Type::ByteInputRange R>
 Binary (R &&range)
 Consume an rvalue range.
 Binary (const Binary &other)
 Copy construct.
 Binary (Binary &&other) noexcept
 Move construct.
virtual ~Binary () noexcept
 Destroy the sequence on Base's heap.
Binary & operator= (const Binary &other)
 Copy assign.
Binary & operator= (Binary &&other) noexcept
 Move assign.
Binary & operator= (std::initializer_list< std::byte > list)
 Replace contents with an initializer list.
bool operator== (const Binary &other) const noexcept
 Equality of byte contents.
bool operator!= (const Binary &other) const noexcept
 Inequality of byte contents.
STORMBYTE_FORCE_INLINE std::strong_ordering operator<=> (const Binary &other) const noexcept
 Three-way lexicographical comparison.
bool operator== (std::span< const std::byte > bytes) const noexcept
 Equality with a byte span.
bool operator!= (std::span< const std::byte > bytes) const noexcept
 Inequality with a byte span.
STORMBYTE_FORCE_INLINE std::strong_ordering operator<=> (std::span< const std::byte > bytes) const noexcept
 Three-way comparison with a byte span.
iterator begin () noexcept
 Mutable iterator to the first byte.
const_iterator begin () const noexcept
 Read-only iterator to the first byte.
iterator end () noexcept
 Mutable iterator one past the last byte.
const_iterator end () const noexcept
 Read-only iterator one past the last byte.
const_iterator cbegin () const noexcept
 Read-only iterator to the first byte.
const_iterator cend () const noexcept
 Read-only iterator one past the last byte.
reverse_iterator rbegin () noexcept
 Mutable reverse iterator to the last byte.
reverse_iterator rend () noexcept
 Mutable reverse iterator before the first byte.
const_reverse_iterator rbegin () const noexcept
 Read-only reverse iterator to the last byte.
const_reverse_iterator rend () const noexcept
 Read-only reverse iterator before the first byte.
const_reverse_iterator crbegin () const noexcept
 Read-only reverse iterator to the last byte.
const_reverse_iterator crend () const noexcept
 Read-only reverse iterator before the first byte.
ByteSize size () const noexcept
 Occupied length in bytes.
ByteSize max_size () const noexcept
 Implementation maximum size in bytes.
ByteSize capacity () const noexcept
 Allocated capacity in bytes.
bool empty () const noexcept
 Whether the sequence holds no bytes.
void reserve (const ByteSize &new_cap)
 Request capacity of at least new_cap bytes.
void resize (const ByteSize &new_size)
 Resize to new_size bytes.
void resize (const ByteSize &new_size, std::byte value)
 Resize to new_size bytes.
void shrink_to_fit ()
 Release unused capacity when the implementation allows it.
void clear () noexcept
 Drop every byte.
std::byte & operator[] (const ByteSize &index) noexcept
 Unchecked mutable subscript.
const std::byte & operator[] (const ByteSize &index) const noexcept
 Unchecked read-only subscript.
std::byte & at (const ByteSize &index)
 Checked mutable subscript.
const std::byte & at (const ByteSize &index) const
 Checked read-only subscript.
std::byte & front ()
 First byte.
const std::byte & front () const
 First byte.
std::byte & back ()
 Last byte.
const std::byte & back () const
 Last byte.
std::byte * data () noexcept
 Mutable pointer to the first byte, or null when empty.
const std::byte * data () const noexcept
 Read-only pointer to the first byte, or null when empty.
STORMBYTE_FORCE_INLINE std::span< std::byte > span () noexcept
 Mutable view of the occupied bytes.
STORMBYTE_FORCE_INLINE std::span< const std::byte > span () const noexcept
 Read-only view of the occupied bytes.
STORMBYTE_FORCE_INLINE operator std::span< std::byte > () noexcept
 Implicit mutable span conversion.
STORMBYTE_FORCE_INLINE operator std::span< const std::byte > () const noexcept
 Implicit read-only span conversion.
STORMBYTE_FORCE_INLINE operator std::vector< std::byte > () const &
 Copy bytes onto the caller CRT as a vector.
STORMBYTE_FORCE_INLINE operator std::vector< std::byte > () &&
 Copy bytes onto the caller CRT, then release this object's storage.
void assign (const ByteSize &count, std::byte value)
 Replace contents with count copies of value.
void assign (std::span< const std::byte > bytes)
 Replace contents with a copy of bytes.
void assign (std::initializer_list< std::byte > list)
 Replace contents with an initializer list.
template<typename InputIt>
void assign (InputIt first, InputIt last)
 Replace contents with the range [first, last).
void append (std::span< const std::byte > bytes)
 Append a copy of bytes.
void append (const std::byte *bytes, const ByteSize &count)
 Append count bytes starting at bytes.
void append (const Binary &other)
 Append a copy of other.
void append (Binary &&other)
 Append other, then empty it.
Binary & operator+= (std::span< const std::byte > bytes)
 Append a copy of bytes.
Binary & operator+= (const Binary &other)
 Append a copy of other.
Binary & operator+= (Binary &&other)
 Append other, then empty it.
void push_back (std::byte value)
 Append one byte.
template<typename T>
reference emplace_back (T &&value)
 Append a byte constructed in place.
void pop_back ()
 Remove the last byte.
iterator insert (const_iterator pos, std::byte value)
 Insert one byte before pos.
iterator insert (const_iterator pos, const ByteSize &count, std::byte value)
 Insert count copies of value before pos.
iterator insert (const_iterator pos, std::initializer_list< std::byte > list)
 Insert an initializer list before pos.
iterator insert (const_iterator pos, std::span< const std::byte > bytes)
 Insert a span before pos.
template<typename InputIt>
iterator insert (const_iterator pos, InputIt first, InputIt last)
 Insert the range [first, last) before pos.
iterator erase (const_iterator pos)
 Erase the byte at pos.
iterator erase (const_iterator first, const_iterator last)
 Erase [first, last).
void swap (Binary &other) noexcept
 Exchange storage with other.
String HexDump () const
 Hexadecimal dump, sixteen bytes per row.
String HexDump (Size columns) const
 Hexadecimal dump of the occupied bytes.

Protected Member Functions

virtual void Discard (std::span< std::byte > bytes) noexcept
 Called with every byte range this sequence is about to drop or release.
virtual bool ConstantTimeCompare () const noexcept
 Whether equality must not depend on where the bytes differ.
virtual void Acquire (std::span< std::byte > block) noexcept
 Called when an allocated block becomes owned by this object: a new block on growth or shrinking, or a block taken from another sequence by move assignment or swap.
virtual void Release (std::span< std::byte > block) noexcept
 Called when a block stops being owned by this object: the old block after a reallocation, or a block handed to another sequence by a move or swap.
std::span< std::byte > Storage () noexcept
 The whole allocated block, including unused capacity.

Static Protected Member Functions

static void Wipe (std::span< std::byte > bytes) noexcept
 Zero bytes.

Detailed Description

Owned contiguous sequence of std::byte, stored in a Vector.

There is no separate backend. Bytes live in Vector of std::byte, allocated with Heap::Allocate. Names match std::vector. Length, capacity and offsets are ByteSize. A hex-dump column count is Size.

A conversion to std::vector copies into the caller. It does not steal the Base pointer. An rvalue overload empties this object after the copy.

The class can be derived. Every byte the sequence drops is first passed to Discard: erased or popped bytes, the shrunk tail, previous contents on assign, and the whole old block when the storage is reallocated. Every allocated block that enters or leaves the object, by reallocation, move or swap, goes through Acquire and Release. SecureBinary overrides them to zero the bytes and lock the pages. A plain Binary does nothing there.

Member Typedef Documentation

◆ const_iterator

using StormByte::Safe::Binary::const_iterator = const std::byte*

Contiguous read-only iterator.

◆ const_pointer

using StormByte::Safe::Binary::const_pointer = const std::byte*

Read-only pointer.

◆ const_reference

using StormByte::Safe::Binary::const_reference = const std::byte&

Read-only element reference.

◆ const_reverse_iterator

Read-only reverse iterator.

◆ difference_type

Iterator difference.

◆ iterator

Contiguous mutable iterator.

◆ pointer

Mutable pointer.

◆ reference

Mutable element reference.

◆ reverse_iterator

using StormByte::Safe::Binary::reverse_iterator = std::reverse_iterator<iterator>

Reverse iterator.

◆ size_type

Count typedef. size() returns ByteSize.

◆ value_type

Element type.

Constructor & Destructor Documentation

◆ Binary() [1/14]

StormByte::Safe::Binary::Binary ( )
noexcept

Construct an empty sequence.

◆ Binary() [2/14]

StormByte::Safe::Binary::Binary ( const ByteSize & count,
std::byte value )

Construct count bytes filled with value.

Parameters
countElement count.
valueFill byte.

◆ Binary() [3/14]

StormByte::Safe::Binary::Binary ( const ByteSize & count)
explicit

Construct count zeroed bytes.

Parameters
countElement count.

◆ Binary() [4/14]

StormByte::Safe::Binary::Binary ( std::span< const std::byte > bytes)
explicit

Copy bytes from a contiguous span.

Parameters
bytesSource view. Not owned.

◆ Binary() [5/14]

StormByte::Safe::Binary::Binary ( const std::byte * bytes,
const ByteSize & count )

Copy count bytes starting at bytes.

Parameters
bytesSource pointer. May be null when count is zero.
countByte count.
Exceptions
OutOfBoundsErrorbytes is null and count is not zero.

◆ Binary() [6/14]

StormByte::Safe::Binary::Binary ( std::initializer_list< std::byte > list)

Copy from an initializer list.

Parameters
listSource bytes.

◆ Binary() [7/14]

StormByte::Safe::Binary::Binary ( std::string_view text)
explicit

Copy character bytes from a string view.

No trailing NUL.

Parameters
textSource characters.

◆ Binary() [8/14]

StormByte::Safe::Binary::Binary ( const char * text)
explicit

Copy character bytes from a C string.

No trailing NUL.

Parameters
textSource. A null pointer yields an empty sequence.

◆ Binary() [9/14]

STORMBYTE_FORCE_INLINE StormByte::Safe::Binary::Binary ( const std::vector< std::byte > & bytes)
inlineexplicit

Copy bytes from a caller-owned vector.

The vector is unchanged.

Parameters
bytesSource.

◆ Binary() [10/14]

STORMBYTE_FORCE_INLINE StormByte::Safe::Binary::Binary ( std::vector< std::byte > && bytes)
inlineexplicit

Copy bytes from a caller-owned vector, then empty it.

Parameters
bytesSource. Cleared after the copy. Not a heap steal.

◆ Binary() [11/14]

template<Type::ByteInputRange R>
StormByte::Safe::Binary::Binary ( const R & range)
explicit

Copy from an input range of byte-convertible values.

Template Parameters
RRange type satisfying Type::ByteInputRange.
Parameters
rangeSource range.

◆ Binary() [12/14]

template<Type::ByteInputRange R>
StormByte::Safe::Binary::Binary ( R && range)
explicit

Consume an rvalue range.

Moves when R is an rvalue Binary.

Template Parameters
RRange type satisfying Type::ByteInputRange.
Parameters
rangeSource range.

◆ Binary() [13/14]

StormByte::Safe::Binary::Binary ( const Binary & other)

Copy construct.

Parameters
otherSource sequence.

◆ Binary() [14/14]

StormByte::Safe::Binary::Binary ( Binary && other)
noexcept

Move construct.

other is left empty and gets Release for its block. Acquire is not called on this object: a derived constructor that keeps the block calls it, or takes the block by move assignment in its body.

Parameters
otherSource sequence.

◆ ~Binary()

virtual StormByte::Safe::Binary::~Binary ( )
virtualnoexcept

Destroy the sequence on Base's heap.

Note
Discard and Release are not called here: a derived class wipes and releases its own storage in its destructor.

Member Function Documentation

◆ Acquire()

virtual void StormByte::Safe::Binary::Acquire ( std::span< std::byte > block)
protectedvirtualnoexcept

Called when an allocated block becomes owned by this object: a new block on growth or shrinking, or a block taken from another sequence by move assignment or swap.

Called before the bytes are copied in. Every block passed here is later passed once to Release, unless this object is destroyed while owning it. Default does nothing. Not called from constructors: a derived constructor that takes a block from its base calls it itself.

Parameters
blockWhole block, including unused capacity.

Reimplemented in StormByte::Safe::SecureBinary.

◆ append() [1/4]

void StormByte::Safe::Binary::append ( Binary && other)

Append other, then empty it.

Parameters
otherSource sequence. Empty afterwards when it is not this object.

◆ append() [2/4]

void StormByte::Safe::Binary::append ( const Binary & other)

Append a copy of other.

Parameters
otherSource sequence.

◆ append() [3/4]

void StormByte::Safe::Binary::append ( const std::byte * bytes,
const ByteSize & count )

Append count bytes starting at bytes.

Parameters
bytesSource pointer. May be null when count is zero.
countByte count.
Exceptions
OutOfBoundsErrorbytes is null and count is not zero.

◆ append() [4/4]

void StormByte::Safe::Binary::append ( std::span< const std::byte > bytes)

Append a copy of bytes.

Parameters
bytesSource view.

◆ assign() [1/4]

void StormByte::Safe::Binary::assign ( const ByteSize & count,
std::byte value )

Replace contents with count copies of value.

Parameters
countNew size.
valueFill byte.

◆ assign() [2/4]

template<typename InputIt>
void StormByte::Safe::Binary::assign ( InputIt first,
InputIt last )

Replace contents with the range [first, last).

Template Parameters
InputItInput iterator whose value converts to std::byte.
Parameters
firstStart of the source range.
lastEnd of the source range.

◆ assign() [3/4]

void StormByte::Safe::Binary::assign ( std::initializer_list< std::byte > list)

Replace contents with an initializer list.

Parameters
listSource bytes.

◆ assign() [4/4]

void StormByte::Safe::Binary::assign ( std::span< const std::byte > bytes)

Replace contents with a copy of bytes.

Parameters
bytesSource view.

◆ at() [1/2]

std::byte & StormByte::Safe::Binary::at ( const ByteSize & index)

Checked mutable subscript.

Parameters
indexByte offset.
Returns
Byte at index.
Exceptions
OutOfBoundsErrorindex is not less than size().

◆ at() [2/2]

const std::byte & StormByte::Safe::Binary::at ( const ByteSize & index) const

Checked read-only subscript.

Parameters
indexByte offset.
Returns
Byte at index.
Exceptions
OutOfBoundsErrorindex is not less than size().

◆ back() [1/2]

std::byte & StormByte::Safe::Binary::back ( )

Last byte.

Returns
Last byte.

◆ back() [2/2]

const std::byte & StormByte::Safe::Binary::back ( ) const

Last byte.

Returns
Last byte.

◆ begin() [1/2]

const_iterator StormByte::Safe::Binary::begin ( ) const
noexcept

Read-only iterator to the first byte.

Returns
First byte, or a valid empty iterator.

◆ begin() [2/2]

iterator StormByte::Safe::Binary::begin ( )
noexcept

Mutable iterator to the first byte.

Returns
First byte, or a valid empty iterator.

◆ capacity()

ByteSize StormByte::Safe::Binary::capacity ( ) const
noexcept

Allocated capacity in bytes.

Returns
Capacity.

◆ cbegin()

const_iterator StormByte::Safe::Binary::cbegin ( ) const
noexcept

Read-only iterator to the first byte.

Returns
Same as const begin().

◆ cend()

const_iterator StormByte::Safe::Binary::cend ( ) const
noexcept

Read-only iterator one past the last byte.

Returns
Same as const end().

◆ clear()

void StormByte::Safe::Binary::clear ( )
noexcept

Drop every byte.

Capacity may remain.

◆ ConstantTimeCompare()

virtual bool StormByte::Safe::Binary::ConstantTimeCompare ( ) const
protectedvirtualnoexcept

Whether equality must not depend on where the bytes differ.

Returns
False here. SecureBinary returns true.

Reimplemented in StormByte::Safe::SecureBinary.

◆ crbegin()

const_reverse_iterator StormByte::Safe::Binary::crbegin ( ) const
noexcept

Read-only reverse iterator to the last byte.

Returns
Same as const rbegin().

◆ crend()

const_reverse_iterator StormByte::Safe::Binary::crend ( ) const
noexcept

Read-only reverse iterator before the first byte.

Returns
Same as const rend().

◆ data() [1/2]

const std::byte * StormByte::Safe::Binary::data ( ) const
noexcept

Read-only pointer to the first byte, or null when empty.

Returns
Contiguous storage.

◆ data() [2/2]

std::byte * StormByte::Safe::Binary::data ( )
noexcept

Mutable pointer to the first byte, or null when empty.

Returns
Contiguous storage.

◆ Discard()

virtual void StormByte::Safe::Binary::Discard ( std::span< std::byte > bytes)
protectedvirtualnoexcept

Called with every byte range this sequence is about to drop or release.

Default does nothing. Not called from constructors or from the destructor, where the call would not reach the derived class.

Parameters
bytesBytes to dispose of. They stay owned by this object.

Reimplemented in StormByte::Safe::SecureBinary.

◆ emplace_back()

template<typename T>
Binary::reference StormByte::Safe::Binary::emplace_back ( T && value)

Append a byte constructed in place.

Template Parameters
TValue convertible to std::byte.
Parameters
valueArgument forwarded into std::byte.
Returns
Reference to the appended byte.

◆ empty()

bool StormByte::Safe::Binary::empty ( ) const
noexcept

Whether the sequence holds no bytes.

Returns
Whether size() is zero.

◆ end() [1/2]

const_iterator StormByte::Safe::Binary::end ( ) const
noexcept

Read-only iterator one past the last byte.

Returns
Past-the-end iterator.

◆ end() [2/2]

iterator StormByte::Safe::Binary::end ( )
noexcept

Mutable iterator one past the last byte.

Returns
Past-the-end iterator.

◆ erase() [1/2]

iterator StormByte::Safe::Binary::erase ( const_iterator first,
const_iterator last )

Erase [first, last).

Parameters
firstStart of the range.
lastEnd of the range.
Returns
Iterator following the last erased byte.

◆ erase() [2/2]

iterator StormByte::Safe::Binary::erase ( const_iterator pos)

Erase the byte at pos.

Parameters
posByte to erase.
Returns
Iterator following the erased byte.

◆ front() [1/2]

std::byte & StormByte::Safe::Binary::front ( )

First byte.

Returns
First byte.

◆ front() [2/2]

const std::byte & StormByte::Safe::Binary::front ( ) const

First byte.

Returns
First byte.

◆ HexDump() [1/2]

String StormByte::Safe::Binary::HexDump ( ) const

Hexadecimal dump, sixteen bytes per row.

Returns
Dump text owned by Base. Empty when this sequence is empty.

◆ HexDump() [2/2]

String StormByte::Safe::Binary::HexDump ( Size columns) const

Hexadecimal dump of the occupied bytes.

Parameters
columnsBytes per row. Zero means a single row. This is a count, not a ByteSize.
Returns
Dump text owned by Base. Empty when this sequence is empty.

◆ insert() [1/5]

iterator StormByte::Safe::Binary::insert ( const_iterator pos,
const ByteSize & count,
std::byte value )

Insert count copies of value before pos.

Parameters
posInsertion point.
countNumber of bytes.
valueFill byte.
Returns
Iterator to the first inserted byte, or pos when count is zero.

◆ insert() [2/5]

template<typename InputIt>
Binary::iterator StormByte::Safe::Binary::insert ( const_iterator pos,
InputIt first,
InputIt last )

Insert the range [first, last) before pos.

Template Parameters
InputItInput iterator whose value converts to std::byte.
Parameters
posInsertion point.
firstStart of the source range.
lastEnd of the source range.
Returns
Iterator to the first inserted byte, or pos when the range is empty.

◆ insert() [3/5]

iterator StormByte::Safe::Binary::insert ( const_iterator pos,
std::byte value )

Insert one byte before pos.

Parameters
posInsertion point.
valueByte to insert.
Returns
Iterator to the inserted byte.

◆ insert() [4/5]

iterator StormByte::Safe::Binary::insert ( const_iterator pos,
std::initializer_list< std::byte > list )

Insert an initializer list before pos.

Parameters
posInsertion point.
listSource bytes.
Returns
Iterator to the first inserted byte, or pos when list is empty.

◆ insert() [5/5]

iterator StormByte::Safe::Binary::insert ( const_iterator pos,
std::span< const std::byte > bytes )

Insert a span before pos.

Parameters
posInsertion point.
bytesSource view.
Returns
Iterator to the first inserted byte, or pos when bytes is empty.

◆ max_size()

ByteSize StormByte::Safe::Binary::max_size ( ) const
noexcept

Implementation maximum size in bytes.

Returns
Maximum size.

◆ operator std::span< const std::byte >()

STORMBYTE_FORCE_INLINE StormByte::Safe::Binary::operator std::span< const std::byte > ( ) const
inlinenoexcept

Implicit read-only span conversion.

Returns
Same as const span().

◆ operator std::span< std::byte >()

STORMBYTE_FORCE_INLINE StormByte::Safe::Binary::operator std::span< std::byte > ( )
inlinenoexcept

Implicit mutable span conversion.

Returns
Same as span().

◆ operator std::vector< std::byte >() [1/2]

STORMBYTE_FORCE_INLINE StormByte::Safe::Binary::operator std::vector< std::byte > ( ) &&
inlineexplicit

Copy bytes onto the caller CRT, then release this object's storage.

Returns
Vector owned by the caller. This object is empty afterwards.

◆ operator std::vector< std::byte >() [2/2]

STORMBYTE_FORCE_INLINE StormByte::Safe::Binary::operator std::vector< std::byte > ( ) const &
inlineexplicit

Copy bytes onto the caller CRT as a vector.

This object is unchanged.

Returns
Vector owned by the caller.

◆ operator!=() [1/2]

bool StormByte::Safe::Binary::operator!= ( const Binary & other) const
noexcept

Inequality of byte contents.

Parameters
otherOther sequence.
Returns
Whether the sequences differ.

◆ operator!=() [2/2]

bool StormByte::Safe::Binary::operator!= ( std::span< const std::byte > bytes) const
noexcept

Inequality with a byte span.

Parameters
bytesView to compare.
Returns
Whether the sequence differs from the span.

◆ operator+=() [1/3]

Binary & StormByte::Safe::Binary::operator+= ( Binary && other)

Append other, then empty it.

Parameters
otherSource sequence.
Returns
This sequence.

◆ operator+=() [2/3]

Binary & StormByte::Safe::Binary::operator+= ( const Binary & other)

Append a copy of other.

Parameters
otherSource sequence.
Returns
This sequence.

◆ operator+=() [3/3]

Binary & StormByte::Safe::Binary::operator+= ( std::span< const std::byte > bytes)

Append a copy of bytes.

Parameters
bytesSource view.
Returns
This sequence.

◆ operator<=>() [1/2]

STORMBYTE_FORCE_INLINE std::strong_ordering StormByte::Safe::Binary::operator<=> ( const Binary & other) const
inlinenoexcept

Three-way lexicographical comparison.

Header-only: std::strong_ordering is not a DLL ABI.

Parameters
otherOther sequence.
Returns
Ordering.

◆ operator<=>() [2/2]

STORMBYTE_FORCE_INLINE std::strong_ordering StormByte::Safe::Binary::operator<=> ( std::span< const std::byte > bytes) const
inlinenoexcept

Three-way comparison with a byte span.

Header-only: std::strong_ordering is not a DLL ABI.

Parameters
bytesView to compare.
Returns
Ordering.

◆ operator=() [1/3]

Binary & StormByte::Safe::Binary::operator= ( Binary && other)
noexcept

Move assign.

other is left empty.

The previous block of this object goes through Discard before it is released. The storage of other is taken as is, even when other is a SecureBinary.

Parameters
otherSource sequence.
Returns
This sequence.

◆ operator=() [2/3]

Binary & StormByte::Safe::Binary::operator= ( const Binary & other)

Copy assign.

Parameters
otherSource sequence.
Returns
This sequence.

◆ operator=() [3/3]

Binary & StormByte::Safe::Binary::operator= ( std::initializer_list< std::byte > list)

Replace contents with an initializer list.

Parameters
listSource bytes.
Returns
This sequence.

◆ operator==() [1/2]

bool StormByte::Safe::Binary::operator== ( const Binary & other) const
noexcept

Equality of byte contents.

Runs in time independent of the contents when either side reports ConstantTimeCompare. Sizes are compared first and are not secret.

Parameters
otherOther sequence.
Returns
Whether sizes and bytes match.

◆ operator==() [2/2]

bool StormByte::Safe::Binary::operator== ( std::span< const std::byte > bytes) const
noexcept

Equality with a byte span.

Constant time when ConstantTimeCompare is true.

Parameters
bytesView to compare.
Returns
Whether sizes and bytes match.

◆ operator[]() [1/2]

const std::byte & StormByte::Safe::Binary::operator[] ( const ByteSize & index) const
noexcept

Unchecked read-only subscript.

Parameters
indexByte offset.
Returns
Byte at index.

◆ operator[]() [2/2]

std::byte & StormByte::Safe::Binary::operator[] ( const ByteSize & index)
noexcept

Unchecked mutable subscript.

Parameters
indexByte offset.
Returns
Byte at index.

◆ pop_back()

void StormByte::Safe::Binary::pop_back ( )

Remove the last byte.

◆ push_back()

void StormByte::Safe::Binary::push_back ( std::byte value)

Append one byte.

Parameters
valueByte to append.

◆ rbegin() [1/2]

const_reverse_iterator StormByte::Safe::Binary::rbegin ( ) const
noexcept

Read-only reverse iterator to the last byte.

Returns
Reverse begin.

◆ rbegin() [2/2]

reverse_iterator StormByte::Safe::Binary::rbegin ( )
noexcept

Mutable reverse iterator to the last byte.

Returns
Reverse begin.

◆ Release()

virtual void StormByte::Safe::Binary::Release ( std::span< std::byte > block)
protectedvirtualnoexcept

Called when a block stops being owned by this object: the old block after a reallocation, or a block handed to another sequence by a move or swap.

The block may still be alive and owned by the other sequence. Called after Discard. Default does nothing. Not called from the destructor: a derived destructor releases its own block.

Parameters
blockWhole block, as passed to Acquire.

Reimplemented in StormByte::Safe::SecureBinary.

◆ rend() [1/2]

const_reverse_iterator StormByte::Safe::Binary::rend ( ) const
noexcept

Read-only reverse iterator before the first byte.

Returns
Reverse end.

◆ rend() [2/2]

reverse_iterator StormByte::Safe::Binary::rend ( )
noexcept

Mutable reverse iterator before the first byte.

Returns
Reverse end.

◆ reserve()

void StormByte::Safe::Binary::reserve ( const ByteSize & new_cap)

Request capacity of at least new_cap bytes.

Parameters
new_capRequested capacity.

◆ resize() [1/2]

void StormByte::Safe::Binary::resize ( const ByteSize & new_size)

Resize to new_size bytes.

Appended bytes are zero.

Parameters
new_sizeNew size.

◆ resize() [2/2]

void StormByte::Safe::Binary::resize ( const ByteSize & new_size,
std::byte value )

Resize to new_size bytes.

Appended bytes are value.

Parameters
new_sizeNew size.
valueFill for new bytes.

◆ shrink_to_fit()

void StormByte::Safe::Binary::shrink_to_fit ( )

Release unused capacity when the implementation allows it.

◆ size()

ByteSize StormByte::Safe::Binary::size ( ) const
noexcept

Occupied length in bytes.

Returns
Length.

◆ span() [1/2]

STORMBYTE_FORCE_INLINE std::span< const std::byte > StormByte::Safe::Binary::span ( ) const
inlinenoexcept

Read-only view of the occupied bytes.

Returns
Span over the occupied bytes. Built in the caller.

◆ span() [2/2]

STORMBYTE_FORCE_INLINE std::span< std::byte > StormByte::Safe::Binary::span ( )
inlinenoexcept

Mutable view of the occupied bytes.

Returns
Span over the occupied bytes. Built in the caller.

◆ Storage()

std::span< std::byte > StormByte::Safe::Binary::Storage ( )
protectednoexcept

The whole allocated block, including unused capacity.

Returns
Span over capacity() bytes. Empty when nothing is allocated.

◆ swap()

void StormByte::Safe::Binary::swap ( Binary & other)
noexcept

Exchange storage with other.

The blocks are swapped, not copied. Swapping a SecureBinary with a plain Binary moves the secret into the plain object.

Parameters
otherOther sequence.

◆ Wipe()

void StormByte::Safe::Binary::Wipe ( std::span< std::byte > bytes)
staticprotectednoexcept

Zero bytes.

The compiler cannot drop the writes.

Parameters
bytesBytes to zero.

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