8000 Encoders extensions with base64 encode/decode support by TristonianJones · Pull Request #373 · google/cel-go · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Encoders extensions with base64 encode/decode support #373

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

Merged
merged 3 commits into from
Jul 22, 2020

Conversation

TristonianJones
Copy link
Collaborator

Extensions for base64 encoding and decoding strings and, as appropriate, bytes.

@TristonianJones
Copy link
Collaborator Author

Closes #374

ext/README.md Outdated

### Base64.Decode

Decodes a base64-encoded string to an unencoded string value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I'm showing my age - I first read that as "uuencoded", which seemed like an odd choice.

Base64 decodes to arbitrary binary data, so this should be bytes. If it's actually ASCII or UTF8 data, the call can be wrapped with string().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, I'll decode to bytes

ext/README.md Outdated

### Base64.Encode

Encodes a bytes or string input to a base64-encoded string.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify that the string-accepting version converts to utf-8 bytes first. Consider accepting only bytes input and rely composition with explicit bytes() conversion, as this might be less error-prone.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll still provide functions for both string and bytes inputs for simplicity on the encoding side since the composition would suffer from the same issues as the string based overload.

@TristonianJones
Copy link
Collaborator Author

PTAL

Copy link
Contributor
@JimLarson JimLarson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good modulo some doc/comment improvements. While the CEL language gives utf8 the preferred treatment in the library for the standard string-to-bytes and bytes-to-string conversions, it's not necessarily true that the runtime representation of strings will be utf8 in all CEL implementations.

This function will return an error if the UTF-8 string input is not
base64-encoded.

base64.decode(<bytes>) -> <bytes>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify that the bytes are interpreted as a utf8-encoded string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the bytes are just treated as a raw byte sequence with no assumptions of utf-8 encoding.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then how do you interpret the sequence of bytes as characters without assuming the character encoding? What if I give it some base64-encoded text, using utf16 as the text-to-binary encoding? If the Go library decodes a sequence of bytes, it must do it by assuming a text encoding. That's the assumption that must be surfaced.

Encodes a bytes or string input to base64-encoded bytes.

base64.encode(<bytes>) -> <bytes>
base6 8000 4.encode(<string>) -> <bytes>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify the the string is converted to bytes via utf8, then encoded.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

//
// This function will return an error if the UTF-8 string input is not base64-encoded.
//
// base64.decode(<bytes>) -> <bytes>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments from the Readme apply here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@TristonianJones TristonianJones merged commit 56b5762 into google:master Jul 22, 2020
@TristonianJones TristonianJones deleted the ext-encoders branch July 22, 2020 18:22
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
0