import { NodeDefaultCryptographicMaterialsManager , KeyringNode , NodeMaterialsManager , } from '@aws-crypto/material-management-node' ; import { ParseHeaderStream } from './parse_header_stream' ; import { VerifyStream } from './verify_stream' ; import { getDecipherStream } from './decipher_stream' ; import { DecryptParameters , DecryptStreamOptions } from './types' ; import Duplexify from 'duplexify' ; import { Duplex } from 'stream' ; import { pipeline , PassThrough } from 'readable-stream' ; export function _decryptStream ( decryptParameters , cmm , { maxBodySize } = { } ) { cmm = cmm instanceof KeyringNode ? new NodeDefaultCryptographicMaterialsManager ( cmm ) : cmm ; const parseHeaderStream = new ParseHeaderStream ( decryptParameters . signaturePolicy , decryptParameters . clientOptions , cmm ) ; const verifyStream = new VerifyStream ( { maxBodySize } ) ; const decipherStream = getDecipherStream ( ) ; const stream = new Duplexify ( parseHeaderStream , decipherStream ) ; pipeline ( parseHeaderStream , verifyStream , decipherStream , new PassThrough ( ) , ( err ) => { if ( err ) stream . emit ( 'error' , err ) ; } ) ; parseHeaderStream . once ( 'MessageHeader' , ( header ) => stream . emit ( 'MessageHeader' , header ) ) ; return stream ; }