Use InsertBraces - and reformat pki as such

Bug: 659
Change-Id: I48eeda0bcd0de45d70644c321138225f83cb6c60
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/64107
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
Auto-Submit: Bob Beck <bbe@google.com>
diff --git a/pki/parse_values.cc b/pki/parse_values.cc
index 13e2c20..cc7a072 100644
--- a/pki/parse_values.cc
+++ b/pki/parse_values.cc
@@ -20,12 +20,14 @@
   // According to ITU-T X.690 section 8.2, a bool is encoded as a single octet
   // where the octet of all zeroes is FALSE and a non-zero value for the octet
   // is TRUE.
-  if (in.Length() != 1)
+  if (in.Length() != 1) {
     return false;
+  }
   ByteReader data(in);
   uint8_t byte;
-  if (!data.ReadByte(&byte))
+  if (!data.ReadByte(&byte)) {
     return false;
+  }
   if (byte == 0) {
     *out = false;
     return true;
@@ -67,10 +69,12 @@
 // 0 and 60 (to allow for leap seconds; no validation is done that a leap
 // second is on a day that could be a leap second).
 bool ValidateGeneralizedTime(const GeneralizedTime &time) {
-  if (time.month < 1 || time.month > 12)
+  if (time.month < 1 || time.month > 12) {
     return false;
-  if (time.day < 1)
+  }
+  if (time.day < 1) {
     return false;
+  }
   if (time.hours > 23) {
     return false;
   }
@@ -88,8 +92,9 @@
     case 6:
     case 9:
     case 11:
-      if (time.day > 30)
+      if (time.day > 30) {
         return false;
+      }
       break;
     case 1:
     case 3:
@@ -98,17 +103,20 @@
     case 8:
     case 10:
     case 12:
-      if (time.day > 31)
+      if (time.day > 31) {
         return false;
+      }
       break;
     case 2:
       if (time.year % 4 == 0 &&
           (time.year % 100 != 0 || time.year % 400 == 0)) {
-        if (time.day > 29)
+        if (time.day > 29) {
           return false;
+        }
       } else {
-        if (time.day > 28)
+        if (time.day > 28) {
           return false;
+        }
       }
       break;
     default:
@@ -129,11 +137,13 @@
 size_t GetUnsignedIntegerLength(const Input &in) {
   der::ByteReader reader(in);
   uint8_t first_byte;
-  if (!reader.ReadByte(&first_byte))
+  if (!reader.ReadByte(&first_byte)) {
     return 0;  // Not valid DER  as |in| was empty.
+  }
 
-  if (first_byte == 0 && in.Length() > 1)
+  if (first_byte == 0 && in.Length() > 1) {
     return in.Length() - 1;
+  }
   return in.Length();
 }
 
@@ -170,12 +180,14 @@
 bool ParseUint64(const Input &in, uint64_t *out) {
   // Reject non-minimally encoded numbers and negative numbers.
   bool negative;
-  if (!IsValidInteger(in, &negative) || negative)
+  if (!IsValidInteger(in, &negative) || negative) {
     return false;
+  }
 
   // Reject (non-negative) integers whose value would overflow the output type.
-  if (GetUnsignedIntegerLength(in) > sizeof(*out))
+  if (GetUnsignedIntegerLength(in) > sizeof(*out)) {
     return false;
+  }
 
   ByteReader reader(in);
   uint8_t data;
@@ -192,11 +204,13 @@
 bool ParseUint8(const Input &in, uint8_t *out) {
   // TODO(eroman): Implement this more directly.
   uint64_t value;
-  if (!ParseUint64(in, &value))
+  if (!ParseUint64(in, &value)) {
     return false;
+  }
 
-  if (value > 0xFF)
+  if (value > 0xFF) {
     return false;
+  }
 
   *out = static_cast<uint8_t>(value);
   return true;
@@ -217,8 +231,9 @@
 
   // If the bit is outside of the bitstring, by definition it is not
   // asserted.
-  if (byte_index >= bytes_.Length())
+  if (byte_index >= bytes_.Length()) {
     return false;
+  }
 
   // Within a byte, bits are ordered from most significant to least significant.
   // Convert |bit_index| to an index within the |byte_index| byte, measured from
@@ -241,14 +256,17 @@
   // bit 1 as the least significant bit, the number of unused bits in the final
   // subsequent octet. The number shall be in the range zero to seven.
   uint8_t unused_bits;
-  if (!reader.ReadByte(&unused_bits))
+  if (!reader.ReadByte(&unused_bits)) {
     return std::nullopt;
-  if (unused_bits > 7)
+  }
+  if (unused_bits > 7) {
     return std::nullopt;
+  }
 
   Input bytes;
-  if (!reader.ReadBytes(reader.BytesLeft(), &bytes))
+  if (!reader.ReadBytes(reader.BytesLeft(), &bytes)) {
     return std::nullopt;  // Not reachable.
+  }
 
   // Ensure that unused bits in the last byte are set to 0.
   if (unused_bits > 0) {
@@ -256,8 +274,9 @@
     //
     // If the bitstring is empty, there shall be no subsequent octets,
     // and the initial octet shall be zero.
-    if (bytes.Length() == 0)
+    if (bytes.Length() == 0) {
       return std::nullopt;
+    }
     uint8_t last_byte = bytes[bytes.Length() - 1];
 
     // From ITU-T X.690, section 11.2.1 (applies to CER and DER, but not BER):
@@ -265,8 +284,9 @@
     // Each unused bit in the final octet of the encoding of a bit string value
     // shall be set to zero.
     uint8_t mask = 0xFF >> (8 - unused_bits);
-    if ((mask & last_byte) != 0)
+    if ((mask & last_byte) != 0) {
       return std::nullopt;
+    }
   }
 
   return BitString(bytes, unused_bits);
@@ -306,15 +326,17 @@
     return false;
   }
   uint8_t zulu;
-  if (!reader.ReadByte(&zulu) || zulu != 'Z' || reader.HasMore())
+  if (!reader.ReadByte(&zulu) || zulu != 'Z' || reader.HasMore()) {
     return false;
+  }
   if (time.year < 50) {
     time.year += 2000;
   } else {
     time.year += 1900;
   }
-  if (!ValidateGeneralizedTime(time))
+  if (!ValidateGeneralizedTime(time)) {
     return false;
+  }
   *value = time;
   return true;
 }
@@ -331,18 +353,21 @@
     return false;
   }
   uint8_t zulu;
-  if (!reader.ReadByte(&zulu) || zulu != 'Z' || reader.HasMore())
+  if (!reader.ReadByte(&zulu) || zulu != 'Z' || reader.HasMore()) {
     return false;
-  if (!ValidateGeneralizedTime(time))
+  }
+  if (!ValidateGeneralizedTime(time)) {
     return false;
+  }
   *value = time;
   return true;
 }
 
 bool ParseIA5String(Input in, std::string *out) {
   for (char c : in.AsStringView()) {
-    if (static_cast<uint8_t>(c) > 127)
+    if (static_cast<uint8_t>(c) > 127) {
       return false;
+    }
   }
   *out = in.AsString();
   return true;
@@ -356,8 +381,9 @@
   // "for VisibleString [the range] is 32 to 126 ... For VisibleString .. all
   // the values in the range are present."
   for (char c : in.AsStringView()) {
-    if (static_cast<uint8_t>(c) < 32 || static_cast<uint8_t>(c) > 126)
+    if (static_cast<uint8_t>(c) < 32 || static_cast<uint8_t>(c) > 126) {
       return false;
+    }
   }
   *out = in.AsString();
   return true;