#include "components/cbor/reader.h"
#include <math.h>
#include <limits>
#include <map>
#include <utility>
#include "base/bit_cast.h"
#include "base/check_op.h"
#include "base/notreached.h"
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_util.h"
#include "components/cbor/constants.h"
#include "components/cbor/float_conversions.h"
namespace cbor {
namespace constants {
const char kUnsupportedMajorType[] = …;
}
namespace {
Value::Type GetMajorType(uint8_t initial_data_byte) { … }
uint8_t GetAdditionalInfo(uint8_t initial_data_byte) { … }
const char kNoError[] = …;
const char kUnknownAdditionalInfo[] = …;
const char kIncompleteCBORData[] = …;
const char kIncorrectMapKeyType[] = …;
const char kTooMuchNesting[] = …;
const char kInvalidUTF8[] = …;
const char kExtraneousData[] = …;
const char kMapKeyOutOfOrder[] = …;
const char kNonMinimalCBOREncoding[] = …;
const char kUnsupportedSimpleValue[] = …;
const char kUnsupportedFloatingPointValue[] = …;
const char kOutOfRangeIntegerValue[] = …;
const char kMapKeyDuplicate[] = …;
const char kUnknownError[] = …;
}
Reader::Config::Config() = default;
Reader::Config::~Config() = default;
Reader::Reader(base::span<const uint8_t> data)
: … { … }
Reader::~Reader() { … }
std::optional<Value> Reader::Read(base::span<uint8_t const> data,
DecoderError* error_code_out,
int max_nesting_level) { … }
std::optional<Value> Reader::Read(base::span<uint8_t const> data,
size_t* num_bytes_consumed,
DecoderError* error_code_out,
int max_nesting_level) { … }
std::optional<Value> Reader::Read(base::span<uint8_t const> data,
const Config& config) { … }
std::optional<Value> Reader::DecodeCompleteDataItem(const Config& config,
int max_nesting_level) { … }
std::optional<Reader::DataItemHeader> Reader::DecodeDataItemHeader() { … }
std::optional<uint64_t> Reader::ReadVariadicLengthInteger(
Value::Type type,
uint8_t additional_info) { … }
std::optional<Value> Reader::DecodeValueToNegative(uint64_t value) { … }
std::optional<Value> Reader::DecodeValueToUnsigned(uint64_t value) { … }
std::optional<Value> Reader::DecodeToSimpleValueOrFloat(
const DataItemHeader& header,
const Config& config) { … }
std::optional<Value> Reader::ReadStringContent(
const Reader::DataItemHeader& header,
const Config& config) { … }
std::optional<Value> Reader::ReadByteStringContent(
const Reader::DataItemHeader& header) { … }
std::optional<Value> Reader::ReadArrayContent(
const Reader::DataItemHeader& header,
const Config& config,
int max_nesting_level) { … }
std::optional<Value> Reader::ReadMapContent(
const Reader::DataItemHeader& header,
const Config& config,
int max_nesting_level) { … }
std::optional<uint8_t> Reader::ReadByte() { … }
std::optional<base::span<const uint8_t>> Reader::ReadBytes(uint64_t num_bytes) { … }
bool Reader::IsEncodingMinimal(uint8_t additional_bytes, uint64_t uint_data) { … }
bool Reader::IsKeyInOrder(const Value& new_key,
const std::map<Value, Value, Value::Less>& map) { … }
bool Reader::IsDuplicateKey(const Value& new_key,
const std::map<Value, Value, Value::Less>& map) { … }
const char* Reader::ErrorCodeToString(DecoderError error) { … }
}