41 unescape (
const char *str,
size_t len)
43 char *out = malloc (len + 1);
49 while (len > 0 && *str)
51 if (len >= 3 && str[0] ==
'=' && str[1] ==
'2' && str[2] ==
'C')
57 else if (len >= 3 && str[0] ==
'=' && str[1] ==
'3' && str[2] ==
'D')
82 if (strnlen (str, len) < 10)
85 if (len == 0 || (*str !=
'n' && *str !=
'y' && *str !=
'p'))
94 if (len == 0 || *str !=
'=')
98 p = memchr (str,
',', len);
101 cf->
cbname = malloc (p - str + 1);
104 memcpy (cf->
cbname, str, p - str);
105 cf->
cbname[p - str] =
'\0';
110 if (len == 0 || *str !=
',')
122 if (len == 0 || *str !=
'=')
126 p = memchr (str,
',', len);
134 cf->
authzid = unescape (str, l);
142 if (len == 0 || *str !=
',')
146 if (len == 0 || *str !=
'n')
150 if (len == 0 || *str !=
'=')
158 p = memchr (str,
',', len);
174 if (len == 0 || *str !=
',')
178 if (len == 0 || *str !=
'r')
182 if (len == 0 || *str !=
'=')
190 p = memchr (str,
',', len);
224 if (strnlen (str, len) < 15)
227 if (len == 0 || *str !=
'r')
231 if (len == 0 || *str !=
'=')
239 p = memchr (str,
',', len);
247 sf->
nonce = malloc (l + 1);
251 memcpy (sf->
nonce, str, l);
258 if (len == 0 || *str !=
',')
262 if (len == 0 || *str !=
's')
266 if (len == 0 || *str !=
'=')
274 p = memchr (str,
',', len);
282 sf->
salt = malloc (l + 1);
286 memcpy (sf->
salt, str, l);
293 if (len == 0 || *str !=
',')
297 if (len == 0 || *str !=
'i')
301 if (len == 0 || *str !=
'=')
306 for (; len > 0 && *str >=
'0' && *str <=
'9'; str++, len--)
308 size_t last_iter = sf->
iter;
310 sf->
iter = sf->
iter * 10 + (*str -
'0');
313 if (sf->
iter < last_iter)
317 if (len > 0 && *str !=
',')
335 if (strnlen (str, len) < 18)
338 if (len == 0 || *str !=
'c')
342 if (len == 0 || *str !=
'=')
350 p = memchr (str,
',', len);
358 cl->
cbind = malloc (l + 1);
362 memcpy (cl->
cbind, str, l);
369 if (len == 0 || *str !=
',')
373 if (len == 0 || *str !=
'r')
377 if (len == 0 || *str !=
'=')
385 p = memchr (str,
',', len);
393 cl->
nonce = malloc (l + 1);
397 memcpy (cl->
nonce, str, l);
404 if (len == 0 || *str !=
',')
409 while (len > 0 && c_isalpha (*str) && *str !=
'p')
416 if (len == 0 || *str !=
'=')
420 p = memchr (str,
',', len);
433 if (len == 0 || *str !=
'p')
437 if (len == 0 || *str !=
'=')
442 if (memchr (str,
'\0', len))
445 cl->
proof = malloc (len + 1);
449 memcpy (cl->
proof, str, len);
450 cl->
proof[len] =
'\0';
465 if (strnlen (str, len) < 6)
468 if (len == 0 || *str !=
'v')
472 if (len == 0 || *str !=
'=')
477 if (memchr (str,
'\0', len))
int scram_parse_client_final(const char *str, size_t len, struct scram_client_final *cl)
int scram_parse_client_first(const char *str, size_t len, struct scram_client_first *cf)
int scram_parse_server_final(const char *str, size_t len, struct scram_server_final *sl)
int scram_parse_server_first(const char *str, size_t len, struct scram_server_first *sf)
bool scram_valid_client_first(struct scram_client_first *cf)
bool scram_valid_server_final(struct scram_server_final *sl)
bool scram_valid_server_first(struct scram_server_first *sf)
bool scram_valid_client_final(struct scram_client_final *cl)
void scram_free_server_first(struct scram_server_first *sf)
void scram_free_client_first(struct scram_client_first *cf)
void scram_free_server_final(struct scram_server_final *sl)
void scram_free_client_final(struct scram_client_final *cl)