Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: host/lib/host_key.c

Issue 2748008: Add vbutil_keyblock (Closed) Base URL: ssh://gitrw.chromium.org/vboot_reference.git
Patch Set: Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « host/include/host_misc.h ('k') | host/lib/host_misc.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « host/include/host_misc.h ('k') | host/lib/host_misc.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698