bufferClass

Class for managing encrypted buffers. More...

Public Functions

TypeName
buffer (const const_buffer< const_key, Hash, const_size > &src) noexcept
buffer (const ::std::string &src) noexcept
buffer (const buffer &src)=default
buffer (const buffer &&src) noexcept
buffer &operator= (const buffer &other)
buffer &operator= (buffer &&other) noexcept
charoperator[] (const size_t index) const noexcept
size_tsize () const
boolempty () const noexcept
voidappend (const buffer &cs)
size_tget_hash () const
~buffer () noexcept

Private Properties

TypeName
size_tkey_
size_thash_

Friends

TypeName
booloperator== (const buffer &lhs, const buffer &rhs) noexcept
booloperator!= (const buffer &lhs, const buffer &rhs) noexcept
booloperator< (const buffer &lhs, const buffer &rhs) noexcept
booloperator<= (const buffer &lhs, const buffer &rhs) noexcept
booloperator> (const buffer &lhs, const buffer &rhs) noexcept
booloperator>= (const buffer &lhs, const buffer &rhs) noexcept

Detailed Description

The buffer class extends std::vector<char> and is designed to handle encrypted data securely. It provides a set of features for encoding, decoding, and managing the encrypted content, leveraging the underlying dynamic array capabilities of std::vector<char> . This class is a key component in systems where data needs to be stored and transmitted securely, with built-in support for encryption and decryption operations.

Key Features:

  • Inheritance :

    • Inherits from std::vector<char> , giving it all the capabilities of a dynamic array, including automatic memory management, resizing, and element access.

    • Adds additional layers of security by integrating encryption and decryption mechanisms.

  • Data Security :

    • The buffer class automatically encrypts data on input and decrypts it on access, ensuring that the data remains secure throughout its lifecycle.

    • Uses a secure encryption key ( key_ ) and a hash value ( hash_ ) to maintain data integrity and prevent unauthorized access or tampering.

  • Constructors :

    • Supports construction from constant buffers ( const_buffer ), strings ( std::string ), and other buffer objects, with both copy and move semantics.

    • The constructors ensure that the data is correctly encrypted and that the key and hash are appropriately set.

  • Operators :

    • Provides several overloaded operators for element access ( operator[] ), comparison ( == , != , < , <= , > , >= ), and type conversion (to std::string ).

    • These operators facilitate easy use of the buffer in a wide range of contexts, including comparisons and conversions, while maintaining security.

Example:

#include <antispy/libantispy.h>

int main() {
   // Creating a buffer from a string
   std::string sensitive_data = "TopSecretData";
   libantispy::buffer encrypted_buffer(sensitive_data);

   // Accessing and using the buffer
   if (!encrypted_buffer.empty()) {
      std::string decrypted_data = encrypted_buffer;
      // Use decrypted_data securely...
   }
}

Public Functions

buffer (const const_buffer< const_key, Hash, const_size > &src) noexcept

Constructs a buffer object from a const_buffer .

Definition

libantispy::buffer::buffer

Detailed Description

This constructor initializes the buffer object using the contents of a const_buffer , which is a constant encrypted buffer. The encrypted data is directly copied into the buffer , and the encryption key and hash value are also copied, ensuring that the data remains secure.

Details:

  • Key and Hash Initialization :

    • The constructor initializes the key_ member with the provided constant key ( const_key ). This key is used for encryption and decryption operations.

    • The hash_ member is initialized with the hash value retrieved from the const_buffer using src.get_hash() . This hash is crucial for verifying the integrity of the data.

  • Data Copying :

    • The constructor copies the encrypted data from the const_buffer into the buffer . This is done by creating a temporary std::vector<char> with the data range from src.raw_data()->data to src.raw_data()->data + const_size .

    • The temporary vector is then swapped with the buffer 's internal vector using swap(*this) . This ensures efficient data transfer with minimal overhead.

  • Noexcept Guarantee :

    • The constructor is marked as noexcept , which indicates that it guarantees not to throw any exceptions. This makes it suitable for use in performance-critical or exception-sensitive code.

Example:

#include <antispy/libantispy.h>

int main() {
   libantispy::const_buffer<12345, 13, 64> encrypted_const_buffer("EncryptedData");
   libantispy::buffer secure_buffer(encrypted_const_buffer);
   // `secure_buffer` now contains the encrypted data from `encrypted_const_buffer`.
}

Template Parameters

Parameters

buffer (const ::std::string &src) noexcept

Constructs a buffer object from a std::string .

Definition

libantispy::buffer::buffer

Detailed Description

This constructor initializes the buffer object using the contents of a provided std::string . The string data is encrypted and stored in the buffer, and a unique key and hash value are generated for the encryption process.

Details:

  • Encryption :

    • The constructor generates a random encryption key using detail::key<char>::make_non_zero_random() . This key is used to encode the string data.

    • The key is ensured to be non-zero, enhancing security by avoiding trivial encryption (e.g., XOR with zero has no effect).

  • Hashing :

    • The fnv1a hashing algorithm is applied to the string to compute a unique hash value. This hash is used for quick comparisons and to verify the integrity of the data.

    • The hash is calculated over the entire string, including the null terminator ( src.length() + 1 ), ensuring that the full content of the string is considered.

  • Encoding :

    • The string is encrypted by the detail::buffer::encode function, which processes the string using the generated key.

    • The resulting encrypted data is stored in the buffer, replacing any previous contents of the buffer.

  • Noexcept Guarantee :

    • The constructor is marked as noexcept , indicating that it guarantees not to throw any exceptions. This is important for performance and reliability, especially in low-level or performance-critical code.

Example:

#include <antispy/libantispy.h>

int main() {
   std::string sensitive_data = "MySecretPassword";
   libantispy::buffer encrypted_buffer(sensitive_data);
   // `encrypted_buffer` now contains the encrypted version of `sensitive_data`.
}

Parameters

  • src: The source std::string containing the data to be encrypted and stored in the buffer.

buffer (const buffer &src)=default

Copy constructor for the buffer class.

Definition

libantispy::buffer::buffer

Detailed Description

This constructor creates a new buffer object as a copy of an existing buffer object. The default copy constructor is used, which automatically copies all the members of the src object to the new object.

Details:

  • Functionality :

    • The copy constructor initializes the new buffer object by performing a member-wise copy of the src buffer.

    • This means that the contents of the underlying std::vector<char> , along with the key_ and hash_ members, are duplicated in the new object.

  • Usage :

    • The copy constructor is invoked when a buffer object is passed by value, returned by value, or explicitly copied using syntax like buffer b2 = b1; .

    • It ensures that the new buffer object is a separate instance with its own copy of the data, key, and hash, independent of the original object.

  • Safety :

    • The default copy constructor is well-suited for simple classes where a shallow copy (i.e., copying the values of all members) is sufficient.

    • The buffer class members, such as std::vector<char> , handle their own memory management, ensuring that each buffer object manages its own resources.

  • Post-Conditions :

    • After the copy operation, the new buffer object ( this ) contains the same data as the src object.

    • The original src buffer remains unchanged and independent of the new copy.

Example:

#include <antispy/libantispy.h>

int main() {
   libantispy::buffer b1("initial_data");
   libantispy::buffer b2 = b1; // b2 is a copy of b1, with its own copy of the data, key, and hash.
}

Parameters

  • src: The source buffer object to copy from.

buffer (const buffer &&src) noexcept

Move constructor for the buffer class.

Definition

libantispy::buffer::buffer

Detailed Description

This constructor initializes a buffer object by transferring the ownership of resources from another buffer object. The move constructor ensures that the current object takes over the data, encryption key, and hash from the src buffer, leaving src in a valid but unspecified state.

Details:

  • Functionality :

    • The move constructor is used to efficiently transfer the contents of one buffer object ( src ) to another, without the need to perform a deep copy.

    • This operation is typically faster than copying because it involves only pointer manipulations rather than duplicating the actual data.

  • Logic :

  • Key and Hash Transfer :

    • The constructor initializes the key_ and hash_ members of the current object by directly assigning them from the src object. This step copies the encryption key and hash value from src to the current buffer .
  • Resource Transfer :

    • The std::vector<char>().swap(*this); call clears the current vector by swapping it with an empty vector.

    • The static_cast<::std::vector<char>>(src).swap(*this); line then swaps the data from the src vector into the current object. This operation effectively transfers the data from src to this .

    • The static_cast is used to treat src as an std::vector<char> , enabling the swap operation.

    • The NOLINT(cppcoreguidelines-slicing) comment suppresses a lint warning about potential slicing when src is cast to std::vector<char> . Slicing does not occur in this context because the move operation correctly handles all relevant members.

  • Usage :

    • This move constructor is invoked when a buffer object is initialized from a temporary buffer (e.g., buffer b = std::move(other_buffer); ).

    • It ensures that the buffer object can be efficiently constructed from another buffer without unnecessary copies.

  • Safety :

    • The constructor is marked noexcept , indicating that it does not throw exceptions. This is important for performance-sensitive applications, as it allows safe usage in contexts where exception handling might be costly or undesired.
  • Post-Conditions :

    • After the move, the src buffer is left in a valid but unspecified state. It can be destructed or assigned a new value, but its contents should not be relied upon.

