snac2

Fork of https://codeberg.org/grunfink/snac2
git clone https://git.inz.fi/snac2
Log | Files | Refs | README | LICENSE

commit 6bd8aed25d5d544927a404f8e3ce7cd8d4b839ce
parent 556c72fec3ac5e00406874299dc883e68f686aec
Author: default <nobody@localhost>
Date:   Wed,  3 Jan 2024 08:56:17 +0100

Made check_signature() a bit clearer.

Diffstat:
Mhttp.c | 31+++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/http.c b/http.c @@ -140,25 +140,32 @@ int check_signature(xs_dict *req, xs_str **err) { /* extract the values */ xs *l = xs_split(sig_hdr, ","); - xs_list *p; + xs_list *p = l; xs_val *v; - p = l; while (xs_list_iter(&p, &v)) { - if (xs_startswith(v, "keyId")) - keyId = xs_crop_i(xs_dup(v), 7, -1); + xs *kv = xs_split_n(v, "=", 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 - if (xs_startswith(v, "headers")) - headers = xs_crop_i(xs_dup(v), 9, -1); + if (!strcmp(k1, "headers")) + headers = xs_dup(v1); else - if (xs_startswith(v, "signature")) - signature = xs_crop_i(xs_dup(v), 11, -1); + if (!strcmp(k1, "signature")) + signature = xs_dup(v1); else - if (xs_startswith(v, "created")) - created = xs_crop_i(xs_dup(v), 9, -1); + if (!strcmp(k1, "created")) + created = xs_dup(v1); else - if (xs_startswith(v, "expires")) - expires = xs_crop_i(xs_dup(v), 9, -1); + if (!strcmp(k1, "expires")) + expires = xs_dup(v1); } }