1 /* SPDX-License-Identifier: MIT */
3 * Copyright (C) 2016 The Android Open Source Project
6 #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
7 #error "Never include this file directly, include libavb.h instead."
10 #ifndef AVB_PROPERTY_DESCRIPTOR_H_
11 #define AVB_PROPERTY_DESCRIPTOR_H_
13 #include "avb_descriptor.h"
19 /* A descriptor for properties (free-form key/value pairs).
21 * Following this struct are |key_num_bytes| bytes of key data,
22 * followed by a NUL byte, then |value_num_bytes| bytes of value data,
23 * followed by a NUL byte and then enough padding to make the combined
24 * size a multiple of 8.
26 typedef struct AvbPropertyDescriptor {
27 AvbDescriptor parent_descriptor;
28 uint64_t key_num_bytes;
29 uint64_t value_num_bytes;
30 } AVB_ATTR_PACKED AvbPropertyDescriptor;
32 /* Copies |src| to |dest| and validates, byte-swapping fields in the
33 * process if needed. Returns true if valid, false if invalid.
35 * Data following the struct is not validated nor copied.
37 bool avb_property_descriptor_validate_and_byteswap(
38 const AvbPropertyDescriptor* src,
39 AvbPropertyDescriptor* dest) AVB_ATTR_WARN_UNUSED_RESULT;
41 /* Convenience function for looking up the value for a property with
42 * name |key| in a vbmeta image. If |key_size| is 0, |key| must be
45 * The |image_data| parameter must be a pointer to a vbmeta image of
48 * This function returns a pointer to the value inside the passed-in
49 * image or NULL if not found. Note that the value is always
50 * guaranteed to be followed by a NUL byte.
52 * If the value was found and |out_value_size| is not NULL, the size
53 * of the value is returned there.
55 * This function is O(n) in number of descriptors so if you need to
56 * look up a lot of values, you may want to build a more efficient
57 * lookup-table by manually walking all descriptors using
58 * avb_descriptor_foreach().
60 * Before using this function, you MUST verify |image_data| with
61 * avb_vbmeta_image_verify() and reject it unless it's signed by a
62 * known good public key.
64 const char* avb_property_lookup(const uint8_t* image_data,
68 size_t* out_value_size)
69 AVB_ATTR_WARN_UNUSED_RESULT;
71 /* Like avb_property_lookup() but parses the intial portions of the
72 * value as an unsigned 64-bit integer. Both decimal and hexadecimal
73 * representations (e.g. "0x2a") are supported. Returns false on
74 * failure and true on success. On success, the parsed value is
75 * returned in |out_value|.
77 bool avb_property_lookup_uint64(const uint8_t* image_data,
82 AVB_ATTR_WARN_UNUSED_RESULT;
88 #endif /* AVB_PROPERTY_DESCRIPTOR_H_ */