-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.
- 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).
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;
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;
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;
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();
fp = fopen("key.pub", "r");
if (!fp) goto clean;
- fseek(fp ,0L ,SEEK_END);
+ fseek(fp, 0L, SEEK_END);
size = ftell(fp);
rewind(fp);
if (fp == NULL)
goto clean;
- fseek(fp ,0L ,SEEK_END);
+ fseek(fp, 0L, SEEK_END);
size = ftell(fp);
rewind(fp);
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;
if (f == NULL)
return -1;
- for(;;) {
+ for (;;) {
size_t read = fread(tmp, 1, BUF_SIZE, f);
if (read > 0) {
#include "internal.h"
-struct yaca_digest_ctx_s
-{
+struct yaca_digest_ctx_s {
struct yaca_ctx_s ctx;
EVP_MD_CTX *mdctx;
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:
*md = NULL;
- switch (algo)
- {
+ switch (algo) {
case YACA_DIGEST_MD5:
*md = EVP_md5();
break;
OP_DECRYPT = 1
};
-struct yaca_encrypt_ctx_s
-{
+struct yaca_encrypt_ctx_s {
struct yaca_ctx_s ctx;
EVP_CIPHER_CTX *cipher_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:
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) {
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;
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:
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);
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);
}
#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,
};
/* 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);
/* Base structure for crypto keys - to be inherited */
-struct yaca_key_s
-{
+struct yaca_key_s {
yaca_key_type_e type;
};
* - 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;
* - YACA_KEY_TYPE_EC_PRIV
*
*/
-struct yaca_key_evp_s
-{
+struct yaca_key_evp_s {
struct yaca_key_s key;
EVP_PKEY *evp;
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;
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;
}
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;
}
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:
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:
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;
}
if (key_fmt == YACA_KEY_FORMAT_PKCS8) {
//TODO NOT_IMPLEMENTED
+ return YACA_ERROR_INVALID_ARGUMENT;
}
return YACA_ERROR_INVALID_ARGUMENT;
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);
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;
}
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;
OP_OPEN = 1
};
-struct yaca_seal_ctx_s
-{
+struct yaca_seal_ctx_s {
struct yaca_ctx_s ctx;
EVP_CIPHER_CTX *cipher_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:
OP_VERIFY = 1
};
-struct yaca_sign_ctx_s
-{
+struct yaca_sign_ctx_s {
struct yaca_ctx_s ctx;
EVP_MD_CTX *mdctx;
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:
return ret;
}
- switch(pad) {
+ switch (pad) {
case RSA_X931_PADDING:
padding = YACA_PADDING_X931;
break;
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;
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;
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;
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();
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;
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;
}
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;
goto err_free;
written += out_len;
- assert (written <= lcipher_len);
+ assert(written <= lcipher_len);
rcipher = yaca_realloc(lcipher, written);
if (rcipher == NULL) {