/src/libphdi/libphdi/libphdi_uuid_string.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * UUID string functions | 
| 3 |  |  * | 
| 4 |  |  * Copyright (C) 2015-2024, Joachim Metz <joachim.metz@gmail.com> | 
| 5 |  |  * | 
| 6 |  |  * Refer to AUTHORS for acknowledgements. | 
| 7 |  |  * | 
| 8 |  |  * This program is free software: you can redistribute it and/or modify | 
| 9 |  |  * it under the terms of the GNU Lesser General Public License as published by | 
| 10 |  |  * the Free Software Foundation, either version 3 of the License, or | 
| 11 |  |  * (at your option) any later version. | 
| 12 |  |  * | 
| 13 |  |  * This program is distributed in the hope that it will be useful, | 
| 14 |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 15 |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| 16 |  |  * GNU General Public License for more details. | 
| 17 |  |  * | 
| 18 |  |  * You should have received a copy of the GNU Lesser General Public License | 
| 19 |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>. | 
| 20 |  |  */ | 
| 21 |  |  | 
| 22 |  | #include <common.h> | 
| 23 |  | #include <types.h> | 
| 24 |  |  | 
| 25 |  | #include "libphdi_libfguid.h" | 
| 26 |  | #include "libphdi_uuid_string.h" | 
| 27 |  |  | 
| 28 |  | /* Copies an UUID string to a byte stream | 
| 29 |  |  * Returns 1 if successful or -1 on error | 
| 30 |  |  */ | 
| 31 |  | int libphdi_uuid_string_copy_to_byte_stream( | 
| 32 |  |      const uint8_t *utf8_string, | 
| 33 |  |      size_t utf8_string_length, | 
| 34 |  |      uint8_t *byte_stream, | 
| 35 |  |      size_t byte_stream_size, | 
| 36 |  |      libcerror_error_t **error ) | 
| 37 | 0 | { | 
| 38 | 0 |   libfguid_identifier_t *guid = NULL; | 
| 39 | 0 |   static char *function       = "libphdi_uuid_string_copy_to_byte_stream"; | 
| 40 |  | 
 | 
| 41 | 0 |   if( libfguid_identifier_initialize( | 
| 42 | 0 |        &guid, | 
| 43 | 0 |        error ) != 1 ) | 
| 44 | 0 |   { | 
| 45 | 0 |     libcerror_error_set( | 
| 46 | 0 |      error, | 
| 47 | 0 |      LIBCERROR_ERROR_DOMAIN_RUNTIME, | 
| 48 | 0 |      LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, | 
| 49 | 0 |      "%s: unable to create GUID.", | 
| 50 | 0 |      function ); | 
| 51 |  | 
 | 
| 52 | 0 |     goto on_error; | 
| 53 | 0 |   } | 
| 54 | 0 |   if( libfguid_identifier_copy_from_utf8_string( | 
| 55 | 0 |        guid, | 
| 56 | 0 |        utf8_string, | 
| 57 | 0 |        utf8_string_length, | 
| 58 | 0 |        LIBFGUID_STRING_FORMAT_FLAG_USE_MIXED_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES, | 
| 59 | 0 |        error ) != 1 ) | 
| 60 | 0 |   { | 
| 61 | 0 |     libcerror_error_set( | 
| 62 | 0 |      error, | 
| 63 | 0 |      LIBCERROR_ERROR_DOMAIN_RUNTIME, | 
| 64 | 0 |      LIBCERROR_RUNTIME_ERROR_SET_FAILED, | 
| 65 | 0 |      "%s: unable to copy GUID from UTF-8 string.", | 
| 66 | 0 |      function ); | 
| 67 |  | 
 | 
| 68 | 0 |     goto on_error; | 
| 69 | 0 |   } | 
| 70 | 0 |   if( libfguid_identifier_copy_to_byte_stream( | 
| 71 | 0 |        guid, | 
| 72 | 0 |        byte_stream, | 
| 73 | 0 |        byte_stream_size, | 
| 74 | 0 |        LIBFGUID_ENDIAN_BIG, | 
| 75 | 0 |        error ) != 1 ) | 
| 76 | 0 |   { | 
| 77 | 0 |     libcerror_error_set( | 
| 78 | 0 |      error, | 
| 79 | 0 |      LIBCERROR_ERROR_DOMAIN_RUNTIME, | 
| 80 | 0 |      LIBCERROR_RUNTIME_ERROR_SET_FAILED, | 
| 81 | 0 |      "%s: unable to copy GUID to byte stream.", | 
| 82 | 0 |      function ); | 
| 83 |  | 
 | 
| 84 | 0 |     goto on_error; | 
| 85 | 0 |   } | 
| 86 | 0 |   if( libfguid_identifier_free( | 
| 87 | 0 |        &guid, | 
| 88 | 0 |        error ) != 1 ) | 
| 89 | 0 |   { | 
| 90 | 0 |     libcerror_error_set( | 
| 91 | 0 |      error, | 
| 92 | 0 |      LIBCERROR_ERROR_DOMAIN_RUNTIME, | 
| 93 | 0 |      LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, | 
| 94 | 0 |      "%s: unable to free GUID.", | 
| 95 | 0 |      function ); | 
| 96 |  | 
 | 
| 97 | 0 |     goto on_error; | 
| 98 | 0 |   } | 
| 99 | 0 |   return( 1 ); | 
| 100 |  |  | 
| 101 | 0 | on_error: | 
| 102 | 0 |   if( guid != NULL ) | 
| 103 | 0 |   { | 
| 104 | 0 |     libfguid_identifier_free( | 
| 105 | 0 |      &guid, | 
| 106 | 0 |      NULL ); | 
| 107 | 0 |   } | 
| 108 | 0 |   return( -1 ); | 
| 109 | 0 | } | 
| 110 |  |  |