Skip to content

Commit f0607a8

Browse files
committed
MessageDecoder: rewrite copyCBORStringToArray and copyCBORByteToArray
1 parent 1563598 commit f0607a8

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/cbor/MessageDecoder.cpp

+12-17
Original file line numberDiff line numberDiff line change
@@ -69,32 +69,27 @@ Decoder::Status CBORMessageDecoder::decode(Message * message, uint8_t const * co
6969
******************************************************************************/
7070

7171
bool copyCBORStringToArray(CborValue * param, char * dest, size_t dest_size) {
72-
if (!cbor_value_is_text_string(param)) {
73-
return false;
74-
}
75-
76-
// NOTE: keep in mind that _cbor_value_copy_string tries to put a \0 at the end of the string
77-
if(_cbor_value_copy_string(param, dest, &dest_size, NULL) != CborNoError) {
78-
return false;
72+
if (cbor_value_is_text_string(param)) {
73+
// NOTE: keep in mind that _cbor_value_copy_string tries to put a \0 at the end of the string
74+
if(_cbor_value_copy_string(param, dest, &dest_size, NULL) == CborNoError) {
75+
return true;
76+
}
7977
}
8078

81-
return true;
79+
return false;
8280
}
8381

8482
// FIXME dest_size should be also returned, the copied byte array can have a different size from the starting one
8583
// for the time being we need this on SHA256 only
8684
bool copyCBORByteToArray(CborValue * param, uint8_t * dest, size_t dest_size) {
87-
if (!cbor_value_is_byte_string(param)) {
88-
return false;
89-
}
90-
91-
// NOTE: keep in mind that _cbor_value_copy_string tries to put a \0 at the end of the string
92-
if(_cbor_value_copy_string(param, dest, &dest_size, NULL) != CborNoError) {
93-
94-
return false;
85+
if (cbor_value_is_byte_string(param)) {
86+
// NOTE: keep in mind that _cbor_value_copy_string tries to put a \0 at the end of the string
87+
if(_cbor_value_copy_string(param, dest, &dest_size, NULL) == CborNoError) {
88+
return true;
89+
}
9590
}
9691

97-
return true;
92+
return false;
9893
}
9994

10095
CBORMessageDecoder::ArrayParserState CBORMessageDecoder::handle_EnterArray(CborValue * main_iter, CborValue * array_iter) {

0 commit comments

Comments
 (0)