in nsm-test/src/main.cc [56:114]
void get_nsm_description(int32_t ctx, NsmDescription &description)
{
char module_str[sizeof(description.module_id) + 1];
ErrorCode status;
// Get NSM description.
status = nsm_get_description(ctx, &description);
if (status != ERROR_CODE_SUCCESS) {
fprintf(stderr, "[Error] Request::DescribeNSM got invalid response: %s\n",
get_status_string(status));
exit(-1);
}
// The NSM must have exactly 32 PCRs.
if (description.max_pcrs != 32) {
fprintf(stderr, "[Error] NSM PCR count is %u.\n", description.max_pcrs);
exit(-1);
}
// Convert the NSM module id to a string.
memset(module_str, 0, sizeof(module_str));
memcpy(module_str, description.module_id, description.module_id_len);
// The NSM module id must not be empty.
if (strlen(module_str) == 0) {
fprintf(stderr, "[Error] NSM module ID is missing.\n");
exit(-1);
}
// Print the NSM description.
printf("NSM Description: [major: %u, minor: %u, patch: %u, module_id: %s, "
"max_pcrs: %u, locked_pcrs: {",
description.version_major, description.version_minor,
description.version_patch, module_str, description.max_pcrs);
// Print the list of locked PCRs.
if (description.locked_pcrs_len > 0) {
for (int i = 0; i < description.locked_pcrs_len - 1; ++i)
printf("%u, ", description.locked_pcrs[i]);
printf("%u", description.locked_pcrs[description.locked_pcrs_len - 1]);
}
// Print the digest type.
printf("}, digest: ");
switch (description.digest) {
case DIGEST_SHA256:
printf("SHA256].\n");
break;
case DIGEST_SHA384:
printf("SHA384].\n");
break;
case DIGEST_SHA512:
printf("SHA512].\n");
break;
}
}