Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 }
}
}