Guides
Code markers
How to mark protected code regions with SDK macros, name them, set their level in the settings file, and which constructs to avoid.
Markers let you protect part of a function instead of the whole function. They help when only some of the code needs protection and the rest is called often, and when a file has no symbols.
Adding the SDK
The SDK contains header files and the licensing library. You download it in the panel, in the SDK section. With CMake, add the SDK folder to CMAKE_PREFIX_PATH and call find_package(Torzen).
#include <torzen/markers.h>
bool LicenseManager::validate(const std::string& key) {
TORZEN_PROTECT_BEGIN("license-check");
const auto record = store_.find(key);
const bool valid = record && record->expires > clock_.now();
TORZEN_PROTECT_END();
return valid;
}Level for a marker
The panel lists the markers it finds next to the functions. In the settings file, you set the level in the markers field:
{
"markers": [{ "name": "license-check", "level": "virtualization" }]
}Markers without an entry get the level from the default field.
Rules
- A marker must begin and end in the same function.
- Do not leave a marked region with
return,gotoor an exception. - A marker name can repeat across functions. Its setting then applies to every occurrence.
- Without protection the macros expand to empty statements, so the code builds and runs before it is uploaded to Torzen.