Add UUID helper component
Change-Id: I4227fd83fc81abb3e4d0a3be1dc7384eb8dfb4bc
Signed-off-by: Julian Hall <julian.hall@arm.com>
diff --git a/components/common/uuid/uuid.h b/components/common/uuid/uuid.h
new file mode 100644
index 0000000..e45e37a
--- /dev/null
+++ b/components/common/uuid/uuid.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef UUID_H
+#define UUID_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#define UUID_OCTETS_LEN (16)
+#define UUID_CANONICAL_FORM_LEN (36)
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Structure for holding an octet representation of a UUID.
+ */
+struct uuid_octets
+{
+ uint8_t octets[UUID_OCTETS_LEN];
+};
+
+/*
+ * Structure for holding an canonical string representation of a UUID.
+ */
+struct uuid_canonical
+{
+ char characters[UUID_CANONICAL_FORM_LEN + 1];
+};
+
+/*
+ * Check if uuid string in canonical form is valid. Returns the number of
+ * valid characters. This will either be UUID_CANONICAL_FORM_LEN or zero
+ * if the string is invalid in some way.
+ */
+size_t uuid_is_valid(const char *canonical_form);
+
+/*
+ * Parses a uuid string in canonical string form, outputing as an array of bytes.
+ * Returns the number of characters parsed from the input string. Returns zero
+ * if there is a parsing error.
+ */
+size_t uuid_parse_to_octets(const char *canonical_form, uint8_t *buf, size_t buf_size);
+
+/*
+ * Parses a uuid string in canonical string form but instead of outputting octets
+ * in standard byte order, octets from each section of the canonical uuid are
+ * reversed.
+ */
+size_t uuid_parse_to_octets_reversed(const char *canonical_form, uint8_t *buf, size_t buf_size);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* UUID_H */