Switch to crypt_jobj_to_string_on_disk().

Use single function when we require json format
string representation for on disk format.
This commit is contained in:
Ondrej Kozina
2025-02-06 13:59:11 +01:00
committed by Milan Broz
parent 07e8628940
commit 000f03ad31
3 changed files with 5 additions and 14 deletions

View File

@@ -424,8 +424,7 @@ int LUKS2_disk_hdr_write(struct crypt_device *cd, struct luks2_hdr *hdr, struct
/*
* Generate text space-efficient JSON representation to json area.
*/
json_text = json_object_to_json_string_ext(hdr->jobj,
JSON_C_TO_STRING_PLAIN | JSON_C_TO_STRING_NOSLASHESCAPE);
json_text = crypt_jobj_to_string_on_disk(hdr->jobj);
if (!json_text || !*json_text) {
log_dbg(cd, "Cannot parse JSON object to text representation.");
free(json_area);

View File

@@ -467,8 +467,7 @@ static int hdr_validate_json_size(struct crypt_device *cd, json_object *hdr_jobj
json_object_object_get_ex(hdr_jobj, "config", &jobj);
json_object_object_get_ex(jobj, "json_size", &jobj1);
json = json_object_to_json_string_ext(hdr_jobj,
JSON_C_TO_STRING_PLAIN | JSON_C_TO_STRING_NOSLASHESCAPE);
json = crypt_jobj_to_string_on_disk(hdr_jobj);
if (!json)
return 1;

View File

@@ -443,12 +443,6 @@ crypt_token_info LUKS2_token_status(struct crypt_device *cd,
return is_builtin_candidate(tmp) ? CRYPT_TOKEN_INTERNAL_UNKNOWN : CRYPT_TOKEN_EXTERNAL_UNKNOWN;
}
static const char *token_json_to_string(json_object *jobj_token)
{
return json_object_to_json_string_ext(jobj_token,
JSON_C_TO_STRING_PLAIN | JSON_C_TO_STRING_NOSLASHESCAPE);
}
static int token_is_usable(struct luks2_hdr *hdr, json_object *jobj_token, int keyslot, int segment,
crypt_keyslot_priority minimal_priority, bool requires_keyslot)
{
@@ -548,7 +542,7 @@ static int token_open(struct crypt_device *cd,
if (!(h = LUKS2_token_handler(cd, token)))
return -ENOENT;
if (h->validate && h->validate(cd, token_json_to_string(jobj_token))) {
if (h->validate && h->validate(cd, crypt_jobj_to_string_on_disk(jobj_token))) {
log_dbg(cd, "Token %d (%s) validation failed.", token, h->name);
return -ENOENT;
}
@@ -851,8 +845,7 @@ void LUKS2_token_dump(struct crypt_device *cd, int token)
if (h && h->dump) {
jobj_token = LUKS2_get_token_jobj(crypt_get_hdr(cd, CRYPT_LUKS2), token);
if (jobj_token)
h->dump(cd, json_object_to_json_string_ext(jobj_token,
JSON_C_TO_STRING_PLAIN | JSON_C_TO_STRING_NOSLASHESCAPE));
h->dump(cd, crypt_jobj_to_string_on_disk(jobj_token));
}
}
@@ -864,7 +857,7 @@ int LUKS2_token_json_get(struct luks2_hdr *hdr, int token, const char **json)
if (!jobj_token)
return -EINVAL;
*json = token_json_to_string(jobj_token);
*json = crypt_jobj_to_string_on_disk(jobj_token);
return 0;
}