diff mbox

[1/2] lib: fwts_guid: Add fwts_guid_str_to_buf to convert string back to a GUID

Message ID 1346869717-16964-2-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King Sept. 5, 2012, 6:28 p.m. UTC
From: Colin Ian King <colin.king@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@canonical.com>
---
 src/lib/include/fwts_guid.h |    1 +
 src/lib/src/fwts_guid.c     |   14 ++++++++++++++
 2 files changed, 15 insertions(+)

Comments

Alex Hung Sept. 10, 2012, 2:46 a.m. UTC | #1
On 09/06/2012 02:28 AM, Colin King wrote:
> From: Colin Ian King <colin.king@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@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]);
> +	}
> +}
>

Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin Sept. 11, 2012, 6:13 a.m. UTC | #2
On Thu, Sep 6, 2012 at 2:28 AM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@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@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
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
diff mbox

Patch

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]);
+	}
+}