Bug 1061021, Part 6: Stop using PLArenaPool for boolean encoding, r=keeler
authorBrian Smith <brian@briansmith.org>
Sat, 30 Aug 2014 17:00:16 -0700
changeset 203701 53bc10ee5cc22ea2b1e255118df6d86cf427b607
parent 203700 cdf7e62e27dec7a86818ef09bbac552682165d0c
child 203702 e5e839098354791ae4d5475b3ea3c8c966199ddb
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerskeeler
bugs1061021
milestone35.0a1
Bug 1061021, Part 6: Stop using PLArenaPool for boolean encoding, r=keeler
security/pkix/test/lib/pkixtestutil.cpp
--- a/security/pkix/test/lib/pkixtestutil.cpp
+++ b/security/pkix/test/lib/pkixtestutil.cpp
@@ -289,28 +289,22 @@ BitString(const ByteString& rawBytes, bo
   prefixed.append(rawBytes);
   if (corrupt) {
     assert(prefixed.length() > 8);
     prefixed[8]++;
   }
   return TLV(der::BIT_STRING, prefixed);
 }
 
-static SECItem*
-Boolean(PLArenaPool* arena, bool value)
+static ByteString
+Boolean(bool value)
 {
-  assert(arena);
-  SECItem* result(SECITEM_AllocItem(arena, nullptr, 3));
-  if (!result) {
-    return nullptr;
-  }
-  result->data[0] = der::BOOLEAN;
-  result->data[1] = 1; // length
-  result->data[2] = value ? 0xff : 0x00;
-  return result;
+  ByteString encodedValue;
+  encodedValue.push_back(value ? 0xff : 0x00);
+  return TLV(der::BOOLEAN, encodedValue);
 }
 
 static ByteString
 Integer(long value)
 {
   if (value < 0 || value > 127) {
     // TODO: add encoding of larger values
     return ENCODING_FAILED;
@@ -565,20 +559,21 @@ Extension(PLArenaPool* arena, Input extn
   Output output;
 
   const SECItem extnIDItem = UnsafeMapInputToSECItem(extnID);
   if (output.Add(&extnIDItem) != Success) {
     return nullptr;
   }
 
   if (criticality == ExtensionCriticality::Critical) {
-    SECItem* critical(Boolean(arena, true));
-    if (output.Add(critical) != Success) {
+    ByteString critical(Boolean(true));
+    if (critical == ENCODING_FAILED) {
       return nullptr;
     }
+    output.Add(critical);
   }
 
   SECItem* extnValueBytes(value.Squash(arena, der::SEQUENCE));
   if (!extnValueBytes) {
     return nullptr;
   }
   SECItem* extnValue(EncodeNested(arena, der::OCTET_STRING, extnValueBytes));
   if (!extnValue) {
@@ -914,19 +909,21 @@ CreateEncodedBasicConstraints(PLArenaPoo
   assert(arena);
   if (!arena) {
     return nullptr;
   }
 
   Output value;
 
   if (isCA) {
-    if (value.Add(Boolean(arena, true)) != Success) {
+    ByteString cA(Boolean(true));
+    if (cA == ENCODING_FAILED) {
       return nullptr;
     }
+    value.Add(cA);
   }
 
   if (pathLenConstraintValue) {
     ByteString pathLenConstraint(Integer(*pathLenConstraintValue));
     if (pathLenConstraint == ENCODING_FAILED) {
       return nullptr;
     }
     value.Add(pathLenConstraint);