From 9302fabc7ea1c60893d5a49768a7e2c874fe14ed Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Tue, 31 May 2016 11:45:06 +0200 Subject: [PATCH] ACR: Fix code formatting. Change-Id: I139f83922a3a1407b2188fb7025637834aa414a8 --- doc/coding-rules.txt | 5 ++--- examples/encrypt.c | 10 +++++----- examples/key_exchange.c | 4 ++-- examples/key_import_export.c | 2 +- examples/misc.c | 2 +- src/digest.c | 9 +++------ src/encrypt.c | 20 +++++++------------- src/internal.h | 17 ++++++----------- src/key.c | 21 ++++++++++----------- src/seal.c | 6 ++---- src/sign.c | 30 ++++++++++++------------------ src/simple.c | 4 ++-- 12 files changed, 53 insertions(+), 77 deletions(-) diff --git a/doc/coding-rules.txt b/doc/coding-rules.txt index 36660e4..4f55843 100644 --- a/doc/coding-rules.txt +++ b/doc/coding-rules.txt @@ -44,6 +44,8 @@ Note: No single space allowed -Exception: Where the closing race is followed by a continuation of the same statement, else should follow close brace '}', while should follow close brace '}' +[M06] [BRC_M_EUS] Open braces for enum, union and struct go on the same line. + [R06] [BRC_R_SST] Do not unnecessarily use braces where a single statement will do. -Exception: if one branch of a conditional statement is a single statement, use braces in both branches. @@ -89,15 +91,12 @@ Note: this is rule of thumb except for Public API. Public API has prefix ( 0) { diff --git a/src/digest.c b/src/digest.c index 5bb6883..47d8f57 100644 --- a/src/digest.c +++ b/src/digest.c @@ -31,8 +31,7 @@ #include "internal.h" -struct yaca_digest_ctx_s -{ +struct yaca_digest_ctx_s { struct yaca_ctx_s ctx; EVP_MD_CTX *mdctx; @@ -43,8 +42,7 @@ static struct yaca_digest_ctx_s *get_digest_ctx(const yaca_ctx_h ctx) if (ctx == YACA_CTX_NULL) return NULL; - switch (ctx->type) - { + switch (ctx->type) { case YACA_CTX_DIGEST: return (struct yaca_digest_ctx_s *)ctx; default: @@ -83,8 +81,7 @@ int digest_get_algorithm(yaca_digest_algo_e algo, const EVP_MD **md) *md = NULL; - switch (algo) - { + switch (algo) { case YACA_DIGEST_MD5: *md = EVP_md5(); break; diff --git a/src/encrypt.c b/src/encrypt.c index 385bec7..27eeb57 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -38,8 +38,7 @@ enum encrypt_op_type { OP_DECRYPT = 1 }; -struct yaca_encrypt_ctx_s -{ +struct yaca_encrypt_ctx_s { struct yaca_ctx_s ctx; EVP_CIPHER_CTX *cipher_ctx; @@ -52,8 +51,7 @@ static struct yaca_encrypt_ctx_s *get_encrypt_ctx(const yaca_ctx_h ctx) if (ctx == YACA_CTX_NULL) return NULL; - switch (ctx->type) - { + switch (ctx->type) { case YACA_CTX_ENCRYPT: return (struct yaca_encrypt_ctx_s *)ctx; default: @@ -111,8 +109,7 @@ static int set_encrypt_param(yaca_ctx_h ctx, return YACA_ERROR_INVALID_ARGUMENT; assert(c->cipher_ctx != NULL); - switch(param) - { + switch (param) { case YACA_PARAM_GCM_AAD: case YACA_PARAM_CCM_AAD: if (EVP_EncryptUpdate(c->cipher_ctx, NULL, &len, value, value_len) != 1) { @@ -167,8 +164,7 @@ static int get_encrypt_param(const yaca_ctx_h ctx, return YACA_ERROR_INVALID_ARGUMENT; assert(c->cipher_ctx != NULL); - switch(param) - { + switch (param) { case YACA_PARAM_GCM_TAG: if (c->tag_len == 0) return YACA_ERROR_INVALID_ARGUMENT; @@ -202,8 +198,7 @@ static int get_encrypt_param(const yaca_ctx_h ctx, static const char *encrypt_algo_to_str(yaca_enc_algo_e algo) { - switch(algo) - { + switch (algo) { case YACA_ENC_AES: return "aes"; case YACA_ENC_UNSAFE_DES: @@ -266,8 +261,7 @@ int encrypt_get_algorithm(yaca_enc_algo_e algo, cipher == NULL) return YACA_ERROR_INVALID_ARGUMENT; - switch(algo) - { + switch (algo) { case YACA_ENC_AES: ret = snprintf(cipher_name, sizeof(cipher_name), "%s-%zu-%s", algo_name, key_bits, bcm_name); @@ -616,6 +610,6 @@ API int yaca_decrypt_final(yaca_ctx_h ctx, char *plain, size_t *plain_len) { - return encrypt_final(ctx,(unsigned char*)plain, plain_len, + return encrypt_final(ctx, (unsigned char*)plain, plain_len, OP_DECRYPT); } diff --git a/src/internal.h b/src/internal.h index 660bbd2..1b5901b 100644 --- a/src/internal.h +++ b/src/internal.h @@ -31,10 +31,9 @@ #include -#define API __attribute__ ((visibility ("default"))) +#define API __attribute__ ((visibility("default"))) -enum yaca_ctx_type_e -{ +enum yaca_ctx_type_e { YACA_CTX_INVALID = 0, YACA_CTX_DIGEST, YACA_CTX_SIGN, @@ -43,8 +42,7 @@ enum yaca_ctx_type_e }; /* Base structure for crypto contexts - to be inherited */ -struct yaca_ctx_s -{ +struct yaca_ctx_s { enum yaca_ctx_type_e type; void (*ctx_destroy)(const yaca_ctx_h ctx); @@ -57,8 +55,7 @@ struct yaca_ctx_s /* Base structure for crypto keys - to be inherited */ -struct yaca_key_s -{ +struct yaca_key_s { yaca_key_type_e type; }; @@ -68,8 +65,7 @@ struct yaca_key_s * - YACA_KEY_TYPE_DES * - YACA_KEY_TYPE_IV */ -struct yaca_key_simple_s -{ +struct yaca_key_simple_s { struct yaca_key_s key; size_t bits; @@ -88,8 +84,7 @@ struct yaca_key_simple_s * - YACA_KEY_TYPE_EC_PRIV * */ -struct yaca_key_evp_s -{ +struct yaca_key_evp_s { struct yaca_key_s key; EVP_PKEY *evp; diff --git a/src/key.c b/src/key.c index 9b4e9c0..6e076f0 100755 --- a/src/key.c +++ b/src/key.c @@ -126,7 +126,7 @@ int base64_decode(const char *data, size_t data_len, BIO **output) BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); /* Try to decode */ - for(;;) { + for (;;) { ret = BIO_read(b64, tmpbuf, TMP_BUF_LEN); if (ret < 0) { ret = YACA_ERROR_INTERNAL; @@ -531,8 +531,8 @@ int export_evp(struct yaca_key_evp_s *evp_key, case YACA_KEY_TYPE_EC_PRIV: case YACA_KEY_TYPE_EC_PUB: //TODO NOT_IMPLEMENTED - default: ret = YACA_ERROR_INVALID_ARGUMENT; + default: goto free_bio; } @@ -559,8 +559,8 @@ int export_evp(struct yaca_key_evp_s *evp_key, case YACA_KEY_TYPE_EC_PRIV: case YACA_KEY_TYPE_EC_PUB: //TODO NOT_IMPLEMENTED - default: ret = YACA_ERROR_INVALID_ARGUMENT; + default: goto free_bio; } @@ -828,8 +828,7 @@ struct yaca_key_simple_s *key_get_simple(const yaca_key_h key) if (key == YACA_KEY_NULL) return NULL; - switch (key->type) - { + switch (key->type) { case YACA_KEY_TYPE_SYMMETRIC: case YACA_KEY_TYPE_DES: case YACA_KEY_TYPE_IV: @@ -853,8 +852,7 @@ struct yaca_key_evp_s *key_get_evp(const yaca_key_h key) if (key == YACA_KEY_NULL) return NULL; - switch (key->type) - { + switch (key->type) { case YACA_KEY_TYPE_RSA_PUB: case YACA_KEY_TYPE_RSA_PRIV: case YACA_KEY_TYPE_DSA_PUB: @@ -942,6 +940,7 @@ API int yaca_key_import(yaca_key_type_e key_type, case YACA_KEY_TYPE_EC_PUB: case YACA_KEY_TYPE_EC_PRIV: //TODO NOT_IMPLEMENTED + return YACA_ERROR_INVALID_ARGUMENT; default: return YACA_ERROR_INVALID_ARGUMENT; } @@ -983,6 +982,7 @@ API int yaca_key_export(const yaca_key_h key, if (key_fmt == YACA_KEY_FORMAT_PKCS8) { //TODO NOT_IMPLEMENTED + return YACA_ERROR_INVALID_ARGUMENT; } return YACA_ERROR_INVALID_ARGUMENT; @@ -1001,8 +1001,7 @@ API int yaca_key_gen(yaca_key_type_e key_type, if (key == NULL || key_bits == 0 || key_bits % 8 != 0) return YACA_ERROR_INVALID_ARGUMENT; - switch(key_type) - { + switch (key_type) { case YACA_KEY_TYPE_SYMMETRIC: case YACA_KEY_TYPE_IV: ret = gen_simple(&nk_simple, key_bits); @@ -1047,6 +1046,7 @@ API int yaca_key_gen(yaca_key_type_e key_type, case YACA_KEY_TYPE_DH_PRIV: case YACA_KEY_TYPE_EC_PRIV: //TODO NOT_IMPLEMENTED + return YACA_ERROR_INVALID_ARGUMENT; default: return YACA_ERROR_INVALID_ARGUMENT; } @@ -1094,8 +1094,7 @@ API int yaca_key_extract_public(const yaca_key_h prv_key, yaca_key_h *pub_key) nk->evp = pkey; *pub_key = (yaca_key_h)nk; - switch(prv_key->type) - { + switch (prv_key->type) { case YACA_KEY_TYPE_RSA_PRIV: (*pub_key)->type = YACA_KEY_TYPE_RSA_PUB; break; diff --git a/src/seal.c b/src/seal.c index 5c1ecb1..cdd3cbf 100644 --- a/src/seal.c +++ b/src/seal.c @@ -38,8 +38,7 @@ enum seal_op_type { OP_OPEN = 1 }; -struct yaca_seal_ctx_s -{ +struct yaca_seal_ctx_s { struct yaca_ctx_s ctx; EVP_CIPHER_CTX *cipher_ctx; @@ -51,8 +50,7 @@ static struct yaca_seal_ctx_s *get_seal_ctx(const yaca_ctx_h ctx) if (ctx == YACA_CTX_NULL) return NULL; - switch (ctx->type) - { + switch (ctx->type) { case YACA_CTX_SEAL: return (struct yaca_seal_ctx_s *)ctx; default: diff --git a/src/sign.c b/src/sign.c index 8ed5a6b..938cf11 100644 --- a/src/sign.c +++ b/src/sign.c @@ -43,8 +43,7 @@ enum sign_op_type { OP_VERIFY = 1 }; -struct yaca_sign_ctx_s -{ +struct yaca_sign_ctx_s { struct yaca_ctx_s ctx; EVP_MD_CTX *mdctx; @@ -56,8 +55,7 @@ static struct yaca_sign_ctx_s *get_sign_ctx(const yaca_ctx_h ctx) if (ctx == YACA_CTX_NULL) return NULL; - switch (ctx->type) - { + switch (ctx->type) { case YACA_CTX_SIGN: return (struct yaca_sign_ctx_s *)ctx; default: @@ -209,7 +207,7 @@ int get_sign_param(const yaca_ctx_h ctx, return ret; } - switch(pad) { + switch (pad) { case RSA_X931_PADDING: padding = YACA_PADDING_X931; break; @@ -247,21 +245,20 @@ API int yaca_sign_init(yaca_ctx_h *ctx, if (ctx == NULL || evp_key == NULL) return YACA_ERROR_INVALID_ARGUMENT; - switch (key->type) - { + switch (key->type) { case YACA_KEY_TYPE_RSA_PRIV: case YACA_KEY_TYPE_DSA_PRIV: break; case YACA_KEY_TYPE_EC_PRIV: //TODO NOT_IMPLEMENTED + return YACA_ERROR_INVALID_ARGUMENT; default: return YACA_ERROR_INVALID_ARGUMENT; } nc = yaca_zalloc(sizeof(struct yaca_sign_ctx_s)); - if (nc == NULL) { + if (nc == NULL) return YACA_ERROR_OUT_OF_MEMORY; - } nc->op_type = OP_SIGN; nc->ctx.type = YACA_CTX_SIGN; @@ -313,9 +310,8 @@ API int yaca_sign_hmac_init(yaca_ctx_h *ctx, return YACA_ERROR_INVALID_ARGUMENT; nc = yaca_zalloc(sizeof(struct yaca_sign_ctx_s)); - if (nc == NULL) { + if (nc == NULL) return YACA_ERROR_OUT_OF_MEMORY; - } nc->op_type = OP_SIGN; nc->ctx.type = YACA_CTX_SIGN; @@ -377,9 +373,8 @@ API int yaca_sign_cmac_init(yaca_ctx_h *ctx, return YACA_ERROR_INVALID_ARGUMENT; nc = yaca_zalloc(sizeof(struct yaca_sign_ctx_s)); - if (nc == NULL) { + if (nc == NULL) return YACA_ERROR_OUT_OF_MEMORY; - } nc->op_type = OP_SIGN; nc->ctx.type = YACA_CTX_SIGN; @@ -387,9 +382,8 @@ API int yaca_sign_cmac_init(yaca_ctx_h *ctx, nc->ctx.get_output_length = get_sign_output_length; ret = encrypt_get_algorithm(algo, YACA_BCM_CBC, simple_key->bits, &cipher); - if (ret != YACA_ERROR_NONE) { + if (ret != YACA_ERROR_NONE) goto free_ctx; - } // create and initialize low level CMAC context cmac_ctx = CMAC_CTX_new(); @@ -481,7 +475,7 @@ API int yaca_sign_final(yaca_ctx_h ctx, return YACA_ERROR_INVALID_ARGUMENT; ret = EVP_DigestSignFinal(c->mdctx, (unsigned char *)signature, signature_len); - if(ret != 1) { + if (ret != 1) { ret = YACA_ERROR_INTERNAL; ERROR_DUMP(ret); return ret; @@ -502,13 +496,13 @@ API int yaca_verify_init(yaca_ctx_h *ctx, if (ctx == NULL || evp_key == NULL) return YACA_ERROR_INVALID_ARGUMENT; - switch (key->type) - { + switch (key->type) { case YACA_KEY_TYPE_RSA_PUB: case YACA_KEY_TYPE_DSA_PUB: break; case YACA_KEY_TYPE_EC_PUB: //TODO NOT_IMPLEMENTED + return YACA_ERROR_INVALID_ARGUMENT; default: return YACA_ERROR_INVALID_ARGUMENT; } diff --git a/src/simple.c b/src/simple.c index df4839a..6779b0d 100644 --- a/src/simple.c +++ b/src/simple.c @@ -127,7 +127,7 @@ API int yaca_encrypt(yaca_enc_algo_e algo, if (ret != YACA_ERROR_NONE) goto err_free; - assert (out_len <= lcipher_len); + assert(out_len <= lcipher_len); written = out_len; out_len = lcipher_len - written; @@ -136,7 +136,7 @@ API int yaca_encrypt(yaca_enc_algo_e algo, goto err_free; written += out_len; - assert (written <= lcipher_len); + assert(written <= lcipher_len); rcipher = yaca_realloc(lcipher, written); if (rcipher == NULL) { -- 2.7.4