tpm2_attr_util.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. #ifndef LIB_TPM2_ATTR_UTIL_H_
  3. #define LIB_TPM2_ATTR_UTIL_H_
  4. #include <stdbool.h>
  5. #include <tss2/tss2_sys.h>
  6. /**
  7. * Converts a list of | (pipe) separated attributes as defined in tavle 204
  8. * of https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf
  9. * to an actual bit field representation. The trailing TPMA_NV_ can be omitted and must be lower-case.
  10. * For example, TPMA_NV_PPWRITE, becomes ppwrite. To append them together, just do the pipe in between.
  11. * ppwrite|ownerwrite.
  12. *
  13. * @param attribute_list
  14. * The attribute string to parse, which may be modified in place.
  15. * @param nvattrs
  16. * The TPMA_NV attributes set based on the attribute list. Only valid on true returns.
  17. * @return
  18. * true on success, false on error.
  19. */
  20. bool tpm2_attr_util_nv_strtoattr(char *attribute_list, TPMA_NV *nvattrs);
  21. /**
  22. * Like tpm2_attr_util_nv_strtoattr() but converts TPMA_OBJECT attributes as defined in:
  23. * Table 31 of https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf
  24. * @param attribute_list
  25. * The attribute string to parse, which may be modified in place.
  26. * The TPMA_OBJECT attributes set based on the attribute list. Only valid on true returns.
  27. * @return
  28. * true on success, false on error.
  29. */
  30. bool tpm2_attr_util_obj_strtoattr(char *attribute_list, TPMA_OBJECT *objattrs);
  31. /**
  32. * Converts a numerical or friendly string described object attribute into the
  33. * TPMA_OBJECT. Similar to tpm2_alg_util_from_optarg().
  34. * @param argvalue
  35. * Either a raw numeric for a UINT32 or a friendly name object attribute list
  36. * as in tpm2_attr_util_nv_strtoattr().
  37. * @param objattrs
  38. * The converted bits for a TPMA_OBJECT
  39. * @return
  40. * true on success or false on error.
  41. */
  42. bool tpm2_attr_util_obj_from_optarg(char *argvalue, TPMA_OBJECT *objattrs);
  43. /**
  44. * Converts a TPMA_NV structure to a friendly name style string.
  45. * @param nvattrs
  46. * The nvattrs to convert to nice name.
  47. * @return A string allocated with calloc(), callers shall use
  48. * free() to free it. The string is a null terminated text representation
  49. * of the TPMA_NV attributes.
  50. */
  51. char *tpm2_attr_util_nv_attrtostr(TPMA_NV nvattrs);
  52. /**
  53. * Like tpm2_nv_util_obj_strtoattr() but converts TPMA_OBJECT attributes as defined in:
  54. * Table 31 of https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf
  55. * @param objattrs
  56. * The object parameters to convert to a name
  57. * @return
  58. * The name of the object attrs as a string that must be freed via free().
  59. */
  60. char *tpm2_attr_util_obj_attrtostr(TPMA_OBJECT objattrs);
  61. #endif /* LIB_TPM2_ATTR_UTIL_H_ */