Skip to content

Commit c8300fc

Browse files
committed
libhashkit/aes: fix code indentation
1 parent 6f1f694 commit c8300fc

File tree

1 file changed

+48
-46
lines changed

1 file changed

+48
-46
lines changed

src/libhashkit/aes.cc

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -55,58 +55,60 @@ bool aes_initialize(const unsigned char *key, const size_t key_length,
5555

5656
hashkit_string_st *aes_encrypt(encryption_context_t *crypto_context, const unsigned char *source,
5757
size_t source_length) {
58-
EVP_CIPHER_CTX *encryption_context = crypto_context->encryption_context;
59-
int cipher_length = source_length + EVP_CIPHER_CTX_block_size(encryption_context);
60-
int final_length = 0;
61-
unsigned char *cipher_text = (unsigned char *) malloc(cipher_length);
62-
if (cipher_text == NULL) {
63-
return NULL;
64-
}
65-
if (EVP_EncryptInit_ex(encryption_context, NULL, NULL, NULL, NULL) != 1
66-
|| EVP_EncryptUpdate(encryption_context, cipher_text, &cipher_length, source, source_length)
67-
!= 1
68-
|| EVP_EncryptFinal_ex(encryption_context, cipher_text + cipher_length, &final_length) != 1)
69-
{
70-
free(cipher_text);
71-
return NULL;
72-
}
58+
EVP_CIPHER_CTX *encryption_context = crypto_context->encryption_context;
59+
int cipher_length = source_length + EVP_CIPHER_CTX_block_size(encryption_context);
60+
int final_length = 0;
61+
unsigned char *cipher_text = (unsigned char *) malloc(cipher_length);
62+
if (cipher_text == NULL) {
63+
return NULL;
64+
}
65+
if (EVP_EncryptInit_ex(encryption_context, NULL, NULL, NULL, NULL) != 1
66+
|| EVP_EncryptUpdate(encryption_context, cipher_text, &cipher_length, source, source_length)
67+
!= 1
68+
|| EVP_EncryptFinal_ex(encryption_context, cipher_text + cipher_length, &final_length) != 1)
69+
{
70+
free(cipher_text);
71+
return NULL;
72+
}
7373

74-
hashkit_string_st *destination = hashkit_string_create(cipher_length + final_length);
75-
if (destination == NULL) {
76-
return NULL;
77-
}
78-
char *dest = hashkit_string_c_str_mutable(destination);
79-
memcpy(dest, cipher_text, cipher_length + final_length);
80-
hashkit_string_set_length(destination, cipher_length + final_length);
81-
return destination;
74+
hashkit_string_st *destination = hashkit_string_create(cipher_length + final_length);
75+
if (destination == NULL) {
76+
return NULL;
77+
}
78+
char *dest = hashkit_string_c_str_mutable(destination);
79+
memcpy(dest, cipher_text, cipher_length + final_length);
80+
hashkit_string_set_length(destination, cipher_length + final_length);
81+
return destination;
8282
}
8383

8484
hashkit_string_st *aes_decrypt(encryption_context_t *crypto_context, const unsigned char *source,
8585
size_t source_length) {
86-
EVP_CIPHER_CTX *decryption_context = crypto_context->decryption_context;
87-
int plain_text_length = source_length;
88-
int final_length = 0;
89-
unsigned char *plain_text = (unsigned char *) malloc(plain_text_length);
90-
if (plain_text == NULL) {
91-
return NULL;
92-
}
93-
if (EVP_DecryptInit_ex(decryption_context, NULL, NULL, NULL, NULL) != 1
94-
|| EVP_DecryptUpdate(decryption_context, plain_text, &plain_text_length, source, source_length)
95-
!= 1
96-
|| EVP_DecryptFinal_ex(decryption_context, plain_text + plain_text_length, &final_length) != 1)
97-
{
98-
free(plain_text);
99-
return NULL;
100-
}
86+
EVP_CIPHER_CTX *decryption_context = crypto_context->decryption_context;
87+
int plain_text_length = source_length;
88+
int final_length = 0;
89+
unsigned char *plain_text = (unsigned char *) malloc(plain_text_length);
90+
if (plain_text == NULL) {
91+
return NULL;
92+
}
93+
if (EVP_DecryptInit_ex(decryption_context, NULL, NULL, NULL, NULL) != 1
94+
|| EVP_DecryptUpdate(decryption_context, plain_text, &plain_text_length, source,
95+
source_length)
96+
!= 1
97+
|| EVP_DecryptFinal_ex(decryption_context, plain_text + plain_text_length, &final_length)
98+
!= 1)
99+
{
100+
free(plain_text);
101+
return NULL;
102+
}
101103

102-
hashkit_string_st *destination = hashkit_string_create(plain_text_length + final_length);
103-
if (destination == NULL) {
104-
return NULL;
105-
}
106-
char *dest = hashkit_string_c_str_mutable(destination);
107-
memcpy(dest, plain_text, plain_text_length + final_length);
108-
hashkit_string_set_length(destination, plain_text_length + final_length);
109-
return destination;
104+
hashkit_string_st *destination = hashkit_string_create(plain_text_length + final_length);
105+
if (destination == NULL) {
106+
return NULL;
107+
}
108+
char *dest = hashkit_string_c_str_mutable(destination);
109+
memcpy(dest, plain_text, plain_text_length + final_length);
110+
hashkit_string_set_length(destination, plain_text_length + final_length);
111+
return destination;
110112
}
111113

112114
encryption_context_t *aes_clone_cryptographic_context(encryption_context_t *source) {

0 commit comments

Comments
 (0)