From patchwork Wed Sep 5 18:28:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1/2] lib: fwts_guid: Add fwts_guid_str_to_buf to convert string back to a GUID From: Colin King X-Patchwork-Id: 181909 Message-Id: <1346869717-16964-2-git-send-email-colin.king@canonical.com> To: fwts-devel@lists.ubuntu.com Date: Wed, 5 Sep 2012 19:28:36 +0100 From: Colin Ian King We need to convert GUIDs in ASCII strings back to a 16 byte GUID for some of the UEFI variable GUID string handling. Signed-off-by: Colin Ian King Acked-by: Alex Hung Acked-by: Keng-Yu Lin --- src/lib/include/fwts_guid.h | 1 + src/lib/src/fwts_guid.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/lib/include/fwts_guid.h b/src/lib/include/fwts_guid.h index d836948..ba5ee6c 100644 --- a/src/lib/include/fwts_guid.h +++ b/src/lib/include/fwts_guid.h @@ -24,5 +24,6 @@ #include void fwts_guid_buf_to_str(uint8_t *guid, char *guid_str, size_t guid_str_len); +void fwts_guid_str_to_buf(const char *guid_str, uint8_t *guid, size_t guid_len); #endif diff --git a/src/lib/src/fwts_guid.c b/src/lib/src/fwts_guid.c index 510cb25..b4e9b07 100644 --- a/src/lib/src/fwts_guid.c +++ b/src/lib/src/fwts_guid.c @@ -33,3 +33,17 @@ void fwts_guid_buf_to_str(uint8_t *guid, char *guid_str, size_t guid_str_len) guid[3], guid[2], guid[1], guid[0], guid[5], guid[4], guid[7], guid[6], guid[8], guid[9], guid[10], guid[11], guid[12], guid[13], guid[14], guid[15]); } + +/* + * fwts_guid_str_to_buf() + * convert a GUID string back to a 16 byte GUID + * guid needs to be at least 16 chars long + */ +void fwts_guid_str_to_buf(const char *guid_str, uint8_t *guid, size_t guid_len) +{ + if (guid && guid_len >= 16) { + sscanf(guid_str, "%2hhx%2hhx%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx", + &guid[3], &guid[2], &guid[1], &guid[0], &guid[5], &guid[4], &guid[7], &guid[6], + &guid[8], &guid[9], &guid[10], &guid[11], &guid[12], &guid[13], &guid[14], &guid[15]); + } +}