Skip to content

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

Description

@mattmahn

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.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions