1// Copyright Joyent, Inc. and other Node contributors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a
4// copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to permit
8// persons to whom the Software is furnished to do so, subject to the
9// following conditions:
10//
11// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22'use strict';
23const common = require('../common');
24
25if (!common.hasCrypto)
26  common.skip('missing crypto');
27
28const assert = require('assert');
29const crypto = require('crypto');
30
31const stream = require('stream');
32const s = new stream.PassThrough();
33const h = crypto.createHash('sha3-512');
34const expect = '36a38a2a35e698974d4e5791a3f05b05' +
35               '198235381e864f91a0e8cd6a26b677ec' +
36               'dcde8e2b069bd7355fabd68abd6fc801' +
37               '19659f25e92f8efc961ee3a7c815c758';
38
39s.pipe(h).on('data', common.mustCall(function(c) {
40  assert.strictEqual(c, expect);
41  // Calling digest() after piping into a stream with SHA3 should not cause
42  // a segmentation fault, see https://github.com/nodejs/node/issues/28245.
43  assert.strictEqual(h.digest('hex'), expect);
44})).setEncoding('hex');
45
46s.end('aoeu');
47