How to use the @aws-crypto/serialize.deserializeSignature 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
const { kdfGetSubtleDecrypt, subtleVerify, dispose } = await getDecryptionHelper(material)
  const info = kdfInfo(suiteId, messageId)
  const getSubtleDecrypt = kdfGetSubtleDecrypt(info)

  // The tag is appended to the Data
  await getSubtleDecrypt(headerIv, rawHeader)(headerAuthTag) // will throw if invalid

  const { plaintext, readPos } = await bodyDecrypt({ buffer: ciphertext, getSubtleDecrypt, headerInfo })

  dispose()

  if (subtleVerify) {
    const data = ciphertext.slice(0, readPos)
    const signatureInfo = ciphertext.slice(readPos)

    const derSignature = deserializeSignature(signatureInfo)
    const rawSignature = der2raw(derSignature, material.suite)

    const isValid = await subtleVerify(rawSignature, data)
    /* Postcondition: subtleVerify must validate the signature. */
    needs(isValid, 'Invalid Signature')
    return { messageHeader, plaintext }
  } else {
    return { messageHeader, plaintext }
  }
}