summaryrefslogtreecommitdiff
path: root/src/shared/json.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-05-15 16:55:04 +0200
committerLennart Poettering <lennart@poettering.net>2019-12-02 09:47:00 +0100
commitb7fc90a2e63f6a90cd94b7fcd21997bb647eb454 (patch)
tree3ae591c4830f452c424641380fda3710c6b42cf4 /src/shared/json.h
parentca409a59c8eedb57692bceef00bfb248dbd92a76 (diff)
downloadsystemd-b7fc90a2e63f6a90cd94b7fcd21997bb647eb454.tar.gz
json: add concept of normalization
Let's add a concept of normalization: as preparation for signing json records let's add a mechanism to bring JSON records into a well-defined order so that we can safely validate JSON records. This adds two booleans to each JsonVariant object: "sorted" and "normalized". The latter indicates whether a variant is fully sorted (i.e. all keys of objects listed in alphabetical order) recursively down the tree. The former is a weaker property: it only checks whether the keys of the object itself are sorted. All variants which are "normalized" are also "sorted", but not vice versa. The knowledge of the "sorted" property is then used to optimize searching for keys in the variant by using bisection. Both properties are determined at the moment the variants are allocated. Since our objects are immutable this is safe.
Diffstat (limited to 'src/shared/json.h')
-rw-r--r--src/shared/json.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/shared/json.h b/src/shared/json.h
index 9ad08c625f..432a66fe41 100644
--- a/src/shared/json.h
+++ b/src/shared/json.h
@@ -123,6 +123,8 @@ static inline bool json_variant_is_null(JsonVariant *v) {
bool json_variant_is_negative(JsonVariant *v);
bool json_variant_is_blank_object(JsonVariant *v);
bool json_variant_is_blank_array(JsonVariant *v);
+bool json_variant_is_normalized(JsonVariant *v);
+bool json_variant_is_sorted(JsonVariant *v);
size_t json_variant_elements(JsonVariant *v);
JsonVariant *json_variant_by_index(JsonVariant *v, size_t index);
@@ -180,6 +182,9 @@ int json_variant_merge(JsonVariant **v, JsonVariant *m);
int json_variant_strv(JsonVariant *v, char ***ret);
+int json_variant_sort(JsonVariant **v);
+int json_variant_normalize(JsonVariant **v);
+
typedef enum JsonParseFlags {
JSON_PARSE_SENSITIVE = 1 << 0, /* mark variant as "sensitive", i.e. something containing secret key material or such */
} JsonParseFlags;