/src/libfvde/libfvde/libfvde_keyring.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Keyring functions |
3 | | * |
4 | | * Copyright (C) 2011-2024, Omar Choudary <choudary.omar@gmail.com> |
5 | | * Joachim Metz <joachim.metz@gmail.com> |
6 | | * |
7 | | * Refer to AUTHORS for acknowledgements. |
8 | | * |
9 | | * This program is free software: you can redistribute it and/or modify |
10 | | * it under the terms of the GNU Lesser General Public License as published by |
11 | | * the Free Software Foundation, either version 3 of the License, or |
12 | | * (at your option) any later version. |
13 | | * |
14 | | * This program is distributed in the hope that it will be useful, |
15 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | * GNU General Public License for more details. |
18 | | * |
19 | | * You should have received a copy of the GNU Lesser General Public License |
20 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
21 | | */ |
22 | | |
23 | | #include <common.h> |
24 | | #include <memory.h> |
25 | | #include <types.h> |
26 | | |
27 | | #include "libfvde_keyring.h" |
28 | | #include "libfvde_libcerror.h" |
29 | | |
30 | | /* Creates a keyring |
31 | | * Make sure the value keyring is referencing, is set to NULL |
32 | | * Returns 1 if successful or -1 on error |
33 | | */ |
34 | | int libfvde_keyring_initialize( |
35 | | libfvde_keyring_t **keyring, |
36 | | libcerror_error_t **error ) |
37 | 0 | { |
38 | 0 | static char *function = "libfvde_keyring_initialize"; |
39 | |
|
40 | 0 | if( keyring == NULL ) |
41 | 0 | { |
42 | 0 | libcerror_error_set( |
43 | 0 | error, |
44 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
45 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
46 | 0 | "%s: invalid keyring.", |
47 | 0 | function ); |
48 | |
|
49 | 0 | return( -1 ); |
50 | 0 | } |
51 | 0 | if( *keyring != NULL ) |
52 | 0 | { |
53 | 0 | libcerror_error_set( |
54 | 0 | error, |
55 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
56 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
57 | 0 | "%s: invalid keyring value already set.", |
58 | 0 | function ); |
59 | |
|
60 | 0 | return( -1 ); |
61 | 0 | } |
62 | 0 | *keyring = memory_allocate_structure( |
63 | 0 | libfvde_keyring_t ); |
64 | |
|
65 | 0 | if( *keyring == NULL ) |
66 | 0 | { |
67 | 0 | libcerror_error_set( |
68 | 0 | error, |
69 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
70 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
71 | 0 | "%s: unable to create keyring.", |
72 | 0 | function ); |
73 | |
|
74 | 0 | goto on_error; |
75 | 0 | } |
76 | 0 | if( memory_set( |
77 | 0 | *keyring, |
78 | 0 | 0, |
79 | 0 | sizeof( libfvde_keyring_t ) ) == NULL ) |
80 | 0 | { |
81 | 0 | libcerror_error_set( |
82 | 0 | error, |
83 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
84 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
85 | 0 | "%s: unable to clear keyring.", |
86 | 0 | function ); |
87 | |
|
88 | 0 | goto on_error; |
89 | 0 | } |
90 | 0 | return( 1 ); |
91 | | |
92 | 0 | on_error: |
93 | 0 | if( *keyring != NULL ) |
94 | 0 | { |
95 | 0 | memory_free( |
96 | 0 | *keyring ); |
97 | |
|
98 | 0 | *keyring = NULL; |
99 | 0 | } |
100 | 0 | return( -1 ); |
101 | 0 | } |
102 | | |
103 | | /* Frees a keyring |
104 | | * Returns 1 if successful or -1 on error |
105 | | */ |
106 | | int libfvde_keyring_free( |
107 | | libfvde_keyring_t **keyring, |
108 | | libcerror_error_t **error ) |
109 | 0 | { |
110 | 0 | static char *function = "libfvde_keyring_free"; |
111 | 0 | int result = 1; |
112 | |
|
113 | 0 | if( keyring == NULL ) |
114 | 0 | { |
115 | 0 | libcerror_error_set( |
116 | 0 | error, |
117 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
118 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
119 | 0 | "%s: invalid keyring.", |
120 | 0 | function ); |
121 | |
|
122 | 0 | return( -1 ); |
123 | 0 | } |
124 | 0 | if( *keyring != NULL ) |
125 | 0 | { |
126 | 0 | if( memory_set( |
127 | 0 | *keyring, |
128 | 0 | 0, |
129 | 0 | sizeof( libfvde_keyring_t ) ) == NULL ) |
130 | 0 | { |
131 | 0 | libcerror_error_set( |
132 | 0 | error, |
133 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
134 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
135 | 0 | "%s: unable to clear keyring.", |
136 | 0 | function ); |
137 | |
|
138 | 0 | result = -1; |
139 | 0 | } |
140 | 0 | memory_free( |
141 | 0 | *keyring ); |
142 | |
|
143 | 0 | *keyring = NULL; |
144 | 0 | } |
145 | 0 | return( result ); |
146 | 0 | } |
147 | | |