Example:

#include <antispy/libantispy.h>

int main() {
   libantispy::buffer b1("initial_data");
   libantispy::buffer b2 = std::move(b1); // b2 takes ownership of b1's data
}

Parameters

  • src: The source buffer object to move from.

buffer & operator= (const buffer &other)

Copy assignment operator for the buffer class.

Definition

buffer & libantispy::buffer::operator=

Detailed Description

This operator allows for the assignment of one buffer object to another, effectively duplicating the contents and state of the other buffer into the current buffer ( this ). The copy assignment operator is crucial in scenarios where a deep copy of the buffer's data and encryption key is needed.

Details:

  • Functionality :

    • The copy assignment operator duplicates the contents of the other buffer and assigns them to the current buffer ( this ), ensuring that the current buffer becomes an exact copy of the other .
  • Logic :

  • Self-Assignment Check :

    • The first step is to check whether the current object ( this ) is the same as the other object.

    • If they are the same, the function simply returns *this , as no operation is needed.

  • Copy Data :

    • If the objects are different, the contents of the other buffer are copied into the current buffer.

    • This is done by creating a temporary std::vector<char> initialized with the range of elements from the other buffer and then swapping it with the current buffer.

    • This ensures that the current buffer is updated with the new data in an exception-safe manner.

  • Copy Key :

    • The encryption key ( key_ ) from the other buffer is assigned to the current buffer's key_ .

    • This step is essential to ensure that the encryption/decryption process can be performed correctly on the copied data.

  • Return Current Object :

    • The function returns a reference to the current buffer ( *this ), allowing for method chaining and further operations.
  • Usage :

    • This operator is used when an existing buffer object needs to be replaced with the contents of another buffer object, resulting in a deep copy.

    • It is useful in scenarios where multiple copies of a buffer need to be maintained independently.

  • Safety :

    • The self-assignment check ensures that the operator behaves correctly even when the same object is assigned to itself, preventing unnecessary operations and potential issues.

    • The use of the swap method provides strong exception safety, as it ensures that the current buffer's state is only updated if all operations succeed.

Example:

#include <antispy/libantispy.h>

int main() {
   libantispy::buffer buf1("data1");
   libantispy::buffer buf2("data2");
   buf1 = buf2; // buf1 is now an exact copy of buf2.
}

Parameters

  • other: The source buffer object to copy from. The contents and encryption key of other are duplicated.

Returns

A reference to the current buffer object ( *this ), now containing a copy of other .

buffer & operator= (buffer &&other) noexcept

Move assignment operator for the buffer class.

Definition

buffer & libantispy::buffer::operator=

Detailed Description

This operator allows for efficient transfer of resources from one buffer object to another, leveraging move semantics to avoid unnecessary copying. The move assignment operator is crucial in scenarios where performance is critical, and ownership of the buffer's resources needs to be transferred rather than duplicated.

Details:

  • Functionality :

    • The move assignment operator transfers the contents and resources from the other buffer to the current buffer ( this ), effectively moving the data and invalidating the other buffer's state.
  • Logic :

  • Self-Assignment Check :

    • The first step is to check whether the current object ( this ) is the same as the other object.

    • If they are the same, the function simply returns *this , as no operation is needed.

  • Clear Current Buffer :

    • If the objects are different, the current buffer is cleared by swapping it with an empty std::vector<char> .

    • This ensures that the current buffer's contents are released before the move.

  • Move Data :

    • The swap function is used to transfer the contents of the other buffer to the current buffer.

    • This operation is efficient because it involves swapping pointers rather than copying data.

  • Transfer Key :

    • The encryption key ( key_ ) from the other buffer is assigned to the current buffer's key_ .

    • This step ensures that the encryption/decryption process can continue seamlessly with the moved data.

  • Return Current Object :

    • The function returns a reference to the current buffer ( *this ), allowing for method chaining and further operations.
  • Usage :

    • This operator is used when an existing buffer object needs to take ownership of the resources of another buffer object that is about to go out of scope or is no longer needed.

    • It is particularly useful in performance-sensitive applications where minimizing copy operations is important.

  • Safety :

    • The operator is marked as noexcept , ensuring that it does not throw exceptions. This is important for maintaining strong exception safety guarantees, particularly in environments where exception handling must be avoided.

    • The self-assignment check ensures that the operator behaves correctly even when the same object is assigned to itself.

Example:

#include <antispy/libantispy.h>

int main() {
   libantispy::buffer buf1("data1");
   libantispy::buffer buf2("data2");
   buf1 = std::move(buf2); // buf1 now owns the data of buf2, and buf2 is left in a valid but unspecified state.
}

Parameters

  • other: The source buffer object to move from. After the move, other is left in a valid but unspecified state.

Returns

A reference to the current buffer object ( *this ), now containing the moved resources.

char operator[] (const size_t index) const noexcept

Index operator for accessing elements of the encrypted buffer.

Definition

char libantispy::buffer::operator[]

Detailed Description

The operator[] function provides access to elements within the encrypted buffer by decrypting them on-the-fly. This operator is crucial for retrieving individual characters from the buffer while ensuring that the data remains secure during access.

Details:

  • Logic :

    • The function uses the given index to access the corresponding encrypted element in the buffer.

    • The encrypted value is then decrypted using the encryptor<char>::decrypt method, which requires:

      • The encrypted character retrieved from the buffer.

      • The encryption key ( key_ ) that was used to encrypt the buffer.

      • The index itself as an additional parameter to the decryption function.

    • The result is the decrypted character at the specified index.

  • Usage :

    • This operator allows for secure access to the buffer's contents, especially when you need to read individual characters in a context where the data must remain protected, such as in secure communications or encrypted file handling.

    • It can be used in loops, conditionals, or any context where indexed access to the buffer's content is required.

  • Performance :

    • While the operator ensures data security by decrypting each accessed element, the decryption process introduces some overhead compared to direct access in a non-encrypted context. However, this is a necessary trade-off for maintaining the confidentiality of the data.
  • Safety :

    • The operator is marked as noexcept , indicating that it does not throw exceptions, which is beneficial in scenarios where exception safety is a concern.

    • The WIN_SUPRESS_4244 macro is used to suppress specific compiler warnings related to potential data loss in type conversions, ensuring clean compilation without warnings while being mindful of data integrity.

Example:

#include <antispy/libantispy.h>

int main() {
   libantispy::buffer buf("encrypted_string");
   char c = buf[0];  // Accesses and decrypts the first character in the buffer
}

Parameters

  • index: The index of the element to access.

Returns

The decrypted character at the specified index.

size_t size () const

Returns the size of the buffer.

Definition

size_t libantispy::buffer::size

Detailed Description

The size() function provides the current number of elements in the buffer. It is an essential function for determining the length or capacity of the buffer in terms of the number of characters it holds.

Details:

  • Logic :

    • The function internally calls the size() method of the underlying std::vector<char> base class.

    • This method returns the number of elements currently stored in the buffer, which reflects the actual size of the data.

  • Usage :

    • This function is useful when you need to determine the length of the buffer, especially when processing or manipulating its contents.

    • The size returned by this function can be used to iterate over the buffer, allocate memory, or perform size-related checks.

  • Performance :

    • Since this function directly returns the size of the vector, it is typically a constant-time operation, meaning it has O(1) complexity.

Example:

#include <antispy/libantispy.h>

int main() {
   libantispy::buffer buf;
   size_t bufferSize = buf.size();
   if (bufferSize > 0) {
      // Process the buffer
   }
}

Returns

The number of elements (characters) in the buffer.

bool empty () const noexcept

Checks whether the buffer is empty.

Definition

bool libantispy::buffer::empty

Detailed Description

The empty() function determines if the current buffer contains any data. It provides a convenient way to check if the buffer is empty, i.e., if it has a size of zero.

Details:

  • Logic :

    • The function internally calls the size() method to retrieve the size of the buffer.

    • It then compares the size to zero. If the size is zero, the buffer is considered empty, and the function returns true .

    • If the size is greater than zero, the function returns false , indicating that the buffer contains data.

  • Noexcept :

    • The function is marked as noexcept , indicating that it is guaranteed not to throw any exceptions. This makes it safe to use in contexts where exception safety is critical.
  • Use Case :

    • This function is particularly useful in conditional statements where operations depend on whether the buffer is empty or not.

    • It simplifies code that needs to handle empty buffers differently from non-empty ones.

Example:

#include <antispy/libantispy.h>

int main() {
   libantispy::buffer buf;
   if (buf.empty()) {
      // Handle the empty buffer case
   } else {
      // Process the buffer
   }
}

Returns

true if the buffer is empty (i.e., size is zero); false otherwise.

void append (const buffer &cs)

Appends the contents of another buffer to this buffer.

Definition

void libantispy::buffer::append

Detailed Description

The append() function allows the current buffer to append the contents of another buffer object to itself. This is useful when you want to combine or concatenate two buffers into a single one, effectively merging their contents.

Details:

  • Process :

    • The function first converts the current buffer ( *this ) into a std::string by using the static_cast operator.

    • It then converts the provided buffer ( cs ) into a std::string as well.

    • The contents of the cs buffer are appended to the str string, which now contains the combined data from both buffers.

    • Finally, the new (this) string(str); statement reconstructs the current buffer with the new combined data, effectively replacing its contents with the concatenated result.

  • In-Place Modification :

    • The new (this) string(str); syntax performs in-place reconstruction of the current buffer object. This approach ensures that the buffer's contents are updated without requiring the creation of a new buffer object.

    • This method takes advantage of placement new to reconstruct the buffer with the updated string content.

  • Performance :

    • The operation of appending a buffer involves memory allocation and copying, especially since the buffers are first converted to std::string objects. While this approach is straightforward, it might not be the most efficient for large buffers.
  • Use Case :

    • This function is particularly useful when managing dynamic data, where buffers need to be extended or combined during runtime.

    • It simplifies buffer management by allowing direct concatenation without requiring external manipulation of the buffer's internal data.

Parameters

  • cs: The buffer object whose contents are to be appended to the current buffer.

size_t get_hash () const

Retrieves the hash value of the buffer.

Definition

size_t libantispy::buffer::get_hash

Detailed Description

The get_hash() function returns the hash value that was calculated and stored within the buffer object. This hash is typically used to verify the integrity of the buffer's contents or to uniquely identify the buffer's data.

Details:

  • Hash Calculation :

    • The hash_ value is computed when the buffer is constructed, either during initialization with a const_buffer or a std::string . The hash typically uses a hashing algorithm like FNV-1a or another method provided by the implementation.
  • Purpose :

    • The hash is useful for quickly comparing buffers, checking data integrity, or for use in cryptographic operations where a consistent, reproducible identifier for the data is required.
  • Performance :

    • This function is marked with ANTISPY_INLINE to suggest inlining by the compiler, which can help reduce the function call overhead when accessing the hash value. However, the actual inlining is subject to the compiler's optimization decisions.
  • Return Value :

    • The function returns the stored hash value, which is a size_t type. This value can be used for any subsequent operations where the buffer's hash is needed.

Returns

The hash value of the buffer, stored as a size_t .

~buffer () noexcept

Destructor for the buffer class.

Definition

libantispy::buffer::~buffer

Detailed Description

The destructor is responsible for securely cleaning up the buffer object when it is no longer needed. It ensures that any sensitive data stored in the buffer is securely erased to prevent unauthorized access or data leakage.

Details:

  • Key and Hash Clearing :

    • The key_ and hash_ member variables, which are used for encryption and integrity checking, are securely cleared by XORing them with themselves. This operation effectively sets their values to zero, ensuring that these sensitive pieces of information are not left in memory after the buffer is destroyed.
  • Data Erasure :

    • The buffer's content is securely erased using memset , which sets the memory occupied by the buffer's data to zero. The memset function is applied to the entire range of the buffer from the beginning to the end.

    • This step is crucial for preventing residual data from being recovered from memory after the buffer is destroyed.

  • Memory Deallocation :

    • The memory allocated for the buffer is deallocated by swapping the current std::vector<char> with an empty vector. This ensures that the memory used by the buffer is released back to the system, preventing memory leaks.
  • Security Considerations :

    • The destructor implements best practices for securely handling and destroying sensitive data, ensuring that encryption keys, hashes, and buffer content do not remain in memory after the buffer is destroyed.

    • The use of XOR and memset helps protect against potential memory dumps or forensic analysis that could otherwise expose sensitive information.

Exception Safety:

  • The destructor is marked noexcept , indicating that it does not throw any exceptions. This ensures that the cleanup process is guaranteed to complete without interruption, even in environments where exceptions are not allowed.

