Skip to content

Hash.prototype._flush does not set state[kFinalized] #38727

Description

@misos1
  • Version: v16.1.0
  • Platform: Darwin Kernel Version 20.4.0
  • Subsystem: crypto

What steps will reproduce the bug?

https://github.com/nodejs/node/blob/master/lib/internal/crypto/hash.js#L90-L93

When using the stream interface of hash it will call this[kHandle].digest() in Hash.prototype._flush. After that it is possible to call Hash.prototype.digest which will call this[kHandle].digest() again. If that is ok then why is Hash.prototype.digest made in a way that it is not possible to call it more than once?

How often does it reproduce? Is there a required condition?

What is the expected behavior?

What do you see instead?

Additional information

Activity

  1. added
    cryptoIssues and PRs related to the crypto subsystem.
    on May 19, 2021
  2. tniessen commented on Apr 2, 2022

    @tniessen
    Member

    I believe this is to enable piping into a Hash object but still being able to call digest() to obtain the hash value instead of reading from the Hash object using the stream API, whereas calling digest() multiple times is usually unnecessary and might indicate a bug.

    Possibly related: #28251

    I am going to close this since there has been no activity in quite a while and I don't think this is really a bug, but please do feel free to reopen or comment if you think this warrants more discussion! :)

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

    cryptoIssues and PRs related to the crypto subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions