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

UTF-8 codec functions are named the wrong way round #84

Closed
infinity0 opened this issue Nov 13, 2015 · 1 comment
Closed

UTF-8 codec functions are named the wrong way round #84

infinity0 opened this issue Nov 13, 2015 · 1 comment

Comments

@infinity0
Copy link

Hi, in the context of UTF-8, "encode" is generally taken to mean string (of unicode characters, like in JS) -> [byte], and "decode" means [byte] -> string. Every single other API in existence has these semantics.

Even the implementation gives a clue - nacl.util.decodeUTF8 calls unescape(encodeURIComponent(s)), which is the standard JS way to encode a Unicode string into a "UTF-8 string" where each 16-bit character has only 8 semantic bits and the higher 8 bits are not set.

Please deprecate this API and create a new API with correct names, before this turns into a hilariously bad security hole.

@dchest
Copy link
Owner

dchest commented Nov 13, 2015

You're right, the confusion here appeared most likely due to the fact that we're not converting unicode runes, but UTF16 strings, so the meaning of these functions here are decode(fromUTF16into)UTF8 and encodeUTF8(intoUTF16string), so it's a bit different from other languages that have types for Unicode characters.

I intend to completely deprecate and remove util functions in the future (see #44, #38), but it won't be soon. I already recommend against using them in README.

dchest added a commit that referenced this issue Feb 19, 2016
Throw error if old nacl.util functions are used.

nacl.util moved into a separate package:
https://github.com/dchest/tweetnacl-util-js
dchest added a commit that referenced this issue Feb 19, 2016
Throw error if old nacl.util functions are used.

nacl.util moved into a separate package:
https://github.com/dchest/tweetnacl-util-js
dchest added a commit that referenced this issue Feb 19, 2016
Throw error if old nacl.util functions are used.

nacl.util moved into a separate package:
https://github.com/dchest/tweetnacl-util-js
dchest added a commit that referenced this issue Feb 20, 2016
Remove nacl.util. Closes #88, #44, #84.
@dchest dchest closed this as completed Feb 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants