ACR: Fix code formatting. 94/72294/3
authorDariusz Michaluk <d.michaluk@samsung.com>
Tue, 31 May 2016 09:45:06 +0000 (11:45 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Tue, 31 May 2016 11:51:53 +0000 (13:51 +0200)
Change-Id: I139f83922a3a1407b2188fb7025637834aa414a8

12 files changed:
doc/coding-rules.txt
examples/encrypt.c
examples/key_exchange.c
examples/key_import_export.c
examples/misc.c
src/digest.c
src/encrypt.c
src/internal.h
src/key.c
src/seal.c
src/sign.c
src/simple.c

index 36660e4..4f55843 100644 (file)
@@ -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 (<libra
 - Line length
     - soft limit (can be broken if expression will be more readable) 80 chars,
     - hard limit 100 characters (should not be broken)
-- Enums, structs, unions etc. should use brackets in newline (like functions)
 - Typedefs should be used only where necessary (for example to make private implementations)
 - Function arguments should either fit one line, or each parameter should be placed in separate line
 
 --------------------------------------------------------------------------------
 3. Tizen rules that should NOT be followed
 --------------------------------------------------------------------------------
-[M06] [BRC_M_EUS] Open braces for enum, union and struct go on the same line.
-Note: They go in new line - the same way as for functions
 
 [R17] Local functions whose scope is limited to the current source file have "static" keyword and names started with "__".
 Note: static functions should not include "prefix" but can have arbitrary names (see R16).
index e4c18f7..7c18aa9 100644 (file)
@@ -196,14 +196,14 @@ int main()
        size_t key_bits = YACA_KEY_256BIT;
 
        encrypt_simple(algo, bcm, key_bits);
-       encrypt_advanced(algo, bcm, key_type,key_bits);
+       encrypt_advanced(algo, bcm, key_type, key_bits);
 
        algo = YACA_ENC_3DES_3TDEA;
        bcm = YACA_BCM_OFB;
        key_type = YACA_KEY_TYPE_DES;
        key_bits = YACA_KEY_192BIT;
 
-       encrypt_advanced(algo, bcm, key_type,key_bits);
+       encrypt_advanced(algo, bcm, key_type, key_bits);
 
        algo = YACA_ENC_CAST5;
        bcm = YACA_BCM_CFB;
@@ -211,7 +211,7 @@ int main()
        key_bits = YACA_KEY_UNSAFE_40BIT;
 
        encrypt_simple(algo, bcm, key_bits);
-       encrypt_advanced(algo, bcm, key_type,key_bits);
+       encrypt_advanced(algo, bcm, key_type, key_bits);
 
        algo = YACA_ENC_UNSAFE_RC2;
        bcm = YACA_BCM_CBC;
@@ -219,7 +219,7 @@ int main()
        key_bits = YACA_KEY_UNSAFE_8BIT;
 
        encrypt_simple(algo, bcm, key_bits);
-       encrypt_advanced(algo, bcm, key_type,key_bits);
+       encrypt_advanced(algo, bcm, key_type, key_bits);
 
        algo = YACA_ENC_UNSAFE_RC4;
        bcm = YACA_BCM_NONE;
@@ -227,7 +227,7 @@ int main()
        key_bits = YACA_KEY_2048BIT;
 
        encrypt_simple(algo, bcm, key_bits);
-       encrypt_advanced(algo, bcm, key_type,key_bits);
+       encrypt_advanced(algo, bcm, key_type, key_bits);
 
        yaca_exit();
 
index 7233a10..4432859 100644 (file)
@@ -57,7 +57,7 @@ void key_exchange_dh(void)
        fp = fopen("key.pub", "r");
        if (!fp) goto clean;
 
-       fseek(fp ,0L ,SEEK_END);
+       fseek(fp, 0L, SEEK_END);
        size = ftell(fp);
        rewind(fp);
 
@@ -117,7 +117,7 @@ void key_exchange_ecdh(void)
        if (fp == NULL)
                goto clean;
 
-       fseek(fp ,0L ,SEEK_END);
+       fseek(fp, 0L, SEEK_END);
        size = ftell(fp);
        rewind(fp);
 
index 3fb33e6..f6f77fd 100644 (file)
@@ -36,7 +36,7 @@ int key_import_export_sym(yaca_key_h sym)
 
        char *raw = NULL;
        size_t raw_len;
-       char *b64= NULL;
+       char *b64 = NULL;
        size_t b64_len;
 
        yaca_key_h raw_imported = YACA_KEY_NULL;
index 7eaedf3..ad7bc40 100644 (file)
@@ -87,7 +87,7 @@ int read_file(const char *path, char **data, size_t *data_len)
        if (f == NULL)
                return -1;
 
-       for(;;) {
+       for (;;) {
                size_t read = fread(tmp, 1, BUF_SIZE, f);
 
                if (read > 0) {
index 5bb6883..47d8f57 100644 (file)
@@ -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;
index 385bec7..27eeb57 100644 (file)
@@ -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);
 }
index 660bbd2..1b5901b 100644 (file)
 
 #include <yaca_types.h>
 
-#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;
index 9b4e9c0..6e076f0 100755 (executable)
--- 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;
index 5c1ecb1..cdd3cbf 100644 (file)
@@ -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:
index 8ed5a6b..938cf11 100644 (file)
@@ -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;
        }
index df4839a..6779b0d 100644 (file)
@@ -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) {