Reference Guide

34 Chapter 3: Resource Management
RSA BSAFE Crypto-C Micro Edition 3.x to 4.1.4 Migration Guide
Tracing
Although not necessary for migration of custom resource lists, Crypto-C ME 4.1.4
provides a tracing API to supply runtime information about the internal operation of
the library. Support for tracing is added to the resource selection logic and can be used
to observe what resources are being used by the library.
The following example code shows how tracing for resource selection can be
implemented.
#include "bsafe/r_select_r.h"
static void logger(const R_TRACER *tracer, const char *message,
unsigned int len)
{
printf("%s\n", message);
}
const R_TRACER tracer =
{
R_TRACE_VERSION_1,
R_TRACE_LVL_ALL,
logger,
NULL,
};
int main(int argc, char **argv)
{
int ret;
R_LIB_CTX *lib_ctx = NULL;
ret = R_STATE_init_defaults();
if (R_ERROR_NONE != ret)
return 1;
ret = R_LIB_CTX_new_ef(&custom_resource_list, NULL,
&lib_ctx);
if (R_ERROR_NONE != ret)
goto end;
/* Enable resource selection tracing */
ret = R_LIB_CTX_add_resource(lib_ctx, R_SELECT_RES_TRACING);
if (R_ERROR_NONE != ret)
goto end;
ret = R_LIB_CTX_set_info(lib_ctx, R_LIB_CTX_INFO_ID_TRACER,
&tracer);
if (R_ERROR_NONE != ret)
goto end;
/* Perform cryptographic operations */
end:
R_LIB_CTX_free(lib_ctx);
R_STATE_cleanup();
return 0;
}