11
11
12
12
namespace goldfish { namespace cbor
13
13
{
14
- struct ill_formatted_cbor_data : ill_formatted {};
14
+ struct ill_formatted_cbor_data : ill_formatted { using ill_formatted::ill_formatted; };
15
15
16
16
template <class Stream , byte expected_type, class _tag > class string ;
17
17
template <class Stream > using byte_string = string<Stream, 2 , tags::binary>;
@@ -53,7 +53,7 @@ namespace goldfish { namespace cbor
53
53
, m_remaining_in_current_block(cb_initial)
54
54
{
55
55
if (m_remaining_in_current_block >= invalid_remaining)
56
- throw ill_formatted_cbor_data{};
56
+ throw ill_formatted_cbor_data{ " CBOR string too large " };
57
57
}
58
58
59
59
size_t read_partial_buffer (buffer_ref buffer)
@@ -74,7 +74,7 @@ namespace goldfish { namespace cbor
74
74
{
75
75
auto to_skip = std::min (cb, m_remaining_in_current_block);
76
76
if (stream::seek (m_stream, to_skip) != to_skip)
77
- throw ill_formatted_cbor_data{};
77
+ throw ill_formatted_cbor_data{ " Unexpected end of stream while reading CBOR string " };
78
78
cb -= to_skip;
79
79
m_remaining_in_current_block -= to_skip;
80
80
}
@@ -100,11 +100,11 @@ namespace goldfish { namespace cbor
100
100
}
101
101
102
102
if ((b >> 5 ) != expected_type)
103
- throw ill_formatted_cbor_data{};
103
+ throw ill_formatted_cbor_data{ " Unexpected type in CBOR string block " };
104
104
105
105
auto cb_next_block = read_integer (b & 31 , m_stream);
106
106
if (cb_next_block >= invalid_remaining)
107
- throw ill_formatted_cbor_data{};
107
+ throw ill_formatted_cbor_data{ " CBOR string too large " };
108
108
m_remaining_in_current_block = cb_next_block;
109
109
}
110
110
return m_remaining_in_current_block != invalid_remaining;
@@ -128,7 +128,7 @@ namespace goldfish { namespace cbor
128
128
, m_remaining_length(length)
129
129
{
130
130
if (m_remaining_length == std::numeric_limits<uint64_t >::max ())
131
- throw ill_formatted_cbor_data{};
131
+ throw ill_formatted_cbor_data{ " CBOR array too large " };
132
132
}
133
133
array (Stream&& s)
134
134
: m_stream(std::move(s))
@@ -149,7 +149,7 @@ namespace goldfish { namespace cbor
149
149
if (m_remaining_length == std::numeric_limits<uint64_t >::max ())
150
150
m_remaining_length = 0 ;
151
151
else
152
- throw ill_formatted_cbor_data{};
152
+ throw ill_formatted_cbor_data{ " CBOR array too large " };
153
153
}
154
154
return document;
155
155
}
@@ -168,7 +168,7 @@ namespace goldfish { namespace cbor
168
168
, m_remaining_length(remaining_length)
169
169
{
170
170
if (m_remaining_length == std::numeric_limits<uint64_t >::max ())
171
- throw ill_formatted_cbor_data{};
171
+ throw ill_formatted_cbor_data{ " CBOR map too large " };
172
172
}
173
173
map (Stream&& s)
174
174
: m_stream(std::move(s))
@@ -187,7 +187,7 @@ namespace goldfish { namespace cbor
187
187
if (m_remaining_length == std::numeric_limits<uint64_t >::max ())
188
188
m_remaining_length = 0 ;
189
189
else
190
- throw ill_formatted_cbor_data{};
190
+ throw ill_formatted_cbor_data{ " Unexpected break code found in finite length map " };
191
191
}
192
192
if (m_remaining_length != std::numeric_limits<uint64_t >::max ())
193
193
--m_remaining_length;
@@ -197,7 +197,7 @@ namespace goldfish { namespace cbor
197
197
{
198
198
auto d = read_no_debug_check (stream::ref (m_stream));
199
199
if (!d)
200
- throw ill_formatted_cbor_data{};
200
+ throw ill_formatted_cbor_data{ " Unexpected break code found as a map value " };
201
201
return std::move (*d);
202
202
}
203
203
private:
@@ -226,7 +226,7 @@ namespace goldfish { namespace cbor
226
226
else if (additional == 27 )
227
227
return from_big_endian (read<uint64_t >(s));
228
228
else
229
- throw ill_formatted_cbor_data{};
229
+ throw ill_formatted_cbor_data{ " Bad CBOR integer encoding " };
230
230
}
231
231
template <class stream > double read_half_point_float (stream& s)
232
232
{
@@ -253,7 +253,7 @@ namespace goldfish { namespace cbor
253
253
{
254
254
auto x = read_integer (static_cast <byte>(first_byte & 31 ), s);
255
255
if (x > static_cast <uint64_t >(std::numeric_limits<int64_t >::max ()))
256
- throw ill_formatted_cbor_data{};
256
+ throw ill_formatted_cbor_data{ " CBOR signed integer too large " };
257
257
258
258
return -1 - static_cast <int64_t >(x);
259
259
}
@@ -278,7 +278,7 @@ namespace goldfish { namespace cbor
278
278
static optional<document<Stream>> fn_float_16 (Stream&& s, byte) { return read_half_point_float (s); }
279
279
static optional<document<Stream>> fn_float_32 (Stream&& s, byte) { return double { to_float (from_big_endian (stream::read<uint32_t >(s))) }; }
280
280
static optional<document<Stream>> fn_float_64 (Stream&& s, byte) { return to_double (from_big_endian (stream::read<uint64_t >(s))); }
281
- static optional<document<Stream>> fn_ill_formatted (Stream&&, byte) { throw ill_formatted_cbor_data{}; };
281
+ static optional<document<Stream>> fn_ill_formatted (Stream&&, byte) { throw ill_formatted_cbor_data{ " Unexpected CBOR opcode " }; };
282
282
283
283
static optional<document<Stream>> fn_small_binary (Stream&& s, byte first_byte) { return byte_string<Stream>{ std::move (s), static_cast <uint8_t >(first_byte & 31 ) }; };
284
284
static optional<document<Stream>> fn_8_binary (Stream&& s, byte) { return byte_string<Stream>{ std::move (s), stream::read<uint8_t >(s) }; };
@@ -392,7 +392,7 @@ namespace goldfish { namespace cbor
392
392
{
393
393
auto d = read_no_debug_check (std::forward<Stream>(s));
394
394
if (!d)
395
- throw ill_formatted_cbor_data{};
395
+ throw ill_formatted_cbor_data{ " Unexpected break code in CBOR stream " };
396
396
return debug_checks::add_read_checks (std::move (*d), e);
397
397
}
398
398
template <class Stream > auto read (Stream&& s) { return read (std::forward<Stream>(s), debug_checks::default_error_handler{}); }
0 commit comments