Bug 1085497: Add Input::size_type, r=mmc
authorBrian Smith <brian@briansmith.org>
Thu, 16 Oct 2014 18:23:27 -0700
changeset 212049 9d83b21c98e8c95d207078ae7542e40ff6307088
parent 212048 9b72d139e81766bdcf363c7b9ed0bf3f248c32d2
child 212050 4cf06b4e43969a6f56530be9ccf36e2bc7db7859
push id27697
push usercbook@mozilla.com
push dateFri, 24 Oct 2014 13:48:53 +0000
treeherdermozilla-central@de805196bbc4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmmc
bugs1085497
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1085497: Add Input::size_type, r=mmc
security/pkix/include/pkix/Input.h
--- a/security/pkix/include/pkix/Input.h
+++ b/security/pkix/include/pkix/Input.h
@@ -48,28 +48,30 @@ class Reader;
 //    Result BadExample(const Input& input);
 //    Result WorseExample(const uint8_t* input, size_t len);
 //
 // Note that in the example, GoodExample has the same performance
 // characteristics as WorseExample, but with much better safety guarantees.
 class Input
 {
 public:
+  typedef uint16_t size_type;
+
   // This constructor is useful for inputs that are statically known to be of a
   // fixed size, e.g.:
   //
   //   static const uint8_t EXPECTED_BYTES[] = { 0x00, 0x01, 0x02 };
   //   const Input expected(EXPECTED_BYTES);
   //
   // This is equivalent to (and preferred over):
   //
   //   static const uint8_t EXPECTED_BYTES[] = { 0x00, 0x01, 0x02 };
   //   Input expected;
   //   Result rv = expected.Init(EXPECTED_BYTES, sizeof EXPECTED_BYTES);
-  template <uint16_t N>
+  template <size_type N>
   explicit Input(const uint8_t (&data)[N])
     : data(data)
     , len(N)
   {
   }
 
   // Construct a valid, empty, Init-able Input.
   Input()
@@ -105,19 +107,19 @@ public:
   // operator= can be used multiple times.
   Result Init(Input other)
   {
     return Init(other.data, other.len);
   }
 
   // Returns the length of the input.
   //
-  // Having the return type be uint16_t instead of size_t avoids the need for
+  // Having the return type be size_type instead of size_t avoids the need for
   // callers to ensure that the result is small enough.
-  uint16_t GetLength() const { return static_cast<uint16_t>(len); }
+  size_type GetLength() const { return static_cast<size_type>(len); }
 
   // Don't use this. It is here because we have some "friend" functions that we
   // don't want to declare in this header file.
   const uint8_t* UnsafeGetData() const { return data; }
 
 private:
   const uint8_t* data;
   size_t len;
@@ -187,17 +189,17 @@ public:
       return rv;
     }
     out = *input++;
     out <<= 8u;
     out |= *input++;
     return Success;
   }
 
-  template <uint16_t N>
+  template <Input::size_type N>
   bool MatchRest(const uint8_t (&toMatch)[N])
   {
     // Normally we use EnsureLength which compares (input + len < end), but
     // here we want to be sure that there is nothing following the matched
     // bytes
     if (static_cast<size_t>(end - input) != N) {
       return false;
     }
@@ -219,41 +221,41 @@ public:
     }
     if (std::memcmp(input, toMatch.UnsafeGetData(), remaining)) {
       return false;
     }
     input = end;
     return true;
   }
 
-  Result Skip(uint16_t len)
+  Result Skip(Input::size_type len)
   {
     Result rv = EnsureLength(len);
     if (rv != Success) {
       return rv;
     }
     input += len;
     return Success;
   }
 
-  Result Skip(uint16_t len, Reader& skipped)
+  Result Skip(Input::size_type len, Reader& skipped)
   {
     Result rv = EnsureLength(len);
     if (rv != Success) {
       return rv;
     }
     rv = skipped.Init(input, len);
     if (rv != Success) {
       return rv;
     }
     input += len;
     return Success;
   }
 
-  Result Skip(uint16_t len, Input& skipped)
+  Result Skip(Input::size_type len, Input& skipped)
   {
     Result rv = EnsureLength(len);
     if (rv != Success) {
       return rv;
     }
     rv = skipped.Init(input, len);
     if (rv != Success) {
       return rv;
@@ -262,17 +264,17 @@ public:
     return Success;
   }
 
   void SkipToEnd()
   {
     input = end;
   }
 
-  Result EnsureLength(uint16_t len)
+  Result EnsureLength(Input::size_type len)
   {
     if (static_cast<size_t>(end - input) < len) {
       return Result::ERROR_BAD_DER;
     }
     return Success;
   }
 
   bool AtEnd() const { return input == end; }
@@ -289,21 +291,22 @@ public:
 
   Mark GetMark() const { return Mark(*this, input); }
 
   Result GetInput(const Mark& mark, /*out*/ Input& item)
   {
     if (&mark.input != this || mark.mark > input) {
       return NotReached("invalid mark", Result::FATAL_ERROR_INVALID_ARGS);
     }
-    return item.Init(mark.mark, static_cast<uint16_t>(input - mark.mark));
+    return item.Init(mark.mark,
+                     static_cast<Input::size_type>(input - mark.mark));
   }
 
 private:
-  Result Init(const uint8_t* data, uint16_t len)
+  Result Init(const uint8_t* data, Input::size_type len)
   {
     if (input) {
       // already initialized
       return Result::FATAL_ERROR_INVALID_ARGS;
     }
     input = data;
     end = data + len;
     return Success;