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

include base64url example #30

Closed
mcmanus opened this issue Nov 20, 2017 · 6 comments · Fixed by #65
Closed

include base64url example #30

mcmanus opened this issue Nov 20, 2017 · 6 comments · Fixed by #65

Comments

@mcmanus
Copy link
Member

mcmanus commented Nov 20, 2017

I've seen an implementation report that confused base64 and base64url; they noted that the examples didn't include one where the distinction was important

@chantra
Copy link

chantra commented Nov 20, 2017

@mcmanus yes, there is also the bit about not having the = sign paddings that caught me at first. During the DOH proxy implementation, I missed the padding part. I have it implemented in

https://github.com/chantra/doh-proxy/blob/master/dohproxy/utils.py

import base64

def doh_b64_encode(s):
    """Base 64 urlsafe encode and remove padding.
    input: bytes
    output: str
    """
    return base64.urlsafe_b64encode(s).decode('utf-8').rstrip('=')

def doh_b64_decode(s):
    """Base 64 urlsafe decode, add padding as needed.
    input: str
    output: bytes
    """
    padding = '=' * (-len(s)%4)
    return base64.urlsafe_b64decode(s + padding)

and I think it is correct :) Would an example implementation in a language be worth adding to the examples? It may be more straightforward to read than examples.

https://docs.python.org/3/library/base64.html#base64.urlsafe_b64encode documentation says:

which substitutes - instead of + and _ instead of / in the standard Base64 alphabet

This may be worth highlighting as what base64url is too.

@paulehoffman
Copy link
Collaborator

This is complicated by the fact that some people want the encoding of responses to GET to be media-type-specific.

@mcmanus
Copy link
Member Author

mcmanus commented Feb 1, 2018

This is complicated by the fact that some people want the encoding of responses to GET to be media-type-specific.

I think you mean GET request body parameters (not responses - which are always in bodies and not encoded)

@paulehoffman
Copy link
Collaborator

Yes, I meant body parameters.

@martinthomson
Copy link
Contributor

Please stop calling the parameter body. It's really confusing. (I just read this and thought to myself "GET doesn't have a body").

@mcmanus
Copy link
Member Author

mcmanus commented Feb 2, 2018

note that the current encoded url in the github copy is wrong as it wasn't updated when the dns id changed to 0. I'll fix that as part of making a base 64 example.

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

Successfully merging a pull request may close this issue.

4 participants