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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « host/include/host_misc.h ('k') | host/lib/host_misc.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: host/lib/host_key.c
diff --git a/host/lib/host_key.c b/host/lib/host_key.c
index 388a2d4e8350f68ef0066779d5f0ac3cde359f3e..c5f49d3171ba263fcb5374ac735ea5dad64be0b2 100644
--- a/host/lib/host_key.c
+++ b/host/lib/host_key.c
@@ -187,37 +187,20 @@ VbPublicKey* PublicKeyRead(const char* filename) {
int PublicKeyWrite(const char* filename, const VbPublicKey* key) {
- VbPublicKey* kcopy = NULL;
- FILE* f = NULL;
- int rv = 1;
+ VbPublicKey* kcopy;
+ int rv;
- do {
- f = fopen(filename, "wb");
- if (!f) {
- debug("PublicKeyWrite() unable to open file %s\n", filename);
- break;
- }
-
- /* Copy the key, so its data is contiguous with the header */
- kcopy = PublicKeyAlloc(key->key_size, 0, 0);
- if (!kcopy || 0 != PublicKeyCopy(kcopy, key))
- break;
-
- if (1 != fwrite(kcopy, kcopy->key_offset + kcopy->key_size, 1, f))
- break;
-
- /* Success */
- rv = 0;
-
- } while(0);
-
- if (kcopy)
+ /* Copy the key, so its data is contiguous with the header */
+ kcopy = PublicKeyAlloc(key->key_size, 0, 0);
+ if (!kcopy)
+ return 1;
+ if (0 != PublicKeyCopy(kcopy, key)) {
Free(kcopy);
- if (f)
- fclose(f);
-
- if (0 != rv)
- unlink(filename); /* Delete any partial file */
+ return 1;
+ }
+ /* Write the copy, then free it */
+ rv = WriteFile(filename, kcopy, kcopy->key_offset + kcopy->key_size);
+ Free(kcopy);
return rv;
}
« 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