diff options
Diffstat (limited to 'utils/imxtools/misc.c')
-rw-r--r-- | utils/imxtools/misc.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/utils/imxtools/misc.c b/utils/imxtools/misc.c index abbffbd5ae..a7cc096059 100644 --- a/utils/imxtools/misc.c +++ b/utils/imxtools/misc.c | |||
@@ -157,18 +157,27 @@ void clear_keys() | |||
157 | g_key_array = NULL; | 157 | g_key_array = NULL; |
158 | } | 158 | } |
159 | 159 | ||
160 | void add_keys_from_file(const char *key_file) | 160 | bool add_keys_from_file(const char *key_file) |
161 | { | 161 | { |
162 | int size; | 162 | int size; |
163 | FILE *fd = fopen(key_file, "r"); | 163 | FILE *fd = fopen(key_file, "r"); |
164 | if(fd == NULL) | 164 | if(fd == NULL) |
165 | bug("opening key file failed"); | 165 | { |
166 | if(g_debug) | ||
167 | perror("cannot open key file"); | ||
168 | return false; | ||
169 | } | ||
166 | fseek(fd, 0, SEEK_END); | 170 | fseek(fd, 0, SEEK_END); |
167 | size = ftell(fd); | 171 | size = ftell(fd); |
168 | fseek(fd, 0, SEEK_SET); | 172 | fseek(fd, 0, SEEK_SET); |
169 | char *buf = xmalloc(size + 1); | 173 | char *buf = xmalloc(size + 1); |
170 | if(fread(buf, 1, size, fd) != (size_t)size) | 174 | if(fread(buf, 1, size, fd) != (size_t)size) |
171 | bug("reading key file"); | 175 | { |
176 | if(g_debug) | ||
177 | perror("Cannot read key file"); | ||
178 | fclose(fd); | ||
179 | return false; | ||
180 | } | ||
172 | buf[size] = 0; | 181 | buf[size] = 0; |
173 | fclose(fd); | 182 | fclose(fd); |
174 | 183 | ||
@@ -180,7 +189,11 @@ void add_keys_from_file(const char *key_file) | |||
180 | struct crypto_key_t k; | 189 | struct crypto_key_t k; |
181 | /* parse key */ | 190 | /* parse key */ |
182 | if(!parse_key(&p, &k)) | 191 | if(!parse_key(&p, &k)) |
183 | bug("invalid key file"); | 192 | { |
193 | if(g_debug) | ||
194 | printf("invalid key file\n"); | ||
195 | return false; | ||
196 | } | ||
184 | if(g_debug) | 197 | if(g_debug) |
185 | { | 198 | { |
186 | printf("Add key: "); | 199 | printf("Add key: "); |
@@ -189,7 +202,11 @@ void add_keys_from_file(const char *key_file) | |||
189 | add_keys(&k, 1); | 202 | add_keys(&k, 1); |
190 | /* request at least one space character before next key, or end of file */ | 203 | /* request at least one space character before next key, or end of file */ |
191 | if(*p != 0 && !isspace(*p)) | 204 | if(*p != 0 && !isspace(*p)) |
192 | bug("invalid key file"); | 205 | { |
206 | if(g_debug) | ||
207 | printf("invalid key file\n"); | ||
208 | return false; | ||
209 | } | ||
193 | /* skip whitespace */ | 210 | /* skip whitespace */ |
194 | while(isspace(*p)) | 211 | while(isspace(*p)) |
195 | p++; | 212 | p++; |
@@ -197,6 +214,7 @@ void add_keys_from_file(const char *key_file) | |||
197 | break; | 214 | break; |
198 | } | 215 | } |
199 | free(buf); | 216 | free(buf); |
217 | return true; | ||
200 | } | 218 | } |
201 | 219 | ||
202 | void print_hex(byte *data, int len, bool newline) | 220 | void print_hex(byte *data, int len, bool newline) |