| OLD | NEW |
| 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
| 4 * | 4 * |
| 5 * Utility functions for file and key handling. | 5 * Utility functions for file and key handling. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "file_keys.h" | 8 #include "file_keys.h" |
| 9 | 9 |
| 10 #include <fcntl.h> | 10 #include <fcntl.h> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 int fd; | 23 int fd; |
| 24 struct stat stat_fd; | 24 struct stat stat_fd; |
| 25 uint8_t* buf = NULL; | 25 uint8_t* buf = NULL; |
| 26 | 26 |
| 27 if ((fd = open(input_file, O_RDONLY)) == -1) { | 27 if ((fd = open(input_file, O_RDONLY)) == -1) { |
| 28 debug("Couldn't open file.\n"); | 28 debug("Couldn't open file.\n"); |
| 29 return NULL; | 29 return NULL; |
| 30 } | 30 } |
| 31 | 31 |
| 32 if (-1 == fstat(fd, &stat_fd)) { | 32 if (-1 == fstat(fd, &stat_fd)) { |
| 33 debug("Couldn't stat key file\n"); | 33 debug("Couldn't stat file\n"); |
| 34 return NULL; | 34 return NULL; |
| 35 } | 35 } |
| 36 *len = stat_fd.st_size; | 36 *len = stat_fd.st_size; |
| 37 | 37 |
| 38 /* Read entire key binary blob into a buffer. */ | |
| 39 buf = (uint8_t*) Malloc(*len); | 38 buf = (uint8_t*) Malloc(*len); |
| 40 if (!buf) | 39 if (!buf) |
| 41 return NULL; | 40 return NULL; |
| 42 | 41 |
| 43 if (*len != read(fd, buf, *len)) { | 42 if (*len != read(fd, buf, *len)) { |
| 44 debug("Couldn't read key into a buffer.\n"); | 43 debug("Couldn't read file into a buffer.\n"); |
| 45 return NULL; | 44 return NULL; |
| 46 } | 45 } |
| 47 | 46 |
| 48 close(fd); | 47 close(fd); |
| 49 return buf; | 48 return buf; |
| 50 } | 49 } |
| 51 | 50 |
| 52 RSAPublicKey* RSAPublicKeyFromFile(const char* input_file) { | 51 RSAPublicKey* RSAPublicKeyFromFile(const char* input_file) { |
| 53 uint64_t len; | 52 uint64_t len; |
| 54 RSAPublicKey* key = NULL; | 53 RSAPublicKey* key = NULL; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 if (fread(signature, signature_size, 1, cmd_out) != 1) { | 110 if (fread(signature, signature_size, 1, cmd_out) != 1) { |
| 112 debug("Couldn't read signature.\n"); | 111 debug("Couldn't read signature.\n"); |
| 113 pclose(cmd_out); | 112 pclose(cmd_out); |
| 114 Free(signature); | 113 Free(signature); |
| 115 return NULL; | 114 return NULL; |
| 116 } | 115 } |
| 117 | 116 |
| 118 pclose(cmd_out); | 117 pclose(cmd_out); |
| 119 return signature; | 118 return signature; |
| 120 } | 119 } |
| OLD | NEW |