GeezerVison is showing github.com — Use urlsafe variant of base64 · Issue #463 · googleapis/google-cloud-node
Use urlsafe variant of base64 #463DescriptionFor a historical reason, all the other samples and client libraries are using the url safe variant of base64 encode/decode.
Is it possible to use the url safe variant? Activitystephenplusplus commented on Mar 26, 2015 Definitely, if it's important to do that for the API. Do you have any API documentation that I can look at that advises to use url-safe?
A quick search turned up https://github.com/RGBboy/urlsafe-base64 if we decide to implement. ryanseys commented on Mar 26, 2015 Some APIs expect base64url (like Task Queues or GMail). The example for pubsub here specifically shows an example using base64 (not url variant) being encoded so that's strange. I'd hope that the url variant would still work. That being said, having a utils#base64urlencode and utils#base64decode used across the library would be great to consolidate this functionality across all libraries, regardless of what variant we use. tmatsuo commented on Mar 26, 2015 ContributorAuthor More actions
Do you have any API documentation that I can look at that advises to use url-safe?
It's Python, but the implementation is simple (uses '-' instead of '+' and '_' instead of '/'.):
def b64encode(s, altchars=None):
"""Encode a string using Base64.
s is the string to encode. Optional altchars must be a string of at least
length 2 (additional characters are ignored) which specifies an
alternative alphabet for the '+' and '/' characters. This allows an
application to e.g. generate url or filesystem safe Base64 strings.
The encoded string is returned.
"""
# Strip off the trailing newline
encoded = binascii.b2a_base64(s)[:-1]
if altchars is not None:
return _translate(encoded, {'+': altchars[0], '/': altchars[1]})
return encoded
def urlsafe_b64encode(s):
"""Encode a string using a url-safe Base64 alphabet.
s is the string to encode. The encoded string is returned. The alphabet
uses '-' instead of '+' and '_' instead of '/'.
"""
return b64encode(s, '-_')
The example for pubsub here specifically shows an example using base64 (not url variant) being encoded so that's strange.
Which part is showing it?
Java library (pubsubMessage.encodeData) uses the urlsafe variant under the cover, Python uses base64.urlsafe_b64encode. ryanseys commented on Mar 26, 2015 The = are removed in the url variant as well ryanseys commented on Mar 26, 2015 so the data field of the example has = leading me to believe it's not the url variant tmatsuo commented on Mar 26, 2015 ContributorAuthor More actions Aha, I found there is a discrepancy between the Java implementation and the Python implementation.
Only the Python implementation adds the padding at the end, and I used the value from the Python's base64.urlsafe_b64encode for that protocol example.
Then I would say, yes, please use the one that @stephenplusplus mentioned. ryanseys commented on Mar 26, 2015 Oh! it's padding, cool! I didn't know that. :) tmatsuo commented on Apr 22, 2015 ContributorAuthor More actions It turned out that, we should just use the standard Base64 variant, so I'm just going to close this bug. I'm very sorry if you've already worked on this. Please ask me for more details if you're interested in. stephenplusplus commented on Apr 22, 2015 No problem, thanks for the update!
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|