blob: e45e37afca2391af6eda68396f5089ed8ed07943 [file] [log] [blame]
Julian Halla7e89b02020-11-23 17:33:31 +01001/*
2 * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef UUID_H
8#define UUID_H
9
10#include <stddef.h>
11#include <stdint.h>
12
13#define UUID_OCTETS_LEN (16)
14#define UUID_CANONICAL_FORM_LEN (36)
15
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21/*
22 * Structure for holding an octet representation of a UUID.
23 */
24struct uuid_octets
25{
26 uint8_t octets[UUID_OCTETS_LEN];
27};
28
29/*
30 * Structure for holding an canonical string representation of a UUID.
31 */
32struct uuid_canonical
33{
34 char characters[UUID_CANONICAL_FORM_LEN + 1];
35};
36
37/*
38 * Check if uuid string in canonical form is valid. Returns the number of
39 * valid characters. This will either be UUID_CANONICAL_FORM_LEN or zero
40 * if the string is invalid in some way.
41 */
42size_t uuid_is_valid(const char *canonical_form);
43
44/*
45 * Parses a uuid string in canonical string form, outputing as an array of bytes.
46 * Returns the number of characters parsed from the input string. Returns zero
47 * if there is a parsing error.
48 */
49size_t uuid_parse_to_octets(const char *canonical_form, uint8_t *buf, size_t buf_size);
50
51/*
52 * Parses a uuid string in canonical string form but instead of outputting octets
53 * in standard byte order, octets from each section of the canonical uuid are
54 * reversed.
55 */
56size_t uuid_parse_to_octets_reversed(const char *canonical_form, uint8_t *buf, size_t buf_size);
57
58
59#ifdef __cplusplus
60}
61#endif
62
63#endif /* UUID_H */