Private Properties

size_t key_

The encryption key used for securing the buffer's content.

Definition

size_t libantispy::buffer::key_

Detailed Description

The key_ member variable holds the encryption key used for encrypting and decrypting the data stored within the buffer class. This key is a crucial part of the buffer's security mechanism, as it ensures that the data is securely transformed between its encrypted and decrypted states.

Details:

  • Type : size_t

  • Usage : The key_ is used in conjunction with the buffer's contents to perform encryption and decryption operations. When data is written to the buffer, it is encrypted using this key. When data is read from the buffer, it is decrypted using the same key.

  • Initialization :

    • **In Constructor from std::string ** : The key_ is initialized to a randomly generated non-zero value using the detail::key<char>::make_non_zero_random() method. This ensures that the key is unique and unpredictable for each instance of the buffer.

    • **In Constructor from const_buffer **: The key_ is set to the key used in the const_buffer , ensuring consistency between the compile-time encrypted data and its runtime representation.

  • Security :

    • The key_ is XORed with itself during the destruction of the buffer to securely erase it.

    • The encryption key is never directly exposed; it is used internally to protect the buffer's data.

  • Scope : This member is private, meaning it is only accessible within the buffer class.

  • Context : The key is used in tandem with the buffer's content and a hashing mechanism (hash_) to ensure the integrity and confidentiality of the data.

Example Usage:

#include <antispy/libantispy.h>

int main() {
   libantispy::buffer secure_data("Sensitive Information");
   std::string decrypted_data = secure_data; // Implicitly decrypts using key_
}

In the example above, the key_ would be used to encrypt "Sensitive Information" when constructing the buffer , and then used again to decrypt the data when accessing it.

size_t hash_

Hash value representing the buffer's content.

Definition

size_t libantispy::buffer::hash_

Detailed Description

The hash_ member variable stores a hash value that uniquely represents the content of the buffer. This hash is used for verifying the integrity of the buffer's content, ensuring that data has not been altered or corrupted.

Details:

  • Type : size_t

  • Purpose :

    • The hash_ is crucial for comparing buffer objects, as it allows quick equality checks by comparing hash values rather than the entire buffer content.

    • It is also used for validating the integrity of the buffer, ensuring that the content matches the expected value.

  • Initialization :

    • **In Constructor from std::string ** : The hash_ is computed using a hash function like libantispy::fnv1a<char>() , which generates a unique hash for the string content, ensuring that even small changes in the content result in a different hash value.

    • **In Constructor from const_buffer **: The hash_ is set to the precomputed hash value from the const_buffer , ensuring consistency between the original and the current buffer.

  • Usage :

    • The hash is primarily used in comparison operators ( == , != , etc.) to quickly determine if two buffers are identical without needing to compare each byte of their content.

    • It is also used in scenarios where the buffer needs to be validated or stored in hash-based containers.

  • Security Considerations :

    • The hash value provides a layer of security by ensuring that any tampering with the buffer content can be detected through a mismatch in the hash value.

    • It is also used to ensure that encrypted buffers are correctly processed and matched with their original content.

Friends

bool operator== (const buffer &lhs, const buffer &rhs) noexcept

Equality operator for comparing two buffer objects.

Definition

bool operator==

Detailed Description

The operator== function is used to compare two buffer objects to determine if they are equal. This operator is vital in scenarios where checking the equivalence of encrypted buffers is required, such as in data integrity verification or during cryptographic operations.

Details:

  • Logic :

    • The function compares the hash values of the two buffers, lhs and rhs .

    • If the hash values are identical, the function returns true , indicating that the buffers are considered equal.

    • If the hash values differ, the function returns false , indicating that the buffers are not equal.

    • This comparison method relies on the assumption that the hash values accurately represent the content of the buffers.

    • Since hash values are generally much smaller in size compared to the buffer's content, this comparison is efficient.

  • Usage :

    • This operator is essential in conditions where it is necessary to confirm that two buffers are identical, such as in cryptographic checks, input validation, or data synchronization processes.

    • It can be used in control flow statements, assertions, or anywhere an equality check between buffers is required.

  • Performance :

    • The performance of this operator is expected to be very efficient since it only compares two size_t values (the hash values).

    • This makes it significantly faster than comparing the entire content of the buffers directly.

Example:

#include <antispy/libantispy.h>

int main() {
   libantispy::buffer buf1("encrypted_data_1");
   libantispy::buffer buf2("encrypted_data_1");
   if (buf1 == buf2) {
      // buf1 and buf2 are equal
   }
}

Parameters

  • lhs: The left-hand side buffer object to compare.

  • rhs: The right-hand side buffer object to compare.

Returns

true if lhs is equal to rhs ; false if they are not equal.

bool operator!= (const buffer &lhs, const buffer &rhs) noexcept

Inequality operator for comparing two buffer objects.

Definition

bool operator!=

Detailed Description

The operator!= function is used to compare two buffer objects to determine if they are not equal. This operator plays a crucial role in scenarios where it is important to identify differences between encrypted buffers, such as validating data integrity or detecting changes.

Details:

  • Logic :

    • The function leverages the equality operator operator== to check if the two buffers are equal.

    • If the buffers are equal, operator== returns true , and this function negates that result, returning false .

    • Conversely, if the buffers are not equal, operator== returns false , and this function negates that result, returning true .

    • The use of operator== ensures that the comparison is based on the underlying encrypted data and its hash value.

  • Usage :

    • This operator is essential in conditions where it is necessary to confirm that two buffers are not the same, such as in data validation, input comparison, or during decryption checks.

    • It can be used in control flow statements, assertions, or anywhere an inequality check between buffers is required.

  • Performance :

    • The performance of this operator is directly tied to the operator== function, as it is built upon it.

    • Since the comparison is generally based on hash values and potentially the buffer's content, it is expected to be efficient.

Example:

#include <antispy/libantispy.h>

int main() {
   libantispy::buffer buf1("encrypted_data_1");
   libantispy::buffer buf2("encrypted_data_2");
   if (buf1 != buf2) {
      // buf1 and buf2 are not equal
   }
}

Parameters

  • lhs: The left-hand side buffer object to compare.

  • rhs: The right-hand side buffer object to compare.

Returns

true if lhs is not equal to rhs ; false if they are equal.

bool operator< (const buffer &lhs, const buffer &rhs) noexcept

Less-than operator for comparing two buffer objects.

Definition

bool operator<

Detailed Description

The operator< function is used to compare two buffer objects to determine if one is strictly less than the other. This operator is essential in situations where you need to establish an order between two encrypted buffers, such as when sorting or implementing data structures that require ordered elements.

Details:

  • Logic :

    • The function first checks if the two buffers are not equal by using the operator!= function.

    • If the buffers are not equal, the function proceeds to convert both buffers to std::string objects by invoking the operator std::string() function.

    • The comparison is then performed on the decrypted string representations of the buffers.

    • If the string representation of the left-hand side ( lhs ) buffer is less than that of the right-hand side ( rhs ) buffer, the function returns true ; otherwise, it returns false .

    • If the buffers are equal, the function returns false , as neither is less than the other.

  • Usage :

    • This operator is commonly used in sorting algorithms, ordered containers (e.g., std::set , std::map ), and other contexts where determining the order between buffers is necessary.

    • It can also be used in conditional checks to enforce specific ordering constraints between encrypted data buffers.

  • Performance :

    • The performance of this operator depends on the cost of the string conversion and the string comparison.

    • Converting the buffer to a string involves decrypting the buffer's contents, which can be an O(n) operation, where n is the length of the string.

    • The string comparison itself is also O(n), making the overall comparison O(n) in the worst case.

Example:

#include <antispy/libantispy.h>

int main() {
   libantispy::buffer buf1("encrypted_data_1");
   libantispy::buffer buf2("encrypted_data_2");
   if (buf1 < buf2) {
      // buf1 is less than buf2
   }
}

Parameters

  • lhs: The left-hand side buffer object to compare.

  • rhs: The right-hand side buffer object to compare.

Returns

true if lhs is strictly less than rhs ; false otherwise.

bool operator<= (const buffer &lhs, const buffer &rhs) noexcept

Less-than-or-equal-to operator for comparing two buffer objects.

Definition

bool operator<=

Detailed Description

The operator<= function is used to compare two buffer objects to determine if one is less than or equal to the other. This operator is especially useful in scenarios where you need to verify if the contents of one encrypted buffer are either less than or equal to another, which can be relevant in sorting or conditional checks.

