You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
The following code will fail on the second call to hash.update:
var hash = require("crypto").createHash('md5')
hash.update(new Buffer(10))
console.log("hash 1 = "+hash.digest('hex'))
hash.update(new Buffer(10))
console.log("hash 2 = "+hash.digest('hex'))
It prints out the following:
hash 1 = 544a69e67a2fccbfc49e6cd6114f7f3e
node.js:116
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: HashUpdate fail
at Object.<anonymous> (/path/to/my/test.js:4:6)
The text was updated successfully, but these errors were encountered:
This is due to .digest() putting the Digest object into an uninitialised state (initialised_ = false), and when an update is called, it returns 0 when checking if it has been initialised. Therefor currently .digest() should be used as a final method call on that object, it should not be used afterward.
To solve this issue or add additional functionality, .digestFinal() can be added which will do the same as digest does now (digest everything and set itself to uninitialised and return the digest). Digest can then be used to only return the digest and still be in an initialised state. The problem with continuing from here is, OpenSSL call to EVP_DigestFinal_ex causes the context to be unusable, so a copy needs to be made before this method call. Copying a digest context on every .digest call in hope that it may be used again might not be the most efficient way to do this, as most uses would just end with digest called once.
The following code will fail on the second call to hash.update:
var hash = require("crypto").createHash('md5')
hash.update(new Buffer(10))
console.log("hash 1 = "+hash.digest('hex'))
hash.update(new Buffer(10))
console.log("hash 2 = "+hash.digest('hex'))
It prints out the following:
hash 1 = 544a69e67a2fccbfc49e6cd6114f7f3e
The text was updated successfully, but these errors were encountered: