const_array.hHeader

Provides the const_array template class for storing and managing immutable arrays in a secure manner. More...

Detailed Description

This header file is part of the antispy SDK library and introduces the const_array template class, which is designed to handle fixed-size arrays of elements in a secure and immutable way. The class ensures that once an array is created, its contents cannot be modified, making it particularly useful for storing sensitive or configuration data that should remain constant throughout the application's lifecycle.

The const_array class leverages the const_value<T> type for its elements, which adds an additional layer of security and protection against tampering. The elements of the array are accessed through a secure index operator, and the class also provides functionality for converting the array into a reference to its underlying data type, as well as for initializing the array in a controlled manner.

Key Features:

  • Immutable Arrays : The const_array class ensures that the array elements are immutable after initialization, which is crucial for storing sensitive data that must not be altered.

  • Secure Element Access : Elements of the array are accessed through a secure index operator that ensures the index is within bounds, preventing accidental or malicious out-of-bounds access.

  • Memory Security : The class uses const_value<T> for storing elements, which provides additional security measures, such as preventing direct modification of the array data.

  • Flexible Initialization : The array can be initialized from an initializer list, allowing for easy and flexible creation of const_array objects with predefined values.

  • Conversion and Initialization : The class provides methods for converting the array to a reference to its underlying data type and for initializing the array through function calls at the array's memory address.

Intended Usage:

The const_array class is intended for use in situations where a fixed-size array of immutable elements is required, such as for look-up tables, static configurations, or embedded constant data. The security features of the class make it particularly well-suited for handling sensitive data that needs to be protected from tampering.

Example Usage:

#include <antispy/libantispy.h>

int main() {
   // Creating a const_array with 3 elements
   libantispy::const_array<int, 3> myArray{1, 2, 3};

   // Accessing an element securely
   int value = myArray[1];
}

This example demonstrates how to create a const_array object and access its elements using the provided secure index operator.

Note:

While the const_array class provides a high level of security and immutability, it is important to be aware of the potential performance implications of the added security features. These should be considered when deciding to use the const_array class in performance-critical parts of the application.