Details:

  • Logic :

    • The function first checks if the two buffers are equal by using the operator== function.

    • If the buffers are equal, the function immediately returns true .

    • If the buffers are not equal, it converts both buffers to std::string objects by invoking the operator std::string() function.

    • The comparison is then made on the decrypted string representations of the buffers.

    • If the left-hand side ( lhs ) buffer is less than the right-hand side ( rhs ) buffer in terms of their string values, the function returns true ; otherwise, it returns false .

  • Usage :

    • This operator is useful when you need to determine whether one buffer is less than or equal to another.

    • It can be used in sorting algorithms, conditional checks, and other scenarios where buffer ordering is important.

  • Performance :

    • The performance of this operator depends on the complexity of the comparison and the conversion of the buffers to strings.

    • The string comparison involves a character-by-character comparison of the decrypted contents, which can be an O(n) operation, where n is the length of the strings.

Example:

#include <antispy/libantispy.h>

int main() {
   libantispy::buffer buf1("encrypted_data_1");
   libantispy::buffer buf2("encrypted_data_2");
   if (buf1 <= buf2) {
      // buf1 is less than or equal to buf2
   }
}

Parameters

  • lhs: The left-hand side buffer object to compare.

  • rhs: The right-hand side buffer object to compare.

Returns

true if lhs is less than or equal to rhs ; false otherwise.

bool operator> (const buffer &lhs, const buffer &rhs) noexcept

Greater-than operator for comparing two buffer objects.

Definition

bool operator>

Detailed Description

The operator> function is used to compare two buffer objects to determine if one is greater than the other. This operator is particularly useful in scenarios where you need to compare the contents of two encrypted buffers to establish their relative order or precedence.

Details:

  • Logic :

    • The function first checks if the two buffers are not equal by using the operator!= function.

    • If the buffers are not equal, it then converts both buffers to std::string objects by invoking the operator std::string() function.

    • The comparison is made on the decrypted string representations of the buffers.

    • If the left-hand side ( lhs ) buffer is greater than the right-hand side ( rhs ) buffer in terms of their string values, the function returns true ; otherwise, it returns false .

  • Usage :

    • This operator is useful when you need to determine whether one buffer is strictly greater than another.

    • It can be used in sorting algorithms, conditional checks, and other scenarios where buffer ordering is important.

  • Performance :

    • The performance of this operator depends on the complexity of the comparison and the conversion of the buffers to strings.

    • The string comparison involves a character-by-character comparison of the decrypted contents, which can be an O(n) operation, where n is the length of the strings.

Example:

#include <antispy/libantispy.h>

int main() {
   libantispy::buffer buf1("encrypted_data_1");
   libantispy::buffer buf2("encrypted_data_2");
   if (buf1 > buf2) {
      // buf1 is greater than buf2
   }
}

Parameters

  • lhs: The left-hand side buffer object to compare.

  • rhs: The right-hand side buffer object to compare.

Returns

true if lhs is greater than rhs ; false otherwise.

bool operator>= (const buffer &lhs, const buffer &rhs) noexcept

Greater-than-or-equal-to operator for comparing two buffer objects.

Definition

bool operator>=

Detailed Description

The operator>= function compares two buffer objects to determine if one is greater than or equal to the other. This operator is particularly useful when sorting or comparing buffers based on their encrypted content.

Details:

  • Logic :

    • The function first checks if the two buffers are equal by using the operator== function.

    • If the buffers are not equal, it then converts both buffers to std::string objects by invoking the operator std::string() function.

    • The comparison is made on the decrypted string representations of the buffers.

    • If the left-hand side ( lhs ) buffer is greater than or equal to the right-hand side ( rhs ) buffer in terms of their string values, the function returns true ; otherwise, it returns false .

  • Usage :

    • This operator is useful when you need to compare two buffers to determine their relative ordering or check if one buffer is at least as large as another.

    • It is often used in sorting algorithms, conditional checks, and other scenarios where buffer comparison is required.

  • Performance :

    • The performance of this operator depends on the complexity of the comparison and the conversion of the buffers to strings.

    • The string comparison involves a character-by-character comparison of the decrypted contents, which can be an O(n) operation, where n is the length of the strings.

Example:

#include <antispy/libantispy.h>

int main() {
   libantispy::buffer buf1("encrypted_data_1");
   libantispy::buffer buf2("encrypted_data_2");
   if (buf1 >= buf2) {
      // buf1 is greater than or equal to buf2
   }
}

Parameters

  • lhs: The left-hand side buffer object to compare.

  • rhs: The right-hand side buffer object to compare.

Returns

true if lhs is greater than or equal to rhs ; false otherwise.