Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base-64-URL #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

base-64-URL #5

wants to merge 2 commits into from

Conversation

briancsparks
Copy link

I needed a base64 encoder that was URL safe, and NibbleAndAHalf was by-far the best implementation (simple to understand and fast.) So, I forked and added the proper tables, and APIs.

I am submitting this PR in the hopes that NibbleAndAHalf will provide a URL-safe variant, and superwills can use my changes as a starting point, if deemed worthy. I tried to keep the coding style that superwills uses -- except that my editor insisted on removing whitespace at the end of lines. (Using "git diff -w" will show a diff that ignores those white-space changes.) I made one commit that had only the white-space changes to make it easier to see the substantive changes by themselves.

I do not need any attribution -- if you choose to accept the PR, please remove the comment at the top of base64.h, as it would be very misleading otherwise. (I only added it to adhere to the NibbleAndAHalf terms that said that I should not try to claim the work as my own; I wanted to let users know that they were using my version (and not the real thing) by looking at the source.)

  • Changed table names to make it clear that there were "standard" and "URL safe" variants.
  • Linked to the wikipedia article that talks about the different base-64 encodings.
  • Provided a version of the decode function that takes the table as a parameter. (The same for the encoder.)

@superwills
Copy link
Owner

superwills commented Jul 27, 2017

Great! I'll look at this and will integrate these changes soon.

  • A quick question: In URL-safe encoding, do you have to replace the usage of = with ~ or something URL-safe like that? URL-safe characters

  • I'm thinking I'm going to make the encodingString/decodingArray the 2nd parameter to the base64/unbase64 function pair. So I'm looking at functions:

    char* base64( const void* binaryData, const char* encodingString, int len, int flen );
    char
    unbase64( const void* binaryData, const unsigned char* decodingArray, int len, int *flen );

  • Will also add in some quick error checks that the base64-encoded string is URL-safe / not URL-safe.

  • We can also do an awfully crappy thing and use a single decodingArray with - having the same value as + and _ having the same value as /

@briancsparks
Copy link
Author

  • The convention is that the Base-64 encoder uses = to pad the end, and then it is up to the caller to percent-encode them before transmission. Seems like a strange way to go, but that's what all the server-side decoders expect.

  • Having only one decodingArray would reduce complexity, which I'm always looking to do :).

  • Any reasonable function signature works for me :)

Thank you, now I can point my build scripts back to 'the real thing.'

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

Successfully merging this pull request may close these issues.

2 participants