Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

modp_b64_gen.c generates two identical char arrays #51

Open
Getfree opened this issue Oct 6, 2019 · 2 comments
Open

modp_b64_gen.c generates two identical char arrays #51

Getfree opened this issue Oct 6, 2019 · 2 comments

Comments

@Getfree
Copy link

Getfree commented Oct 6, 2019

The following two lines generate two identical char arrays.

char_array_to_c(cary, sizeof(cary), "e1");

char_array_to_c(cary, sizeof(cary), "e2");

One called e1 and the other e2.
I can't figure out what's the use two identical array literals.
They appear to be used only in the function modp_b64_encode which could work well with only one of them.

Is this deliberate?
For what purpose?

@baylesj
Copy link

baylesj commented Oct 20, 2020

char_array_to_c prints the passed in character array as a C program snippet.

If you build the library and open src/modp_b64_data.h you can see what the outputted C program snippets look like:

static const uint8_t e0[256] = {
    'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'C', 'C',
    'C', 'C', 'D', 'D', 'D', 'D', 'E', 'E', 'E', 'E',
    'F', 'F', 'F', 'F', 'G', 'G', 'G', 'G', 'H', 'H',
    'H', 'H', 'I', 'I', 'I', 'I', 'J', 'J', 'J', 'J',
    'K', 'K', 'K', 'K', 'L', 'L', 'L', 'L', 'M', 'M',
    'M', 'M', 'N', 'N', 'N', 'N', 'O', 'O', 'O', 'O',
    'P', 'P', 'P', 'P', 'Q', 'Q', 'Q', 'Q', 'R', 'R',
    'R', 'R', 'S', 'S', 'S', 'S', 'T', 'T', 'T', 'T',
    'U', 'U', 'U', 'U', 'V', 'V', 'V', 'V', 'W', 'W',
    'W', 'W', 'X', 'X', 'X', 'X', 'Y', 'Y', 'Y', 'Y',
    'Z', 'Z', 'Z', 'Z', 'a', 'a', 'a', 'a', 'b', 'b',
    'b', 'b', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'd',
    'e', 'e', 'e', 'e', 'f', 'f', 'f', 'f', 'g', 'g',
    'g', 'g', 'h', 'h', 'h', 'h', 'i', 'i', 'i', 'i',
    'j', 'j', 'j', 'j', 'k', 'k', 'k', 'k', 'l', 'l',
    'l', 'l', 'm', 'm', 'm', 'm', 'n', 'n', 'n', 'n',
    'o', 'o', 'o', 'o', 'p', 'p', 'p', 'p', 'q', 'q',
    'q', 'q', 'r', 'r', 'r', 'r', 's', 's', 's', 's',
    't', 't', 't', 't', 'u', 'u', 'u', 'u', 'v', 'v',
    'v', 'v', 'w', 'w', 'w', 'w', 'x', 'x', 'x', 'x',
    'y', 'y', 'y', 'y', 'z', 'z', 'z', 'z', '0', '0',
    '0', '0', '1', '1', '1', '1', '2', '2', '2', '2',
    '3', '3', '3', '3', '4', '4', '4', '4', '5', '5',
    '5', '5', '6', '6', '6', '6', '7', '7', '7', '7',
    '8', '8', '8', '8', '9', '9', '9', '9', '+', '+',
    '+', '+', '/', '/', '/', '/'
};
...

The outputted arrays are then used in modp_b64.c to do interesting things. It is working as intended.

@Getfree
Copy link
Author

Getfree commented Oct 23, 2020

@baylesj, your comment is not related to my question.

The question is why are there two identical array literals being generated. One named e1 and the other named e2.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants