This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto: bring module into modern age
Introduce 'buffer' encoding, allow returning and giving buffers as arguments of 'crypto' routines. Fix #3278
- Loading branch information
Showing
6 changed files
with
173 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
63ff449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make the default be 'buffer' instead of 'binary' if no encoding is given and the argument is a Buffer?
63ff449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mscdex I think it might break backward compatibility.
63ff449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine.... this is in 0.9/master already because it's an API change :-)
63ff449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
I was under the impression that this "buffer encoding" was going to be internal, and not exposed in the docs. Returning a
Buffer
instance should be the default, just like all the other Node core APIs IMO.63ff449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TooTallNate @mscdex:
All crypto is stable
This doesn't mean that we can change stable API between major releases, or I'm wrong?
By changing default behaviour you break lot of modules. (need investigation)
Note that there is more features required from crypto e.g. streams.
One posibility is entirely new module (something like
crypto.2
) which will respect all the new goods.63ff449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO if "stable" here means that this particular change cannot be made, then I think it was a mistake to label it as "stable", especially when Buffer support wasn't even added until just now (which is crazy).
Also as @TooTallNate mentioned, it's better to have Buffer as a default encoding to more closely match encoding behavior elsewhere in node. The less gotchas the better.
63ff449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mscdex Absolutely agree, but...
Buffer
as implicit, deprecate other encodings in crypto module.but step two must come some time later, giving maintainers of packages a chance to update
63ff449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As much as I agree that the 'binary' encoding is not very efficient/elegant/whatever, it's very nice to have available because you can use native string functions to find bytes, perform manipulations, etc.
IMHO since Buffer does not have these same kinds of methods available (unless core members would be willing to merge in something like node-buffertools), we should not remove 'binary' encoding support.
Also, I'm not so sure that deprecating additional/other encodings in crypto is a good idea (making a Buffer the only allowed input/output?). Especially if we're really talking about just crypto, since that would introduce more gotchas if encodings can be used in similar situations elsewhere in node.
63ff449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@richardhoffman that's like telling people to just convert binary string results back to a Buffer when using crypto functions. Sure you can do that, but why would you want to do it?
63ff449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mscdex Where input or output has no encoding by nature - just bytes - there shouldn't be string input or output.
Speaking in C++ types,
void *
andchar *
are different. No reason toreinterpret_cast
them in javascript.Node
Buffer
is not part of standart nor V8, that means pull requests can be accepted if reasonable.If you want text, you can get if from buffer by
Buffer#toString(encoding, start, end)
and you should choose proper one or'hex'
63ff449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to @mscdex and @TooTallNate : it's better to have Buffer as a default encoding to more closely match encoding behavior elsewhere in node.
63ff449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, here's a plan. @indutny et al, please let me know if you think this is sane:
binary
remains the default, and we addbuffer
, noting that it is kludgey and weird.2: Unstable
. Add a paragraph in the docs noting that thebinary
encoding will cease to be the default in a future version.buffer
the default, and bump the stability back up to3: Stable
.63ff449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
63ff449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@isaacs SGTM too