1 //**********************************************************************;
2 // Copyright (c) 2017, Intel Corporation
3 // All rights reserved.
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
15 // 3. Neither the name of Intel Corporation nor the names of its contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 // THE POSSIBILITY OF SUCH DAMAGE.
30 //**********************************************************************;
31 #ifndef LIB_TPM2_ATTR_UTIL_H_
32 #define LIB_TPM2_ATTR_UTIL_H_
36 #include <tss2/tss2_sys.h>
39 * Converts a list of | (pipe) separated attributes as defined in tavle 204
40 * of https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf
41 * to an actual bit field representation. The trailing TPMA_NV_ can be omitted and must be lower-case.
42 * For exmaple, TPMA_NV_PPWRITE, bcomes ppwrite. To append them together, just do the pipe inbetwwen.
45 * @param attribute_list
46 * The attribute string to parse, which may be modified in place.
48 * The TPMA_NV attributes set based on the attribute list. Only valid on true returns.
50 * true on success, false on error.
52 bool tpm2_attr_util_nv_strtoattr(char *attribute_list, TPMA_NV *nvattrs);
55 * Like tpm2_attr_util_nv_strtoattr() but converts TPMA_OBJECT attributes as defined in:
56 * Table 31 of https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf
57 * @param attribute_list
58 * The attribute string to parse, which may be modified in place.
59 * The TPMA_OBJECT attributes set based on the attribute list. Only valid on true returns.
61 * true on success, false on error.
63 bool tpm2_attr_util_obj_strtoattr(char *attribute_list, TPMA_OBJECT *objattrs);
66 * Converts a numerical or friendly string described object attribute into the
67 * TPMA_OBJECT. Similar to tpm2_alg_util_from_optarg().
69 * Either a raw numeric for a UINT32 or a friendly name object attribute list
70 * as in tpm2_attr_util_nv_strtoattr().
72 * The converted bits for a TPMA_OBJECT
74 * true on success or false on error.
76 bool tpm2_attr_util_obj_from_optarg(char *argvalue, TPMA_OBJECT *objattrs);
79 * Converts a TPMA_NV structure to a friendly name style string.
81 * The nvattrs to convert to nice name.
82 * @return A string allocated with calloc(), callers shall use
83 * free() to free it. The string is a null terminated text representation
84 * of the TPMA_NV attributes.
86 char *tpm2_attr_util_nv_attrtostr(TPMA_NV nvattrs);
89 * Like tpm2_nv_util_obj_strtoattr() but converts TPMA_OBJECT attributes as defined in:
90 * Table 31 of https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf
92 * The object parameters to convert to a name
94 * The name of the object attrs as a string that must be freed via free().
96 char *tpm2_attr_util_obj_attrtostr(TPMA_OBJECT objattrs);
98 #endif /* LIB_TPM2_ATTR_UTIL_H_ */