| 287 | } |
| 288 | |
| 289 | int |
| 290 | fips_test_init(const char *req_file_path, const char *rsp_file_path, |
| 291 | const char *device_name) |
| 292 | { |
| 293 | if (strcmp(req_file_path, rsp_file_path) == 0) { |
| 294 | RTE_LOG(ERR, USER1, "File paths cannot be the same\n"); |
| 295 | return -EINVAL; |
| 296 | } |
| 297 | |
| 298 | fips_test_clear(); |
| 299 | |
| 300 | if (rte_strscpy(info.file_name, req_file_path, |
| 301 | sizeof(info.file_name)) < 0) { |
| 302 | RTE_LOG(ERR, USER1, "Path %s too long\n", req_file_path); |
| 303 | return -EINVAL; |
| 304 | } |
| 305 | info.algo = FIPS_TEST_ALGO_MAX; |
| 306 | if (parse_file_type(req_file_path) < 0) { |
| 307 | RTE_LOG(ERR, USER1, "File %s type not supported\n", |
| 308 | req_file_path); |
| 309 | return -EINVAL; |
| 310 | } |
| 311 | |
| 312 | info.fp_rd = fopen(req_file_path, "r"); |
| 313 | if (!info.fp_rd) { |
| 314 | RTE_LOG(ERR, USER1, "Cannot open file %s\n", req_file_path); |
| 315 | return -EINVAL; |
| 316 | } |
| 317 | |
| 318 | if (info.file_type == FIPS_TYPE_JSON) { |
| 319 | #ifdef USE_JANSSON |
| 320 | json_error_t error; |
| 321 | json_info.json_root = json_loadf(info.fp_rd, 0, &error); |
| 322 | if (!json_info.json_root) { |
| 323 | RTE_LOG(ERR, USER1, "Cannot parse json file %s (line %d, column %d)\n", |
| 324 | req_file_path, error.line, error.column); |
| 325 | return -EINVAL; |
| 326 | } |
| 327 | #else /* USE_JANSSON */ |
| 328 | RTE_LOG(ERR, USER1, "No json library configured.\n"); |
| 329 | return -EINVAL; |
| 330 | #endif /* USE_JANSSON */ |
| 331 | } |
| 332 | |
| 333 | info.fp_wr = fopen(rsp_file_path, "w"); |
| 334 | if (!info.fp_wr) { |
| 335 | RTE_LOG(ERR, USER1, "Cannot open file %s\n", rsp_file_path); |
| 336 | return -EINVAL; |
| 337 | } |
| 338 | |
| 339 | info.one_line_text = calloc(1, MAX_LINE_CHAR); |
| 340 | if (!info.one_line_text) { |
| 341 | RTE_LOG(ERR, USER1, "Insufficient memory\n"); |
| 342 | return -ENOMEM; |
| 343 | } |
| 344 | |
| 345 | if (rte_strscpy(info.device_name, device_name, |
| 346 | sizeof(info.device_name)) < 0) { |
no test coverage detected