mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 18:50:28 +09:00
base64: Reformat
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com> Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
This commit is contained in:
committed by
Sahana Prasad
parent
8ed9f5e69b
commit
9ddde3803e
26
src/base64.c
26
src/base64.c
@@ -57,11 +57,12 @@ static int get_equals(char *string);
|
||||
* @returns A buffer containing the decoded string, NULL if something went
|
||||
* wrong (e.g. incorrect char).
|
||||
*/
|
||||
ssh_buffer base64_to_bin(const char *source) {
|
||||
ssh_buffer base64_to_bin(const char *source)
|
||||
{
|
||||
ssh_buffer buffer = NULL;
|
||||
unsigned char block[3];
|
||||
char *base64;
|
||||
char *ptr;
|
||||
char *base64 = NULL;
|
||||
char *ptr = NULL;
|
||||
size_t len;
|
||||
int equals;
|
||||
|
||||
@@ -130,7 +131,7 @@ ssh_buffer base64_to_bin(const char *source) {
|
||||
* two "=" padding characters.
|
||||
*/
|
||||
case 2:
|
||||
if (equals != 2){
|
||||
if (equals != 2) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -155,7 +156,7 @@ ssh_buffer base64_to_bin(const char *source) {
|
||||
if (_base64_to_bin(block, ptr, 2) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (ssh_buffer_add_data(buffer,block,2) < 0) {
|
||||
if (ssh_buffer_add_data(buffer, block, 2) < 0) {
|
||||
goto error;
|
||||
}
|
||||
SAFE_FREE(base64);
|
||||
@@ -179,7 +180,8 @@ error:
|
||||
} while(0)
|
||||
|
||||
/* Returns 0 if ok, -1 if not (ie invalid char into the stuff) */
|
||||
static int to_block4(unsigned long *block, const char *source, int num) {
|
||||
static int to_block4(unsigned long *block, const char *source, int num)
|
||||
{
|
||||
const char *ptr = NULL;
|
||||
unsigned int i;
|
||||
|
||||
@@ -189,7 +191,7 @@ static int to_block4(unsigned long *block, const char *source, int num) {
|
||||
}
|
||||
|
||||
BLOCK(A, 0); /* 6 bit */
|
||||
BLOCK(B,1); /* 12 bit */
|
||||
BLOCK(B, 1); /* 12 bit */
|
||||
|
||||
if (num < 2) {
|
||||
return 0;
|
||||
@@ -207,7 +209,8 @@ static int to_block4(unsigned long *block, const char *source, int num) {
|
||||
}
|
||||
|
||||
/* num = numbers of final bytes to be decoded */
|
||||
static int _base64_to_bin(unsigned char dest[3], const char *source, int num) {
|
||||
static int _base64_to_bin(unsigned char dest[3], const char *source, int num)
|
||||
{
|
||||
unsigned long block;
|
||||
|
||||
if (to_block4(&block, source, num) < 0) {
|
||||
@@ -221,11 +224,12 @@ static int _base64_to_bin(unsigned char dest[3], const char *source, int num) {
|
||||
}
|
||||
|
||||
/* Count the number of "=" signs and replace them by zeroes */
|
||||
static int get_equals(char *string) {
|
||||
static int get_equals(char *string)
|
||||
{
|
||||
char *ptr = string;
|
||||
int num = 0;
|
||||
|
||||
while ((ptr=strchr(ptr,'=')) != NULL) {
|
||||
while ((ptr = strchr(ptr, '=')) != NULL) {
|
||||
num++;
|
||||
*ptr = '\0';
|
||||
ptr++;
|
||||
@@ -283,7 +287,7 @@ uint8_t *bin_to_base64(const uint8_t *source, size_t len)
|
||||
}
|
||||
ptr = base64;
|
||||
|
||||
while(len > 0){
|
||||
while (len > 0) {
|
||||
_bin_to_base64(ptr, source, len > 3 ? 3 : len);
|
||||
ptr += 4;
|
||||
if (len < 3) {
|
||||
|
||||
Reference in New Issue
Block a user