Configuration data protection
A method includes in a first package, defining a data type as implementing a method that returns a copy of a protected configuration value and in a second package, providing a function that accepts a variable of the data type and that calls the method to obtain the copy of the protected configuration value. The first package and the second package are imported into a common package so that the function in the second package can obtain the copy of the protected configuration value without being able to modify the protected configuration value.
1 . A method comprising:
importing a first code package, a second code package and a configuration package into a main code package, wherein:
the configuration package provides instructions for loading first configuration data used by the first code package and second configuration data used by the second code package into data objects wrapped by a data structure;
the configuration package prevents the first code package and the second code package from accessing the data objects directly;
the data structure implements a first method that returns a copy of at least one data object loaded with the first configuration data and a second method that returns a copy of at least one data object loaded with the second configuration data;
the first code package includes an interface that references the first method and a function that receives a pointer to the data structure and utilizes the copy of the at least one data object returned by the data structure implementing first method; and
the second code package includes an interface that references the second method and a function that receives a pointer to the data structure and utilizes the copy of the at least one data object returned by data structure implementing the second method.
2 . The method of claim 1 wherein the data objects are part of a single data structure that implements both the first method and the second method.
3 . The method of claim 1 wherein the first code package can be imported into a different main code package together with a second configuration package that provides a different implementation of the first method.
4 . The method of claim 3 wherein the second code package can be imported into a different main code package together with a third configuration package that provides a different implementation of the second method.
5 . The method of claim 1 wherein the first code package can be imported into a different main code package together with a second configuration package that does not provide an implementation of the second method.
6 . The method of claim 5 wherein the second code package can be imported into a different main code package together with a third configuration package that does not provide an implementation of the first method.
7 . The method of claim 1 wherein instructions in the first code package are prevented from changing the second configuration data loaded into the data objects.