File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -122,7 +122,8 @@ Hash.prototype.copy = function copy(options) {
122122} ;
123123
124124Hash . prototype . _transform = function _transform ( chunk , encoding , callback ) {
125- this [ kHandle ] . update ( chunk , encoding ) ;
125+ if ( ! this [ kHandle ] . update ( chunk , encoding ) )
126+ return callback ( new ERR_CRYPTO_HASH_UPDATE_FAILED ( ) ) ;
126127 callback ( ) ;
127128} ;
128129
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ // Flags: --expose-internals
4+
5+ const common = require ( '../common' ) ;
6+ if ( ! common . hasCrypto ) common . skip ( 'missing crypto' ) ;
7+
8+ const assert = require ( 'assert' ) ;
9+ const crypto = require ( 'crypto' ) ;
10+ const { kHandle } = require ( 'internal/crypto/util' ) ;
11+
12+ /**
13+ * This test verifies that the Hash stream properly surfaces an error
14+ * when the underlying native update fails.
15+ */
16+
17+ const h = crypto . createHash ( 'sha256' ) ;
18+
19+ // Simulate native update failure by replacing the internal handle
20+ const fakeHandle = {
21+ update : ( ) => false ,
22+ digest : ( ) => Buffer . from ( '' )
23+ } ;
24+
25+ h [ kHandle ] = fakeHandle ;
26+
27+ h . on ( 'error' , common . mustCall ( ( err ) => {
28+ assert . strictEqual ( err . code , 'ERR_CRYPTO_HASH_UPDATE_FAILED' ) ;
29+ } ) ) ;
30+
31+ h . write ( 'test data' ) ;
32+ h . end ( ) ;
You can’t perform that action at this time.
0 commit comments