Bug 1061021, Part 9: Stop using PLArenaPool for SingleResponse encoding, r=keeler
authorBrian Smith <brian@briansmith.org>
Sat, 30 Aug 2014 18:00:02 -0700
changeset 14680 40b2079e912c7ef2246a663fe471099cec41bb14
parent 14679 cbd4132642d4c8df7359f071aa3d5243e002dac7
child 14681 ae1e6fc28aecdc104cf827422ed3f95054bf83cc
push id3202
push userfranziskuskiefer@gmail.com
push dateMon, 01 Oct 2018 08:30:12 +0000
reviewerskeeler
bugs1061021
Bug 1061021, Part 9: Stop using PLArenaPool for SingleResponse encoding, r=keeler
lib/mozpkix/test/lib/pkixtestutil.cpp
--- a/lib/mozpkix/test/lib/pkixtestutil.cpp
+++ b/lib/mozpkix/test/lib/pkixtestutil.cpp
@@ -247,17 +247,17 @@ OCSPResponseContext::OCSPResponseContext
 {
 }
 
 static ByteString ResponseBytes(OCSPResponseContext& context);
 static ByteString BasicOCSPResponse(OCSPResponseContext& context);
 static SECItem* ResponseData(OCSPResponseContext& context);
 static ByteString ResponderID(OCSPResponseContext& context);
 static ByteString KeyHash(OCSPResponseContext& context);
-static SECItem* SingleResponse(OCSPResponseContext& context);
+static ByteString SingleResponse(OCSPResponseContext& context);
 static ByteString CertID(OCSPResponseContext& context);
 static ByteString CertStatus(OCSPResponseContext& context);
 
 static SECItem*
 EncodeNested(PLArenaPool* arena, uint8_t tag, const SECItem* inner)
 {
   Output output;
   if (output.Add(inner) != Success) {
@@ -1130,36 +1130,33 @@ ResponseData(OCSPResponseContext& contex
   ByteString responderID(ResponderID(context));
   if (responderID == ENCODING_FAILED) {
     return nullptr;
   }
   ByteString producedAtEncoded(TimeToGeneralizedTime(context.producedAt));
   if (producedAtEncoded == ENCODING_FAILED) {
     return nullptr;
   }
-  SECItem* responses = SingleResponse(context);
-  if (!responses) {
+  ByteString response(SingleResponse(context));
+  if (response == ENCODING_FAILED) {
     return nullptr;
   }
-  SECItem* responsesNested = EncodeNested(context.arena, der::SEQUENCE,
-                                          responses);
-  if (!responsesNested) {
+  ByteString responses(TLV(der::SEQUENCE, response));
+  if (responses == ENCODING_FAILED) {
     return nullptr;
   }
   SECItem* responseExtensions = nullptr;
   if (context.extensions || context.includeEmptyExtensions) {
     responseExtensions = Extensions(context);
   }
 
   Output output;
   output.Add(responderID);
   output.Add(producedAtEncoded);
-  if (output.Add(responsesNested) != Success) {
-    return nullptr;
-  }
+  output.Add(responses);
   if (responseExtensions) {
     if (output.Add(responseExtensions) != Success) {
       return nullptr;
     }
   }
   return output.Squash(context.arena, der::SEQUENCE);
 }
 
@@ -1209,52 +1206,50 @@ KeyHash(OCSPResponseContext& context)
 }
 
 // SingleResponse ::= SEQUENCE {
 //    certID                  CertID,
 //    certStatus              CertStatus,
 //    thisUpdate              GeneralizedTime,
 //    nextUpdate          [0] EXPLICIT GeneralizedTime OPTIONAL,
 //    singleExtensions    [1] EXPLICIT Extensions OPTIONAL }
-SECItem*
+ByteString
 SingleResponse(OCSPResponseContext& context)
 {
   ByteString certID(CertID(context));
   if (certID == ENCODING_FAILED) {
-    return nullptr;
+    return ENCODING_FAILED;
   }
   ByteString certStatus(CertStatus(context));
   if (certStatus == ENCODING_FAILED) {
-    return nullptr;
+    return ENCODING_FAILED;
   }
   ByteString thisUpdateEncoded(TimeToGeneralizedTime(context.thisUpdate));
   if (thisUpdateEncoded == ENCODING_FAILED) {
-    return nullptr;
+    return ENCODING_FAILED;
   }
   ByteString nextUpdateEncodedNested;
   if (context.includeNextUpdate) {
     ByteString nextUpdateEncoded(TimeToGeneralizedTime(context.nextUpdate));
     if (nextUpdateEncoded == ENCODING_FAILED) {
-      return nullptr;
+      return ENCODING_FAILED;
     }
     nextUpdateEncodedNested = TLV(der::CONSTRUCTED | der::CONTEXT_SPECIFIC | 0,
                                   nextUpdateEncoded);
     if (nextUpdateEncodedNested == ENCODING_FAILED) {
-      return nullptr;
+      return ENCODING_FAILED;
     }
   }
 
-  Output output;
-  output.Add(certID);
-  output.Add(certStatus);
-  output.Add(thisUpdateEncoded);
-  if (!nextUpdateEncodedNested.empty()) {
-    output.Add(nextUpdateEncodedNested);
-  }
-  return output.Squash(context.arena, der::SEQUENCE);
+  ByteString value;
+  value.append(certID);
+  value.append(certStatus);
+  value.append(thisUpdateEncoded);
+  value.append(nextUpdateEncodedNested);
+  return TLV(der::SEQUENCE, value);
 }
 
 // CertID          ::=     SEQUENCE {
 //        hashAlgorithm       AlgorithmIdentifier,
 //        issuerNameHash      OCTET STRING, -- Hash of issuer's DN
 //        issuerKeyHash       OCTET STRING, -- Hash of issuer's public key
 //        serialNumber        CertificateSerialNumber }
 ByteString