blob: d36825d1fe19e83eae2fc93350ac494846f436c4 [file] [log] [blame]
Julian Hall201ce462021-04-29 11:05:34 +01001/*
2 * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef CLAIM_H
8#define CLAIM_H
9
10#include <stddef.h>
11#include <stdbool.h>
12#include <stdint.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18struct claim;
19
20/**
21 * An iterator for accessing claims within a collection. A concrete
22 * claim_iterator provides functions that understand a specific
23 * representation of measurements or observations.
24 */
25struct claim_iterator
26{
27 /**
28 * Initialise the iterator to the first claim
29 * in a collection.
30 */
31 void (*first)(struct claim_iterator *iter);
32
33 /**
34 * Advance the iterator to the next claim
35 * in a collection. Returns true if successful.
36 */
37 bool (*next)(struct claim_iterator *iter);
38
39 /**
40 * Check if iterator has reached the end of
41 * the collection.
42 */
43 bool (*is_done)(struct claim_iterator *iter);
44
45 /**
46 * Access the claim at the current iterator position.
47 * Returns true if there is a valid claim, else false.
48 */
49 bool (*current)(struct claim_iterator *iter, struct claim *claim);
50
51 /* Abstract handle marking the beginning of a collection */
52 const void *begin_pos;
53
54 /* Abstract handle marking the end of a collection */
55 const void *end_pos;
56
57 /* Abstract handle marking the current iterator position */
58 const void *cur_pos;
59};
60
61/**
62 * Claim variants for different types of claim.
63 */
64
65/* A variant for integer value claims */
66struct integer_claim_variant
67{
68 int32_t value;
69};
70
71/* A variant for zero terminated text string claims */
72struct text_string_claim_variant
73{
74 const char *string;
75};
76
77/* A variant for byte array claims */
78struct byte_string_claim_variant
79{
80 size_t len;
81 const uint8_t *bytes;
82};
83
84/* A variant for measurement claims that carry a digest that
85 * refects the security state of the mesaured component.
86 */
87struct measurement_claim_variant
88{
89 struct byte_string_claim_variant id;
90 struct byte_string_claim_variant digest;
91};
92
93/* A variant that is a container for 0..* claim objects */
94struct claim_collection_variant
95{
96 void (*create_iterator)(const struct claim_collection_variant *variant,
97 struct claim_iterator *iter);
98
99 const void *begin_pos;
100 const void *end_pos;
101};
102
103/**
104 * \brief Initializes an iterator to access a concrete claim collection
105 *
106 * \param[in] variant The claim variant to access
107 * \param[out] iter The iterator to initialize
108 */
109static inline void claim_collection_variant_create_iterator(
110 const struct claim_collection_variant *variant,
111 struct claim_iterator *iter)
112{
113 variant->create_iterator(variant, iter);
114}
115
116/**
117 * Claim subject identifier. Used for identifying what the claim relates
118 * to.
119 */
120enum claim_subject_id
121{
122 CLAIM_SUBJECT_ID_NONE = 0,
123 CLAIM_SUBJECT_ID_SW_COMPONENT,
124};
125
126/**
127 * Claim variant identifier. Identifies the concrete claim variant.
128 */
129enum claim_variant_id
130{
131 CLAIM_VARIANT_ID_UNSUPPORTED,
132 CLAIM_VARIANT_ID_INTEGER,
133 CLAIM_VARIANT_ID_TEXT_STRING,
134 CLAIM_VARIANT_ID_BYTE_STRING,
135 CLAIM_VARIANT_ID_MEASUREMENT,
136 CLAIM_VARIANT_ID_COLLECTION
137};
138
139/**
140 * The common claim structure, holds a particular variant, identified
141 * by the variant_id. A claim may be an arbitrarily deep tree or just
142 * a single node.
143 */
144struct claim
145{
146 enum claim_subject_id subject_id;
147 enum claim_variant_id variant_id;
148
149 /* Pointer to the raw record. Allows a client with
150 * knowledge of the record format to access additional
151 * information. NULL if not available.
152 */
153 const uint8_t *raw_data;
154
155 union claim_variant
156 {
157 struct integer_claim_variant integer;
158 struct text_string_claim_variant text_string;
159 struct byte_string_claim_variant byte_string;
160 struct measurement_claim_variant measurement;
161 struct claim_collection_variant collection;
162
163 } variant;
164};
165
166#ifdef __cplusplus
167} /* extern "C" */
168#endif
169
170#endif /* CLAIM_H */