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

serialize: salt option is required but the spec says it is optional #22

Open
mattmahn opened this issue Apr 20, 2022 · 2 comments
Open

Comments

@mattmahn
Copy link

mattmahn commented Apr 20, 2022

The specification says that the salt option is optional:

optionally, a $ sign followed by the (encoded) salt value;

However, this package requires it to be defined to output the hash.

Here's an example:

#!/usr/bin/env node
const crypto = require('node:crypto')
const phc = require('@phc/format')

const hbuf = crypto.createHash('sha256').update('asdf').digest()

console.log(phc.serialize({
    id: 'sha256',
    // salt: Buffer.alloc(0),
    hash: hbuf,
}))

I expect this to print $sha256$8OTC92xYkW7CWPJGhRvqCR0U1CR6L8PhhpRGGxgW4Ts, but it only prints $sha256.
I need to specify a salt to get the hash to print. (Also note that un-commenting the salt line will serialize with a zero-length salt, i.e., $sha256$$ prefix.)

@simonepri
Copy link
Owner

My memory might be a little rusty on this, as I wrote it 4y+ ago, but I think it was a concoius decision to limit the API as I didn't forsee the use case you are describing.

I found P-H-C/phc-string-format#3, so I guess I did think about whether to make it optional or not, and I preferred to play it safe I guess.

Feel free to contribute and change this, I'll be happy to review it.

@ephphatha
Copy link

This is intended from what I can see of the phc-sf spec

...the hash output may be present only if the salt is present

For an unsalted function a minimum length of 0 bytes is valid for the salt, which gives the $<id>$$<hash> string observed.

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

No branches or pull requests

3 participants