How to use the @aws-crypto/serialize.decodeBodyHeader function in @aws-crypto/serialize

To help you get started, we’ve selected a few @aws-crypto/serialize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-encryption-sdk-javascript / modules / decrypt-browser / src / decrypt.ts View on Github external
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 }
}