commit 6bd8aed

default  ·  2024-01-03 07:56:17 +0000 UTC
parent 556c72f
Made check_signature() a bit clearer.
1 files changed,  +19, -12
M http.c
M http.c
+19, -12
 1@@ -140,25 +140,32 @@ int check_signature(xs_dict *req, xs_str **err)
 2     {
 3         /* extract the values */
 4         xs *l = xs_split(sig_hdr, ",");
 5-        xs_list *p;
 6+        xs_list *p = l;
 7         xs_val *v;
 8 
 9-        p = l;
10         while (xs_list_iter(&p, &v)) {
11-            if (xs_startswith(v, "keyId"))
12-                keyId = xs_crop_i(xs_dup(v), 7, -1);
13+            xs *kv = xs_split_n(v, "=", 1);
14+
15+            if (xs_list_len(kv) != 2)
16+                continue;
17+
18+            xs *k1 = xs_strip_i(xs_dup(xs_list_get(kv, 0)));
19+            xs *v1 = xs_strip_chars_i(xs_dup(xs_list_get(kv, 1)), " \"");
20+
21+            if (!strcmp(k1, "keyId"))
22+                keyId = xs_dup(v1);
23             else
24-            if (xs_startswith(v, "headers"))
25-                headers = xs_crop_i(xs_dup(v), 9, -1);
26+            if (!strcmp(k1, "headers"))
27+                headers = xs_dup(v1);
28             else
29-            if (xs_startswith(v, "signature"))
30-                signature = xs_crop_i(xs_dup(v), 11, -1);
31+            if (!strcmp(k1, "signature"))
32+                signature = xs_dup(v1);
33             else
34-            if (xs_startswith(v, "created"))
35-                created = xs_crop_i(xs_dup(v), 9, -1);
36+            if (!strcmp(k1, "created"))
37+                created = xs_dup(v1);
38             else
39-            if (xs_startswith(v, "expires"))
40-                expires = xs_crop_i(xs_dup(v), 9, -1);
41+            if (!strcmp(k1, "expires"))
42+                expires = xs_dup(v1);
43         }
44     }
45