added base64_decode fn
All checks were successful
Codacy Scan / Codacy Security Scan (push) Successful in 22s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 1m56s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m17s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m16s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m29s
All checks were successful
Codacy Scan / Codacy Security Scan (push) Successful in 22s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 1m56s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m17s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m16s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m29s
and tweaked the encode fn a bit
This commit is contained in:
parent
685b8e446e
commit
d764002546
@ -35,33 +35,55 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
EVP_PKEY *keypair = NULL; //KEYPAIR
|
EVP_PKEY *keypair = NULL; //KEYPAIR
|
||||||
|
|
||||||
//LOCAL
|
//LOCAL
|
||||||
char *base64_encode(char *data)
|
char* base64_encode(char *message)
|
||||||
{
|
{
|
||||||
//VARIABLES
|
//VARIABLES
|
||||||
BIO *bio;
|
BIO *bio;
|
||||||
BIO *b64;
|
BIO *b64;
|
||||||
BUF_MEM *buffer_ptr;
|
BUF_MEM *buffer_ptr;
|
||||||
|
char* encoded_message;
|
||||||
|
|
||||||
//CREATE BIO
|
//INIT BIOs
|
||||||
b64 = BIO_new(BIO_f_base64());
|
b64 = BIO_new(BIO_f_base64());
|
||||||
bio = BIO_new(BIO_s_mem());
|
bio = BIO_new(BIO_s_mem());
|
||||||
bio = BIO_push(b64, bio);
|
bio = BIO_push(b64, bio);
|
||||||
|
|
||||||
BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); //NO NEWLINES
|
//ENCODE
|
||||||
BIO_write(bio, data, strlen(data)); //ENCODE
|
BIO_write(bio, message, strlen(message));
|
||||||
BIO_flush(bio);
|
BIO_flush(bio);
|
||||||
|
BIO_get_mem_ptr(bio, &buffer_ptr);
|
||||||
BIO_get_mem_ptr(bio, &buffer_ptr); //GET PTR
|
|
||||||
char *b64text = why2_malloc(buffer_ptr -> length + 1); //ALLOCATE
|
|
||||||
|
|
||||||
//COPY
|
//COPY
|
||||||
memcpy(b64text, buffer_ptr -> data, buffer_ptr -> length);
|
encoded_message = why2_malloc(buffer_ptr -> length + 1);
|
||||||
b64text[buffer_ptr -> length] = '\0'; //NULL-TERM
|
memcpy(encoded_message, buffer_ptr -> data, buffer_ptr -> length);
|
||||||
|
encoded_message[buffer_ptr -> length] = '\0';
|
||||||
|
|
||||||
//DEALLOCATION
|
//DEALLOCATION
|
||||||
BIO_free_all(bio);
|
BIO_free_all(bio);
|
||||||
|
|
||||||
return b64text;
|
return encoded_message;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* base64_decode(char *encoded_message)
|
||||||
|
{
|
||||||
|
//VARIABLES
|
||||||
|
BIO *bio;
|
||||||
|
BIO *b64;
|
||||||
|
size_t length = strlen(encoded_message);
|
||||||
|
char* decoded_message = why2_malloc(length);
|
||||||
|
|
||||||
|
//INIT BIOs
|
||||||
|
b64 = BIO_new(BIO_f_base64());
|
||||||
|
bio = BIO_new_mem_buf(encoded_message, length);
|
||||||
|
bio = BIO_push(b64, bio);
|
||||||
|
|
||||||
|
//NULL-TERM
|
||||||
|
decoded_message[BIO_read(bio, decoded_message, length)] = '\0';
|
||||||
|
|
||||||
|
//DEALLOCATION
|
||||||
|
BIO_free_all(bio);
|
||||||
|
|
||||||
|
return decoded_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
//GLOBAL
|
//GLOBAL
|
||||||
|
Loading…
x
Reference in New Issue
Block a user