Add 'recovery_key' in Google Binary Block (GBB) utility

Review URL: http://codereview.chromium.org/2553001
diff --git a/utility/gbb_utility.cc b/utility/gbb_utility.cc
index 8b10787..71e6878 100644
--- a/utility/gbb_utility.cc
+++ b/utility/gbb_utility.cc
@@ -257,7 +257,18 @@
         *pname = "bmp_fv";
       break;
 
+    case PROP_RCVKEY:
+      *poffset = header_.recovery_key_offset;;
+      *psize = header_.recovery_key_size;
+      if (pname)
+        *pname = "recovery_key";
+      break;
+
     default:
+      if (verbose) {
+        fprintf(stderr, " internal error: unknown property (%d).\n",
+            static_cast<int>(i));
+      }
       assert(!"invalid property index.");
       return false;
   }
@@ -272,12 +283,8 @@
 
   assert(is_valid_gbb);
 
-  if (!find_property(i, &prop_offset, &prop_size, &prop_name)) {
-    if (verbose)
-      fprintf(stderr, " internal error: unknown property (%d).\n",
-              static_cast<int>(i));
+  if (!find_property(i, &prop_offset, &prop_size, &prop_name))
     return false;
-  }
 
   if (prop_size < value.size()) {
     if (verbose)
@@ -308,12 +315,8 @@
 
   assert(is_valid_gbb);
 
-  if (!find_property(i, &prop_offset, &prop_size, &prop_name)) {
-    if (verbose)
-      fprintf(stderr, " internal error: unknown property (%d).\n",
-              static_cast<int>(i));
+  if (!find_property(i, &prop_offset, &prop_size, &prop_name))
     return "";
-  }
 
   // check range again to allow empty value (for compatbility)
   if (prop_offset == 0 && prop_size == 0) {
@@ -333,9 +336,6 @@
   const char *prop_name;
 
   if (!find_property(i, &unused_off, &unused_size, &prop_name)) {
-    if (verbose)
-      fprintf(stderr, " internal error: unknown property (%d).\n",
-          static_cast<int>(i));
     assert(!"invalid property index.");
     return "";
   }
@@ -355,6 +355,10 @@
   return set_property(PROP_BMPFV, value);
 }
 
+bool GoogleBinaryBlockUtil::set_recovery_key(const string &value) {
+  return set_property(PROP_RCVKEY, value);
+}
+
 }  // namespace vboot_reference
 
 #ifdef WITH_UTIL_MAIN
@@ -378,6 +382,7 @@
     "     --hwid          \tReport hardware id (default).\n"
     " -k, --rootkey=FILE  \tFile name to export Root Key.\n"
     " -b, --bmpfv=FILE    \tFile name to export Bitmap FV.\n"
+    "     --recoverykey=FILE\tFile name to export Recovery Key.\n"
     "\n"
     "SET MODE:\n"
     "-s, --set            \tSet (write) to bios_file, "
@@ -386,6 +391,7 @@
     " -i, --hwid=HWID     \tThe new hardware id to be changed.\n"
     " -k, --rootkey=FILE  \tFile name of new Root Key.\n"
     " -b, --bmpfv=FILE    \tFile name of new Bitmap FV.\n"
+    "     --recoverykey=FILE\tFile name of new Recovery Key.\n"
     "\n"
     "SAMPLE:\n"
     "  %s -g bios.bin\n"
@@ -490,6 +496,7 @@
     {"hwid", 2, NULL, 'i' },
     {"rootkey", 1, NULL, 'k' },
     {"bmpfv", 1, NULL, 'b' },
+    {"recoverykey", 1, NULL, 'R' },
     { NULL, 0, NULL, 0 },
   };
 
@@ -527,6 +534,12 @@
           usagehelp_exit(myname);
         break;
 
+      case 'R':
+        if (!opt_props.set_new_value(
+              GoogleBinaryBlockUtil::PROP_RCVKEY, optarg))
+          usagehelp_exit(myname);
+        break;
+
       default:
       case '?':
         usagehelp_exit(myname);
diff --git a/utility/include/gbb_utility.h b/utility/include/gbb_utility.h
index 021eb80..468cddf 100644
--- a/utility/include/gbb_utility.h
+++ b/utility/include/gbb_utility.h
@@ -18,6 +18,7 @@
     PROP_HWID,      // hardware id
     PROP_ROOTKEY,   // root key
     PROP_BMPFV,     // bitmap FV
+    PROP_RCVKEY,    // recovery key
     PROP_RANGE,     // indicator of valid property range
   };
 
@@ -48,9 +49,11 @@
   bool set_hwid(const char *hwid);      // NOTE: hwid is NUL-terminated.
   bool set_rootkey(const std::string &value);
   bool set_bmpfv(const std::string &value);
+  bool set_recovery_key(const std::string &value);
   std::string get_hwid() const { return get_property(PROP_HWID); }
   std::string get_rootkey() const { return get_property(PROP_ROOTKEY); }
   std::string get_bmpfv() const { return get_property(PROP_BMPFV); }
+  std::string get_recovery_key() const { return get_property(PROP_RCVKEY); }
 
  private:
   // clear all cached data and initialize to original state