[PATCH 1/2] lib: fwts_guid: Add fwts_guid_str_to_buf to convert string back to a GUID
Colin King
colin.king at canonical.com
Wed Sep 5 18:28:36 UTC 2012
From: Colin Ian King <colin.king at canonical.com>
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 <colin.king at canonical.com>
---
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 <stdint.h>
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]);
+ }
+}
--
1.7.10.4
More information about the fwts-devel
mailing list