@@ -29,16 +29,6 @@ namespace
2929 }
3030 }
3131
32- Value consume_unsigned (cbor_nondet_t cbor)
33- {
34- Unsigned value{0 };
35- if (!cbor_nondet_read_uint64 (cbor, &value))
36- {
37- throw CBORDecodeError (" Failed to consume unsigned value" );
38- }
39- return std::make_unique<ValueImpl>(value);
40- }
41-
4232 Value consume_signed (cbor_nondet_t cbor)
4333 {
4434 Signed value{0 };
@@ -151,7 +141,6 @@ namespace
151141 switch (mt)
152142 {
153143 case CBOR_MAJOR_TYPE_UINT64:
154- return consume_unsigned (cbor);
155144 case CBOR_MAJOR_TYPE_NEG_INT64:
156145 return consume_signed (cbor);
157146 case CBOR_MAJOR_TYPE_BYTE_STRING:
@@ -184,12 +173,7 @@ namespace
184173 std::visit (
185174 [&os, indent](const auto & v) {
186175 using T = std::decay_t <decltype (v)>;
187- if constexpr (std::is_same_v<T, Unsigned>)
188- {
189- print_indent (os, indent);
190- os << " Unsigned: " << v << std::endl;
191- }
192- else if constexpr (std::is_same_v<T, Signed>)
176+ if constexpr (std::is_same_v<T, Signed>)
193177 {
194178 print_indent (os, indent);
195179 os << " Signed: " << v << std::endl;
@@ -268,24 +252,10 @@ namespace
268252 },
269253 value->value );
270254 }
271-
272- bool signed_equals_unsigned (Signed a, Unsigned b)
273- {
274- if (a < 0 || b > std::numeric_limits<Signed>::max ())
275- {
276- return false ;
277- }
278- return a == b;
279- }
280255} // namespace
281256
282257namespace ccf ::cbor
283258{
284- Value make_unsigned (uint64_t value)
285- {
286- return std::make_unique<ValueImpl>(value);
287- }
288-
289259 Value make_signed (int64_t value)
290260 {
291261 return std::make_unique<ValueImpl>(value);
@@ -382,21 +352,9 @@ namespace ccf::cbor
382352
383353 if constexpr (!std::is_same_v<TA, TB>)
384354 {
385- // Handle unsigned/signed equally for key comparison.
386- if constexpr (
387- std::is_same_v<TA, Signed> && std::is_same_v<TB, Unsigned>)
388- {
389- return signed_equals_unsigned (a, b);
390- }
391- if constexpr (
392- std::is_same_v<TA, Unsigned> && std::is_same_v<TB, Signed>)
393- {
394- return signed_equals_unsigned (b, a);
395- }
396355 return false ;
397356 }
398- else if constexpr (
399- std::is_same_v<TA, Unsigned> || std::is_same_v<TA, Signed>)
357+ else if constexpr (std::is_same_v<TA, Signed>)
400358 {
401359 return a == b;
402360 }
@@ -453,40 +411,15 @@ namespace ccf::cbor
453411 return tagged.item ;
454412 }
455413
456- Unsigned ValueImpl::as_unsigned () const
457- {
458- if (!std::holds_alternative<Unsigned>(value))
459- {
460- if (!std::holds_alternative<Signed>(value))
461- {
462- throw CBORDecodeError (" Not an unsigned value" );
463- }
464- const auto s_value = std::get<Signed>(value);
465- if (s_value < 0 )
466- {
467- throw CBORDecodeError (" Casting signed to unsigned will overflow" );
468- }
469- return static_cast <Unsigned>(s_value);
470- }
471- return std::get<Unsigned>(value);
472- }
473414 Signed ValueImpl::as_signed () const
474415 {
475416 if (!std::holds_alternative<Signed>(value))
476417 {
477- if (!std::holds_alternative<Unsigned>(value))
478- {
479- throw CBORDecodeError (" Not a signed value" );
480- }
481- const auto u_value = std::get<Unsigned>(value);
482- if (u_value > std::numeric_limits<int64_t >::max ())
483- {
484- throw CBORDecodeError (" Casting unsigned to signed will overflow" );
485- }
486- return static_cast <Signed>(u_value);
418+ throw CBORDecodeError (" Not a signed value" );
487419 }
488420 return std::get<Signed>(value);
489421 }
422+
490423 Bytes ValueImpl::as_bytes () const
491424 {
492425 if (!std::holds_alternative<Bytes>(value))
@@ -495,6 +428,7 @@ namespace ccf::cbor
495428 }
496429 return std::get<Bytes>(value);
497430 }
431+
498432 String ValueImpl::as_string () const
499433 {
500434 if (!std::holds_alternative<String>(value))
@@ -503,6 +437,7 @@ namespace ccf::cbor
503437 }
504438 return std::get<String>(value);
505439 }
440+
506441 Simple ValueImpl::as_simple () const
507442 {
508443 if (!std::holds_alternative<Simple>(value))
0 commit comments