Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function framedDecrypt ({ buffer, getSubtleDecrypt, headerInfo, readPos }: FramedDecryptOptions) {
const { messageHeader: { messageId } } = headerInfo
const frameInfo = decodeBodyHeader(buffer, headerInfo, readPos)
if (!frameInfo) throw new Error('Format Error')
const cipherLength = frameInfo.contentLength + frameInfo.tagLength / 8
const contentString = messageAADContentString(frameInfo)
const messageAdditionalData = messageAAD(messageId, contentString, frameInfo.sequenceNumber, frameInfo.contentLength)
const cipherBlob = buffer.slice(frameInfo.readPos, frameInfo.readPos + cipherLength)
const clearBlob = await getSubtleDecrypt(frameInfo.iv, messageAdditionalData)(cipherBlob)
frameInfo.readPos += cipherLength
return { clearBlob, frameInfo }
}