From 07e8628940f217645c000be051bcf40d59f68540 Mon Sep 17 00:00:00 2001 From: Ondrej Kozina Date: Thu, 6 Feb 2025 13:53:03 +0100 Subject: [PATCH] Add helper to unify json string format. Add a single function to use when generating json format string representation for on disk storage purposes so that it can be easily reused when needed. --- lib/luks2/luks2_internal.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/luks2/luks2_internal.h b/lib/luks2/luks2_internal.h index aca75a74..adaea91a 100644 --- a/lib/luks2/luks2_internal.h +++ b/lib/luks2/luks2_internal.h @@ -48,6 +48,16 @@ uint64_t crypt_jobj_get_uint64(json_object *jobj); uint32_t crypt_jobj_get_uint32(json_object *jobj); json_object *crypt_jobj_new_uint64(uint64_t value); +/* + * Generate json format string representation libcryptsetup uses + * to store json metadata on disk. + */ +static inline const char *crypt_jobj_to_string_on_disk(json_object *jobj) +{ + return json_object_to_json_string_ext(jobj, + JSON_C_TO_STRING_PLAIN | JSON_C_TO_STRING_NOSLASHESCAPE); +} + int json_object_object_add_by_uint(json_object *jobj, unsigned key, json_object *jobj_val); int json_object_object_add_by_uint_by_ref(json_object *jobj, unsigned key, json_object **jobj_val_ref); void json_object_object_del_by_uint(json_object *jobj, unsigned key);