Made check_signature() a bit clearer.

This commit is contained in:
default 2024-01-03 08:56:17 +01:00
parent 556c72fec3
commit 6bd8aed25d

31
http.c
View file

@ -140,25 +140,32 @@ int check_signature(xs_dict *req, xs_str **err)
{ {
/* extract the values */ /* extract the values */
xs *l = xs_split(sig_hdr, ","); xs *l = xs_split(sig_hdr, ",");
xs_list *p; xs_list *p = l;
xs_val *v; xs_val *v;
p = l;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
if (xs_startswith(v, "keyId")) xs *kv = xs_split_n(v, "=", 1);
keyId = xs_crop_i(xs_dup(v), 7, -1);
if (xs_list_len(kv) != 2)
continue;
xs *k1 = xs_strip_i(xs_dup(xs_list_get(kv, 0)));
xs *v1 = xs_strip_chars_i(xs_dup(xs_list_get(kv, 1)), " \"");
if (!strcmp(k1, "keyId"))
keyId = xs_dup(v1);
else else
if (xs_startswith(v, "headers")) if (!strcmp(k1, "headers"))
headers = xs_crop_i(xs_dup(v), 9, -1); headers = xs_dup(v1);
else else
if (xs_startswith(v, "signature")) if (!strcmp(k1, "signature"))
signature = xs_crop_i(xs_dup(v), 11, -1); signature = xs_dup(v1);
else else
if (xs_startswith(v, "created")) if (!strcmp(k1, "created"))
created = xs_crop_i(xs_dup(v), 9, -1); created = xs_dup(v1);
else else
if (xs_startswith(v, "expires")) if (!strcmp(k1, "expires"))
expires = xs_crop_i(xs_dup(v), 9, -1); expires = xs_dup(v1);
} }
} }