Julian Hall | a7e89b0 | 2020-11-23 17:33:31 +0100 | [diff] [blame] | 1 | /* |
Julian Hall | 93df76a | 2022-09-22 17:30:06 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved. |
Julian Hall | a7e89b0 | 2020-11-23 17:33:31 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Julian Hall | 93df76a | 2022-09-22 17:30:06 +0100 | [diff] [blame] | 7 | #ifndef COMMON_UUID_H |
| 8 | #define COMMON_UUID_H |
Julian Hall | a7e89b0 | 2020-11-23 17:33:31 +0100 | [diff] [blame] | 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 |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
| 21 | /* |
| 22 | * Structure for holding an octet representation of a UUID. |
| 23 | */ |
| 24 | struct 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 | */ |
| 32 | struct uuid_canonical |
| 33 | { |
| 34 | char characters[UUID_CANONICAL_FORM_LEN + 1]; |
| 35 | }; |
| 36 | |
| 37 | /* |
Julian Hall | 7c2ae0c | 2022-09-29 08:27:07 +0100 | [diff] [blame] | 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 |
Julian Hall | a7e89b0 | 2020-11-23 17:33:31 +0100 | [diff] [blame] | 40 | * if the string is invalid in some way. |
| 41 | */ |
| 42 | size_t uuid_is_valid(const char *canonical_form); |
| 43 | |
| 44 | /* |
Julian Hall | 7c2ae0c | 2022-09-29 08:27:07 +0100 | [diff] [blame] | 45 | * 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 Hall | a7e89b0 | 2020-11-23 17:33:31 +0100 | [diff] [blame] | 48 | */ |
Julian Hall | 7c2ae0c | 2022-09-29 08:27:07 +0100 | [diff] [blame] | 49 | size_t uuid_parse_to_octets(const char *canonical_form, |
| 50 | uint8_t *buf, size_t buf_size); |
Julian Hall | a7e89b0 | 2020-11-23 17:33:31 +0100 | [diff] [blame] | 51 | |
| 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 Hall | 7c2ae0c | 2022-09-29 08:27:07 +0100 | [diff] [blame] | 57 | size_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 | */ |
| 64 | void uuid_reverse_octets(const struct uuid_octets *standard_encoding, |
| 65 | uint8_t *buf, size_t buf_size); |
Julian Hall | a7e89b0 | 2020-11-23 17:33:31 +0100 | [diff] [blame] | 66 | |
| 67 | |
| 68 | #ifdef __cplusplus |
| 69 | } |
| 70 | #endif |
| 71 | |
Julian Hall | 93df76a | 2022-09-22 17:30:06 +0100 | [diff] [blame] | 72 | #endif /* COMMON_UUID_H */ |