Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
chardoncs committed Nov 11, 2022
1 parent 7aa2678 commit 56366a2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions include/backend/base-encoding-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ size_t __pgfe_transform_codes(const pgfe_encode_t input[], size_t length, uint8_
size_t
__pgfe_unittostr(PGFE_BASE_PARAMS_DEF, const char alphabet[], const pgfe_encode_t unit[], char out[], bool padding);

size_t __pgfe_encode_generic(
size_t __pgfe_encode_base_generic(
PGFE_BASE_PARAMS_DEF, const char alphabet[], const pgfe_encode_t input[], size_t input_length, char cs_out[]
);

size_t __pgfe_decode_generic(
size_t __pgfe_decode_base_generic(
PGFE_BASE_PARAMS_DEF, pgfe_encode_t (*func)(char), const char basexx_cs[], pgfe_encode_t output[]
);

Expand Down
14 changes: 7 additions & 7 deletions src/c/base_encoding/base-encoding-internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ size_t __pgfe_unittostr(
return chunk_count;
}

size_t __pgfe_encode_generic(
size_t __pgfe_encode_base_generic(
PGFE_BASE_PARAMS_DEF, const char alphabet[], const pgfe_encode_t input[], size_t input_length, char cs_out[]
) {
pgfe_encode_t input_unit[unit_size], *inp = (pgfe_encode_t *)input;
pgfe_encode_t input_unit[unit_size];
const pgfe_encode_t *inp = input;
size_t i, remain;
char *sp = cs_out;

Expand All @@ -101,13 +102,12 @@ size_t __pgfe_encode_generic(
return sp - cs_out;
}

size_t __pgfe_decode_generic(
size_t __pgfe_decode_base_generic(
PGFE_BASE_PARAMS_DEF, pgfe_encode_t (*func)(char), const char basexx_cs[], pgfe_encode_t output[]
) {
pgfe_encode_t *op, ch, sig, o_unit[unit_size];
const size_t sz_ou = to_bit(sizeof(pgfe_encode_t));
char *sp = (char *)basexx_cs;
size_t i = 0, j;
const char *sp = basexx_cs;
size_t i, j;
uint64_t u;
const uint8_t mask = __mkmask(bit_size);

Expand All @@ -132,7 +132,7 @@ size_t __pgfe_decode_generic(
}

for (j = 0; j < unit_size; j++) {
o_unit[j] = (pgfe_encode_t)((u >> (sz_ou * (unit_size - j - 1))) & 0xFF);
o_unit[j] = (pgfe_encode_t)((u >> (__bitsz * (unit_size - j - 1))) & 0xFF);
}

memcpy(op, o_unit, unit_size);
Expand Down
4 changes: 2 additions & 2 deletions src/c/base_encoding/base16.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ inline pgfe_encode_t pgfe_decode_base16_char(char base16_c) {
}

inline size_t pgfe_encode_base16(const pgfe_encode_t input[], size_t input_length, char cs_out[]) {
return __pgfe_encode_generic(PGFE_BASE_PARAMS(BASE16), BASE16_ALPHABET, input, input_length, cs_out);
return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE16), BASE16_ALPHABET, input, input_length, cs_out);
}

size_t pgfe_decode_base16(const char base16_cs[], pgfe_encode_t output[]) {
return __pgfe_decode_generic(PGFE_BASE_PARAMS(BASE16), pgfe_decode_base16_char, base16_cs, output);
return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE16), pgfe_decode_base16_char, base16_cs, output);
}
8 changes: 4 additions & 4 deletions src/c/base_encoding/base32.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ inline pgfe_encode_t pgfe_decode_base32hex_char(char base32_c) {
}

inline size_t pgfe_encode_base32(const pgfe_encode_t input[], size_t input_length, char cs_out[]) {
return __pgfe_encode_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET, input, input_length, cs_out);
return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET, input, input_length, cs_out);
}

inline size_t pgfe_encode_base32hex(const pgfe_encode_t input[], size_t input_length, char cs_out[]) {
return __pgfe_encode_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET_EXTHEX, input, input_length, cs_out);
return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET_EXTHEX, input, input_length, cs_out);
}

inline size_t pgfe_decode_base32(const char base32_cs[], pgfe_encode_t output[]) {
return __pgfe_decode_generic(PGFE_BASE_PARAMS(BASE32), pgfe_decode_base32_char, base32_cs, output);
return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE32), pgfe_decode_base32_char, base32_cs, output);
}

inline size_t pgfe_decode_base32hex(const char base32_cs[], pgfe_encode_t output[]) {
return __pgfe_decode_generic(PGFE_BASE_PARAMS(BASE32), pgfe_decode_base32hex_char, base32_cs, output);
return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE32), pgfe_decode_base32hex_char, base32_cs, output);
}
6 changes: 3 additions & 3 deletions src/c/base_encoding/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ inline pgfe_encode_t pgfe_decode_base64_char(char base64_c) {
}

inline size_t pgfe_encode_base64(const pgfe_encode_t input[], size_t input_length, char cs_out[]) {
return __pgfe_encode_generic(PGFE_BASE_PARAMS(BASE64), BASE64_ALPHABET, input, input_length, cs_out);
return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE64), BASE64_ALPHABET, input, input_length, cs_out);
}

inline size_t pgfe_encode_base64_url(const pgfe_encode_t input[], size_t input_length, char cs_out[]) {
return __pgfe_encode_generic(PGFE_BASE_PARAMS(BASE64), BASE64_ALPHABET_FS, input, input_length, cs_out);
return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE64), BASE64_ALPHABET_FS, input, input_length, cs_out);
}

inline size_t pgfe_decode_base64(const char base64_cs[], pgfe_encode_t output[]) {
return __pgfe_decode_generic(PGFE_BASE_PARAMS(BASE64), pgfe_decode_base64_char, base64_cs, output);
return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE64), pgfe_decode_base64_char, base64_cs, output);
}

0 comments on commit 56366a2

Please sign in to comment.