Bug 1154399 - Part 1: De-templatize and un-inline IntegralValue. r=keeler

This commit is contained in:
Brian Smith 2015-04-14 05:06:41 -10:00
parent 221df621f6
commit 10450b2670
2 changed files with 25 additions and 23 deletions

View File

@ -551,6 +551,30 @@ IntegralBytes(Reader& input, uint8_t tag,
return Success;
}
// This parser will only parse values between 0..127. If this range is
// increased then callers will need to be changed.
Result
IntegralValue(Reader& input, uint8_t tag, /*out*/ uint8_t& value)
{
// Conveniently, all the Integers that we actually have to be able to parse
// are positive and very small. Consequently, this parser is *much* simpler
// than a general Integer parser would need to be.
Input valueBytes;
Result rv = IntegralBytes(input, tag, IntegralValueRestriction::MustBe0To127,
valueBytes, nullptr);
if (rv != Success) {
return rv;
}
Reader valueReader(valueBytes);
rv = valueReader.Read(value);
if (rv != Success) {
return NotReached("IntegralBytes already validated the value.", rv);
}
rv = End(valueReader);
assert(rv == Success); // guaranteed by IntegralBytes's range checks.
return rv;
}
} // namespace internal
} } } // namespace mozilla::pkix::der

View File

@ -275,29 +275,7 @@ Result IntegralBytes(Reader& input, uint8_t tag,
// This parser will only parse values between 0..127. If this range is
// increased then callers will need to be changed.
template <typename T> inline Result
IntegralValue(Reader& input, uint8_t tag, T& value)
{
// Conveniently, all the Integers that we actually have to be able to parse
// are positive and very small. Consequently, this parser is *much* simpler
// than a general Integer parser would need to be.
Input valueBytes;
Result rv = IntegralBytes(input, tag, IntegralValueRestriction::MustBe0To127,
valueBytes, nullptr);
if (rv != Success) {
return rv;
}
Reader valueReader(valueBytes);
uint8_t valueByte;
rv = valueReader.Read(valueByte);
if (rv != Success) {
return NotReached("IntegralBytes already validated the value.", rv);
}
value = valueByte;
rv = End(valueReader);
assert(rv == Success); // guaranteed by IntegralBytes's range checks.
return rv;
}
Result IntegralValue(Reader& input, uint8_t tag, /*out*/ uint8_t& value);
} // namespace internal