-
Notifications
You must be signed in to change notification settings - Fork 6
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
Use buffers instead of strings for the public API #5
Comments
I hadn't thought of using binary keys as passphrases, but I can see the value. I'm not sure that saving 32 bytes is worth deviating from Percival's standard file header format. I shall have to give this some thought. |
I am mostly concerned about supporting I consider that a buffer better convey the semantics of the output (it's just an array of bytes) but it is something I can post-process myself when storing it in the database ( |
I've allowed Buffer or any TypeArray as input types for the passphrase, I can't see any downside to that at all, and can see potential value. I realise Percival's standard file header format doesn't mention base64 (as it's purely a file format!), but I think hashed passwords are conventionally handled as strings, for convenience and portability. If you prefer to store in binary, there's not much overhead to do If you would like to review revisions & confirm, I'll release a new version. Thanks for all your contributions. |
Hi, Could you publish the latest version of the package to |
Any plans to do this? Should a new issue to track this be opened? |
Perhaps I could add a third Hence to obtain a Buffer, a call to
If
|
For consistency with const format = options.format !== undefined ? options:format : "base64";
const buffer = Buffer.from(linear);
return format === null ? buffer : buffer.toString(format); |
I agree with @demurgos, |
Earlier work allowed `passphrase` to be a TypedArray. This extends that to allow for `key` to be too. See chrisveness#5
Ok, that makes sense, I'll do a semver major with the key returned as a Buffer. |
New version using Buffers for the key is now available for review before release as 2.0.0. |
Thank you very much for your reactivity @chrisveness. I was able to test the version |
The current API uses strings: the passphrase is expected to be a string and the key is a base64 string.
The passphrase is passed as-is to the core lib. The core lib also accepts buffers so it should be safe to simply update the checks and documentation to use (
string | Buffer
). Requiring strings prevents from using binary keys as passphrases due to encoding-related restrictions (not all buffers are valid UTF-8).The main issue is related to the return type. In the database, it is more efficient to store the hash as
bytes
array. The current function post-processes the output buffer to encode it tobase64
. This requires users to decode the result back to a buffer to handle encoding themselves.I'd argue that it would be more ergonomic to provide a general API returning returning a Buffer and let the user call
.toString("base64")
if needed instead of forcing the encoding. This behavior would also be closer to the behavior of the standard library.This would be a semver major breaking change.
The text was updated successfully, but these errors were encountered: