in modules/decrypt-node/src/verify_stream.ts [58:114]
constructor({ maxBodySize }: VerifyStreamOptions) {
super()
/* Precondition: VerifyStream requires maxBodySize must be falsey or a number. */
needs(
!maxBodySize || typeof maxBodySize === 'number',
'Unsupported MaxBodySize.'
)
Object.defineProperty(this, '_maxBodySize', {
value: maxBodySize,
enumerable: true,
})
this.on('pipe', (source: ParseHeaderStream) => {
/* Precondition: The source must a ParseHeaderStream emit the required events. */
needs(source instanceof ParseHeaderStream, 'Unsupported source')
source.once('VerifyInfo', (verifyInfo: VerifyInfo) => {
const { getDecipher, verify, headerInfo, dispose } = verifyInfo
const { messageId, contentType } = headerInfo.messageHeader
/* If I have a verify, the header needs to be flushed through.
* I do it here for initialize the verifier before I even
* add the element to the object.
*/
if (verify) {
const { rawHeader, headerAuth, messageHeader } = headerInfo
const { headerIv, headerAuthTag } = headerAuth
verify.update(<Buffer>rawHeader)
verify.update(
<Buffer>serializeMessageHeaderAuth({
headerIv,
headerAuthTag,
messageHeader,
})
)
}
Object.defineProperty(this, '_headerInfo', {
value: headerInfo,
enumerable: true,
})
Object.defineProperty(this, '_verify', {
value: verify,
enumerable: true,
})
const decipherInfo: DecipherInfo = {
messageId: Buffer.from(
(messageId as Uint8Array).buffer || messageId,
(messageId as Uint8Array).byteOffset || 0,
messageId.byteLength
),
contentType,
getDecipher,
dispose,
}
this.emit('DecipherInfo', decipherInfo)
})
})
}