| 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 * Host functions for keys. | 5 * Host functions for keys. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 /* TODO: change all 'return 0', 'return 1' into meaningful return codes */ | 8 /* TODO: change all 'return 0', 'return 1' into meaningful return codes */ |
| 9 | 9 |
| 10 #define OPENSSL_NO_SHA | 10 #define OPENSSL_NO_SHA |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 180 |
| 181 } while(0); | 181 } while(0); |
| 182 | 182 |
| 183 /* Error */ | 183 /* Error */ |
| 184 Free(key); | 184 Free(key); |
| 185 return NULL; | 185 return NULL; |
| 186 } | 186 } |
| 187 | 187 |
| 188 | 188 |
| 189 int PublicKeyWrite(const char* filename, const VbPublicKey* key) { | 189 int PublicKeyWrite(const char* filename, const VbPublicKey* key) { |
| 190 VbPublicKey* kcopy = NULL; | 190 VbPublicKey* kcopy; |
| 191 FILE* f = NULL; | 191 int rv; |
| 192 int rv = 1; | |
| 193 | 192 |
| 194 do { | 193 /* Copy the key, so its data is contiguous with the header */ |
| 195 f = fopen(filename, "wb"); | 194 kcopy = PublicKeyAlloc(key->key_size, 0, 0); |
| 196 if (!f) { | 195 if (!kcopy) |
| 197 debug("PublicKeyWrite() unable to open file %s\n", filename); | 196 return 1; |
| 198 break; | 197 if (0 != PublicKeyCopy(kcopy, key)) { |
| 199 } | 198 Free(kcopy); |
| 199 return 1; |
| 200 } |
| 200 | 201 |
| 201 /* Copy the key, so its data is contiguous with the header */ | 202 /* Write the copy, then free it */ |
| 202 kcopy = PublicKeyAlloc(key->key_size, 0, 0); | 203 rv = WriteFile(filename, kcopy, kcopy->key_offset + kcopy->key_size); |
| 203 if (!kcopy || 0 != PublicKeyCopy(kcopy, key)) | 204 Free(kcopy); |
| 204 break; | |
| 205 | |
| 206 if (1 != fwrite(kcopy, kcopy->key_offset + kcopy->key_size, 1, f)) | |
| 207 break; | |
| 208 | |
| 209 /* Success */ | |
| 210 rv = 0; | |
| 211 | |
| 212 } while(0); | |
| 213 | |
| 214 if (kcopy) | |
| 215 Free(kcopy); | |
| 216 if (f) | |
| 217 fclose(f); | |
| 218 | |
| 219 if (0 != rv) | |
| 220 unlink(filename); /* Delete any partial file */ | |
| 221 | |
| 222 return rv; | 205 return rv; |
| 223 } | 206 } |
| OLD | NEW |