Commit ea85530c authored by Adam Langley's avatar Adam Langley Committed by Commit Bot

cbor: have one Read function wrap the other.

This is a trivial matter but makes a bit more sense when I make the
inner Read call a little more complex in the next change.

Change-Id: Ie1c19e8760a598cf36914e634037c519e7f78d72
Reviewed-on: https://chromium-review.googlesource.com/990194Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Commit-Queue: Adam Langley <agl@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547569}
parent 2a112566
...@@ -66,17 +66,16 @@ CBORReader::~CBORReader() {} ...@@ -66,17 +66,16 @@ CBORReader::~CBORReader() {}
base::Optional<CBORValue> CBORReader::Read(base::span<uint8_t const> data, base::Optional<CBORValue> CBORReader::Read(base::span<uint8_t const> data,
DecoderError* error_code_out, DecoderError* error_code_out,
int max_nesting_level) { int max_nesting_level) {
CBORReader reader(data.cbegin(), data.cend()); size_t num_bytes_consumed;
base::Optional<CBORValue> decoded_cbor = auto decoded_cbor =
reader.DecodeCompleteDataItem(max_nesting_level); Read(data, &num_bytes_consumed, error_code_out, max_nesting_level);
if (decoded_cbor)
reader.CheckExtraneousData();
if (error_code_out)
*error_code_out = reader.GetErrorCode();
if (reader.GetErrorCode() != DecoderError::CBOR_NO_ERROR) if (decoded_cbor && num_bytes_consumed != data.size()) {
if (error_code_out)
*error_code_out = DecoderError::EXTRANEOUS_DATA;
return base::nullopt; return base::nullopt;
}
return decoded_cbor; return decoded_cbor;
} }
...@@ -340,11 +339,6 @@ bool CBORReader::CheckMinimalEncoding(uint8_t additional_bytes, ...@@ -340,11 +339,6 @@ bool CBORReader::CheckMinimalEncoding(uint8_t additional_bytes,
return true; return true;
} }
void CBORReader::CheckExtraneousData() {
if (it_ != end_)
error_code_ = DecoderError::EXTRANEOUS_DATA;
}
bool CBORReader::HasValidUTF8Format(const std::string& string_data) { bool CBORReader::HasValidUTF8Format(const std::string& string_data) {
if (!base::IsStringUTF8(string_data)) { if (!base::IsStringUTF8(string_data)) {
error_code_ = DecoderError::INVALID_UTF8; error_code_ = DecoderError::INVALID_UTF8;
......
...@@ -140,7 +140,6 @@ class CBOR_EXPORT CBORReader { ...@@ -140,7 +140,6 @@ class CBOR_EXPORT CBORReader {
base::Optional<CBORValue> ReadMapContent(const DataItemHeader& header, base::Optional<CBORValue> ReadMapContent(const DataItemHeader& header,
int max_nesting_level); int max_nesting_level);
bool CanConsume(uint64_t bytes); bool CanConsume(uint64_t bytes);
void CheckExtraneousData();
bool HasValidUTF8Format(const std::string& string_data); bool HasValidUTF8Format(const std::string& string_data);
bool CheckOutOfOrderKey(const CBORValue& new_key, CBORValue::MapValue* map); bool CheckOutOfOrderKey(const CBORValue& new_key, CBORValue::MapValue* map);
bool CheckMinimalEncoding(uint8_t additional_bytes, uint64_t uint_data); bool CheckMinimalEncoding(uint8_t additional_bytes, uint64_t uint_data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment