encrypted_valueClass

Template class for securely storing an encrypted value. More...

Public Functions

TypeName
constexprencrypted_value (const T &src)
operator T () const noexcept

Private Properties

TypeName
Tstore_

Detailed Description

The encrypted_value class provides a mechanism for securely storing a value of type T by encrypting it with a specified key and identifier. This class ensures that the value is encrypted when stored and decrypted when accessed, thereby adding a layer of protection against unauthorized access or tampering.

Template Parameters

  • T: The type of the value to be encrypted and stored.

  • Key: The encryption key used for securing the value.

  • N: An additional identifier or modifier used in the encryption process to enhance security.

This class is designed to be used in environments where the security of sensitive data is a concern. By encrypting the data at rest and decrypting it only when needed, the encrypted_value class helps prevent direct access to the raw value, adding an extra layer of security.

Example usage:

#include <antispy/libantispy.h>

int main() {
int original_value = 42;
   encrypted_value<int, 0xDEADBEEF, 123> encrypted(original_value);

   int decrypted_value = encrypted; // decrypted_value will be 42
}

Public Functions

constexpr encrypted_value (const T &src)

Constructs an encrypted_value object by encrypting a source value.

Definition

constexpr libantispy::encrypted_value< T, Key, N >::encrypted_value

Detailed Description

This constexpr constructor initializes an encrypted_value object by encrypting the given source value using the specified encryption key Key and an additional identifier N . The encrypted value is then stored internally, ensuring that it remains secure until it is accessed and decrypted.

Parameters

  • src: The source value of type T to be encrypted and stored.

This constructor leverages the encryptor<T>::encrypt function to perform the encryption. The resulting encrypted value is stored in the store_ member variable. As a constexpr constructor, it allows for compile-time encryption when possible, enabling efficient and secure storage of constant values.

Example usage:

#include <antispy/libantispy.h>

int main() {
   constexpr int original_value = 42;
   constexpr encrypted_value<int, 0xDEADBEEF, 123> encrypted(original_value);
   // The value is encrypted at compile-time and stored securely.
}

operator T () const noexcept

Conversion operator to the original type T .

Definition

libantispy::encrypted_value< T, Key, N >::operator T

Detailed Description

This ANTISPY_INLINE conversion operator allows an encrypted_value object to be implicitly converted back to the original type T . The operator performs decryption of the internally stored encrypted value using the specified encryption key Key and identifier N . The decrypted value is then returned as type T .

Returns

The decrypted value as type T .

This operator ensures that the encrypted value stored within the object is securely decrypted before being returned. It is marked as noexcept , indicating that the operation is guaranteed not to throw any exceptions, which is crucial for reliability and performance.

Example usage:

#include <antispy/libantispy.h>

int main() {
   encrypted_value<int, 0xDEADBEEF, 123> encrypted(42);
   int decrypted_value = encrypted;  // Implicitly converts and decrypts the value
}

Private Properties

T store_

Stores the encrypted value.

Definition

T libantispy::encrypted_value< T, Key, N >::store_

Detailed Description

The store_ member variable holds the encrypted version of the original value of type T . This encryption is performed using the specified encryption key ( Key ) and an identifier ( N ).

  • Type : T

  • Access : Private

The value stored in store_ is not the original value but the result of an encryption operation performed during the construction of the encrypted_value object. This encrypted value remains secure and is only decrypted when the conversion operator is invoked, allowing the object to be used safely in scenarios where data integrity and security are paramount.

The encryption algorithm ensures that the data is obfuscated and cannot be easily read or tampered with by an attacker. As a private member, store_ is only accessible within the encrypted_value class, preserving its integrity and preventing unauthorized access.

Example:

#include <antispy/libantispy.h>

int main() {
   encrypted_value<int, 0xDEADBEEF, 123> encrypted(42);
   // Internally, 'store_' holds the encrypted form of 42.
}