changed base64_encode length to size_t*

This commit is contained in:
Václav Šmejkal 2025-02-02 15:01:20 +01:00
parent 0a9a716ffe
commit 4c7100760b
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
2 changed files with 7 additions and 7 deletions

View File

@ -43,7 +43,7 @@ extern "C" {
void why2_chat_init_keys(void); //INIT (POSSIBLY GENERATE) ECC KEYS void why2_chat_init_keys(void); //INIT (POSSIBLY GENERATE) ECC KEYS
void why2_chat_deallocate_keys(void); //DEALLOCATE :) (NO SLUR HERE) void why2_chat_deallocate_keys(void); //DEALLOCATE :) (NO SLUR HERE)
char *why2_chat_base64_encode(char *message, size_t length); //ENCODE message OF length INTO BASE64 WITH LENGTH DELIMITER (WHY2_CHAT_BASE64_LENGTH_DELIMITER) char *why2_chat_base64_encode(char *message, size_t *length); //ENCODE message OF length INTO BASE64 WITH LENGTH DELIMITER (WHY2_CHAT_BASE64_LENGTH_DELIMITER)
char *why2_chat_base64_decode(char *encoded_message, size_t *length); //DECODE encoded_message AND SET length TO OUTPUT LENGTH char *why2_chat_base64_decode(char *encoded_message, size_t *length); //DECODE encoded_message AND SET length TO OUTPUT LENGTH
char *why2_chat_ecc_sign(char *message); //SIGN message WITH ECC KEY char *why2_chat_ecc_sign(char *message); //SIGN message WITH ECC KEY

View File

@ -96,7 +96,7 @@ void why2_chat_init_keys(void)
why2_deallocate(key); why2_deallocate(key);
} }
char *why2_chat_base64_encode(char *message, size_t length) char *why2_chat_base64_encode(char *message, size_t *length)
{ {
//VARIABLES //VARIABLES
BIO *bio; BIO *bio;
@ -111,15 +111,15 @@ char *why2_chat_base64_encode(char *message, size_t length)
bio = BIO_push(b64, bio); bio = BIO_push(b64, bio);
//ENCODE //ENCODE
BIO_write(bio, message, length); BIO_write(bio, message, *length);
BIO_flush(bio); BIO_flush(bio);
BIO_get_mem_ptr(bio, &buffer_ptr); BIO_get_mem_ptr(bio, &buffer_ptr);
//COPY //COPY
encoded_message = why2_malloc(buffer_ptr -> length + why2_count_int_length((int) length) + 2); encoded_message = why2_malloc(buffer_ptr -> length + why2_count_int_length((int) *length) + 2);
memcpy(encoded_message, buffer_ptr -> data, buffer_ptr -> length); memcpy(encoded_message, buffer_ptr -> data, buffer_ptr -> length);
sprintf(encoded_message + buffer_ptr -> length, "%c%zu%c", WHY2_CHAT_BASE64_LENGTH_DELIMITER, length, '\0'); //APPEND LENGTH sprintf(encoded_message + buffer_ptr -> length, "%c%zu%c", WHY2_CHAT_BASE64_LENGTH_DELIMITER, *length, '\0'); //APPEND LENGTH
//DEALLOCATION //DEALLOCATION
BIO_free_all(bio); BIO_free_all(bio);
@ -177,7 +177,7 @@ char *why2_chat_ecc_sign(char *message)
sig = why2_malloc(siglen); //ALLOCATE SIGNATURE sig = why2_malloc(siglen); //ALLOCATE SIGNATURE
EVP_DigestSignFinal(mdctx, (unsigned char*) sig, &siglen); EVP_DigestSignFinal(mdctx, (unsigned char*) sig, &siglen);
encoded_sig = why2_chat_base64_encode(sig, siglen); //CONVERT sig TO BASE64 encoded_sig = why2_chat_base64_encode(sig, &siglen); //CONVERT sig TO BASE64
//DEALLOCATION //DEALLOCATION
why2_deallocate(sig); why2_deallocate(sig);
@ -232,7 +232,7 @@ char *why2_chat_ecc_serialize_public_key()
pubkey[length] = '\0'; pubkey[length] = '\0';
//ENCODE //ENCODE
base64_encoded = why2_chat_base64_encode(pubkey, length); base64_encoded = why2_chat_base64_encode(pubkey, &length);
//DEALLOCATION //DEALLOCATION
BIO_free(bio); BIO_free(bio);