blob: 2d9e90e2526feb4ad6dc2eb77a71fd72abdc5292 [file] [log] [blame]
Angel Pons118a9c72020-04-02 23:48:34 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Nico Huber2e6a0f82019-10-24 15:01:33 +02003
4#include <stdint.h>
5#include <lib.h>
6#include <uuid.h>
7
8int parse_uuid(uint8_t *const uuid, const char *const uuid_str)
9{
10 const uint8_t order[] = { 3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15 };
11 uint8_t uuid_binstr[UUID_LEN];
12 unsigned int i;
13
14 if (strlen(uuid_str) != UUID_STRLEN)
15 return -1;
16 if (uuid_str[8] != '-' || uuid_str[13] != '-' ||
17 uuid_str[18] != '-' || uuid_str[23] != '-')
18 return -1;
19 if (hexstrtobin(uuid_str, uuid_binstr, UUID_LEN) != UUID_LEN)
20 return -1;
21 for (i = 0; i < UUID_LEN; ++i)
22 uuid[i] = uuid_binstr[order[i]];
23
24 return 0;
25}