parse_key_string * parse x:x:x:x.... hex number key string into uint8_t *key * return: * > 0: number of bytes parsed * 0: failed */
| 312 | * 0: failed |
| 313 | */ |
| 314 | static uint32_t |
| 315 | parse_key_string(const char *key_str, uint8_t *key) |
| 316 | { |
| 317 | const char *pt_start = key_str, *pt_end = key_str; |
| 318 | uint32_t nb_bytes = 0; |
| 319 | |
| 320 | while (pt_end != NULL) { |
| 321 | char sub_str[3] = {0}; |
| 322 | |
| 323 | pt_end = strchr(pt_start, ':'); |
| 324 | |
| 325 | if (pt_end == NULL) { |
| 326 | if (strlen(pt_start) > 2) |
| 327 | return 0; |
| 328 | strncpy(sub_str, pt_start, 2); |
| 329 | } else { |
| 330 | if (pt_end - pt_start > 2) |
| 331 | return 0; |
| 332 | |
| 333 | strncpy(sub_str, pt_start, pt_end - pt_start); |
| 334 | pt_start = pt_end + 1; |
| 335 | } |
| 336 | |
| 337 | key[nb_bytes++] = strtol(sub_str, NULL, 16); |
| 338 | } |
| 339 | |
| 340 | return nb_bytes; |
| 341 | } |
| 342 | |
| 343 | static int |
| 344 | extend_sa_arr(struct ipsec_sa **sa_tbl, uint32_t cur_cnt, uint32_t *cur_sz) |
no test coverage detected