blob: 02d83b6ca770453ee7ab3d0661fe335c9fd35f2b [file] [log] [blame]
Julian Halla7e89b02020-11-23 17:33:31 +01001/*
Julian Hall93df76a2022-09-22 17:30:06 +01002 * Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
Julian Halla7e89b02020-11-23 17:33:31 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Julian Hall93df76a2022-09-22 17:30:06 +01007#ifndef COMMON_UUID_H
8#define COMMON_UUID_H
Julian Halla7e89b02020-11-23 17:33:31 +01009
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/*
Julian Hall7c2ae0c2022-09-29 08:27:07 +010038 * 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
Julian Halla7e89b02020-11-23 17:33:31 +010040 * if the string is invalid in some way.
41 */
42size_t uuid_is_valid(const char *canonical_form);
43
44/*
Julian Hall7c2ae0c2022-09-29 08:27:07 +010045 * Parses a uuid string in canonical string form, outputting as an array of bytes
46 * in the standard big endian byte order. Returns the number of characters parsed
47 * from the input string. Returns zero if there is a parsing error.
Julian Halla7e89b02020-11-23 17:33:31 +010048 */
Julian Hall7c2ae0c2022-09-29 08:27:07 +010049size_t uuid_parse_to_octets(const char *canonical_form,
50 uint8_t *buf, size_t buf_size);
Julian Halla7e89b02020-11-23 17:33:31 +010051
52/*
53 * Parses a uuid string in canonical string form but instead of outputting octets
54 * in standard byte order, octets from each section of the canonical uuid are
55 * reversed.
56 */
Julian Hall7c2ae0c2022-09-29 08:27:07 +010057size_t uuid_parse_to_octets_reversed(const char *canonical_form,
58 uint8_t *buf, size_t buf_size);
59
60/*
61 * Reverses bytes from the normal big endian binary encoding to the reversed encoding used
62 * by tf-a and optee (same byte order as uuid_parse_to_octets_reversed()).
63 */
64void uuid_reverse_octets(const struct uuid_octets *standard_encoding,
65 uint8_t *buf, size_t buf_size);
Julian Halla7e89b02020-11-23 17:33:31 +010066
67
68#ifdef __cplusplus
69}
70#endif
71
Julian Hall93df76a2022-09-22 17:30:06 +010072#endif /* COMMON_UUID_H */