Format code

This commit is contained in:
Tomas Rezucha 2022-02-17 14:56:45 +01:00
parent 5362db237b
commit e651ec16c5
8 changed files with 1555 additions and 1537 deletions

View File

@ -9,6 +9,7 @@
#if 0 //High level layout for state machine
// *INDENT-OFF*
@startuml
[*] --> READ_MAGIC
READ_MAGIC --> READ_MAGIC : READ LEN < 4
@ -34,7 +35,7 @@ PROCESS_BINARY --> ESP_OK : READ LEN = BIN_SIZE
ESP_OK --> [*]
ESP_FAIL --> [*]
@enduml
// *INDENT-OFF*
#endif
#ifdef __cplusplus

View File

@ -378,8 +378,7 @@ esp_err_t esp_encrypted_img_decrypt_data(esp_decrypt_handle_t *ctx, pre_enc_decr
return ESP_ERR_NOT_FINISHED;
}
/* falls through */
case ESP_PRE_ENC_IMG_READ_EXTRA_HEADER:
{
case ESP_PRE_ENC_IMG_READ_EXTRA_HEADER: {
int temp = curr_index;
curr_index += MIN(args->data_in_len - curr_index, RESERVED_HEADER - handle->binary_file_read);
handle->binary_file_read += MIN(args->data_in_len - temp, RESERVED_HEADER - handle->binary_file_read);

View File

@ -63,8 +63,8 @@ static void data_handler(void *userData, const XML_Char *s, int len)
insert_space(user_data);
// s is not zero-terminated
char tmp_str[len+1];
strlcpy(tmp_str, s, len+1);
char tmp_str[len + 1];
strlcpy(tmp_str, s, len + 1);
int ret = snprintf(user_data->output + user_data->output_off, sizeof(user_data->output) - user_data->output_off,
"%s", tmp_str);

View File

@ -34,7 +34,8 @@
* Allocates a fresh unused token from the token pull.
*/
static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser,
jsmntok_t *tokens, size_t num_tokens) {
jsmntok_t *tokens, size_t num_tokens)
{
jsmntok_t *tok;
if (parser->toknext >= num_tokens) {
return NULL;
@ -52,7 +53,8 @@ static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser,
* Fills token type and boundaries.
*/
static void jsmn_fill_token(jsmntok_t *token, jsmntype_t type,
int start, int end) {
int start, int end)
{
token->type = type;
token->start = start;
token->end = end;
@ -63,7 +65,8 @@ static void jsmn_fill_token(jsmntok_t *token, jsmntype_t type,
* Fills next available token with JSON primitive.
*/
static int jsmn_parse_primitive(jsmn_parser *parser, const char *js,
size_t len, jsmntok_t *tokens, size_t num_tokens) {
size_t len, jsmntok_t *tokens, size_t num_tokens)
{
jsmntok_t *token;
int start;
@ -112,7 +115,8 @@ found:
* Fills next token with JSON string.
*/
static int jsmn_parse_string(jsmn_parser *parser, const char *js,
size_t len, jsmntok_t *tokens, size_t num_tokens) {
size_t len, jsmntok_t *tokens, size_t num_tokens)
{
jsmntok_t *token;
int start = parser->pos;
@ -133,7 +137,7 @@ static int jsmn_parse_string(jsmn_parser *parser, const char *js,
parser->pos = start;
return JSMN_ERROR_NOMEM;
}
jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos);
jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
#ifdef JSMN_PARENT_LINKS
token->parent = parser->toksuper;
#endif
@ -152,9 +156,9 @@ static int jsmn_parse_string(jsmn_parser *parser, const char *js,
/* Allows escaped symbol \uXXXX */
case 'u':
parser->pos++;
for(i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++) {
for (i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++) {
/* If it isn't a hex character we have an error */
if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
if (!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
(js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
(js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */
parser->pos = start;
@ -179,7 +183,8 @@ static int jsmn_parse_string(jsmn_parser *parser, const char *js,
* Parse JSON string and fill tokens.
*/
int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
jsmntok_t *tokens, unsigned int num_tokens) {
jsmntok_t *tokens, unsigned int num_tokens)
{
int r;
int i;
jsmntok_t *token;
@ -197,8 +202,9 @@ int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
break;
}
token = jsmn_alloc_token(parser, tokens, num_tokens);
if (token == NULL)
if (token == NULL) {
return JSMN_ERROR_NOMEM;
}
if (parser->toksuper != -1) {
tokens[parser->toksuper].size++;
#ifdef JSMN_PARENT_LINKS
@ -210,8 +216,9 @@ int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
parser->toksuper = parser->toknext - 1;
break;
case '}': case ']':
if (tokens == NULL)
if (tokens == NULL) {
break;
}
type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
#ifdef JSMN_PARENT_LINKS
if (parser->toknext < 1) {
@ -245,7 +252,9 @@ int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
}
}
/* Error if unmatched closing bracket */
if (i == -1) return JSMN_ERROR_INVAL;
if (i == -1) {
return JSMN_ERROR_INVAL;
}
for (; i >= 0; i--) {
token = &tokens[i];
if (token->start != -1 && token->end == -1) {
@ -257,10 +266,13 @@ int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
break;
case '\"':
r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
if (r < 0) return r;
if (r < 0) {
return r;
}
count++;
if (parser->toksuper != -1 && tokens != NULL)
if (parser->toksuper != -1 && tokens != NULL) {
tokens[parser->toksuper].size++;
}
break;
case '\t' : case '\r' : case '\n' : case ' ':
break;
@ -303,10 +315,13 @@ int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
default:
#endif
r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
if (r < 0) return r;
if (r < 0) {
return r;
}
count++;
if (parser->toksuper != -1 && tokens != NULL)
if (parser->toksuper != -1 && tokens != NULL) {
tokens[parser->toksuper].size++;
}
break;
#ifdef JSMN_STRICT
@ -333,7 +348,8 @@ int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
* Creates a new parser based over a given buffer with an array of tokens
* available.
*/
void jsmn_init(jsmn_parser *parser) {
void jsmn_init(jsmn_parser *parser)
{
parser->pos = 0;
parser->toknext = 0;
parser->toksuper = -1;

View File

@ -71,7 +71,8 @@ TEST_CASE("sha256 sanity check", "[libsodium]")
const uint8_t expected[] = { 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41,
0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, 0xb0, 0x03,
0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff,
0x61, 0xf2, 0x00, 0x15, 0xad, };
0x61, 0xf2, 0x00, 0x15, 0xad,
};
uint8_t calculated[32];
crypto_hash_sha256_state state;
@ -87,7 +88,7 @@ TEST_CASE("sha256 sanity check", "[libsodium]")
// Multi-line version
crypto_hash_sha256_init(&state);
crypto_hash_sha256_update(&state, in, inlen - 1); // split into two updates
crypto_hash_sha256_update(&state, in + (inlen -1), 1);
crypto_hash_sha256_update(&state, in + (inlen - 1), 1);
crypto_hash_sha256_final(&state, calculated);
TEST_ASSERT_EQUAL_MEMORY(expected, calculated, crypto_hash_sha256_bytes());
}
@ -101,7 +102,8 @@ TEST_CASE("sha512 sanity check", "[libsodium]")
0x27, 0x4f, 0xc1, 0xa8, 0x36, 0xba, 0x3c, 0x23, 0xa3,
0xfe, 0xeb, 0xbd, 0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c,
0xe8, 0x0e, 0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4,
0x9f };
0x9f
};
uint8_t calculated[64];
crypto_hash_sha512_state state;
@ -118,7 +120,7 @@ TEST_CASE("sha512 sanity check", "[libsodium]")
// Multi-line version
crypto_hash_sha512_init(&state);
crypto_hash_sha512_update(&state, in, inlen - 1); // split into two updates
crypto_hash_sha512_update(&state, in + (inlen -1), 1);
crypto_hash_sha512_update(&state, in + (inlen - 1), 1);
crypto_hash_sha512_final(&state, calculated);
TEST_ASSERT_EQUAL_MEMORY(expected, calculated, crypto_hash_sha512_bytes());
}