util-lib,tests: rework unbase64 so that we skip over whitespace automatically (#7522)
Let's optimize things a bit, and instead of having to strip whitespace first before decoding base64, let's do that implicitly while doing so. Given that base64 was designed the way it was designed specifically to be tolerant to whitespace changes, it's a good idea to do this automatically and implicitly.
This commit is contained in:
committed by
Yu Watanabe
parent
84786b8e32
commit
081f36d82d
@@ -415,19 +415,12 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
|
||||
r = sd_bus_message_append(m, "v", "s", eq);
|
||||
|
||||
else if (streq(field, "StandardInputData")) {
|
||||
_cleanup_free_ char *cleaned = NULL;
|
||||
_cleanup_free_ void *decoded = NULL;
|
||||
size_t sz;
|
||||
|
||||
cleaned = strdup(eq);
|
||||
if (!cleaned)
|
||||
return log_oom();
|
||||
|
||||
delete_chars(cleaned, WHITESPACE);
|
||||
|
||||
r = unbase64mem(cleaned, (size_t) -1, &decoded, &sz);
|
||||
r = unbase64mem(eq, (size_t) -1, &decoded, &sz);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to decode base64 data '%s': %m", cleaned);
|
||||
return log_error_errno(r, "Failed to decode base64 data '%s': %m", eq);
|
||||
|
||||
r = sd_bus_message_open_container(m, 'v', "ay");
|
||||
if (r < 0)
|
||||
|
||||
Reference in New Issue
Block a user