Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getEncryptionInfo (material : NodeEncryptionMaterial, frameLength: number) {
const { kdfGetCipher } = getEncryptHelper(material)
const { encryptionContext } = material
const messageId = randomBytes(MESSAGE_ID_LENGTH)
const { id, ivLength } = material.suite
const messageHeader: MessageHeader = Object.freeze({
version: SerializationVersion.V1,
type: ObjectType.CUSTOMER_AE_DATA,
suiteId: id,
messageId,
encryptionContext,
encryptedDataKeys: Object.freeze(material.encryptedDataKeys), // freeze me please
contentType: ContentType.FRAMED_DATA,
headerIvLength: ivLength,
frameLength
})
const { buffer, byteOffset, byteLength } = serializeMessageHeader(messageHeader)
const headerBuffer = Buffer.from(buffer, byteOffset, byteLength)
const info = kdfInfo(messageHeader.suiteId, messageHeader.messageId)
const getCipher = kdfGetCipher(info)
const headerIv = headerAuthIv(ivLength)
const validateHeader = getCipher(headerIv)
const encryptionRequest: WebCryptoEncryptionRequest = {
suite,
encryptionContext,
plaintextLength
}
const material = await cmm.getEncryptionMaterials(encryptionRequest)
const { kdfGetSubtleEncrypt, subtleSign, dispose } = await getEncryptHelper(material)
const messageId = await backend.randomValues(MESSAGE_ID_LENGTH)
const { id, ivLength } = material.suite
const messageHeader: MessageHeader = {
version: SerializationVersion.V1,
type: ObjectType.CUSTOMER_AE_DATA,
suiteId: id,
messageId,
encryptionContext: material.encryptionContext,
encryptedDataKeys: material.encryptedDataKeys,
contentType: ContentType.FRAMED_DATA,
headerIvLength: ivLength,
frameLength
}
const header = serialize.serializeMessageHeader(messageHeader)
const info = kdfInfo(id, messageId)
const getSubtleEncrypt = kdfGetSubtleEncrypt(info)
const headerAuthIv = serialize.headerAuthIv(ivLength)
const headerAuthTag = await getSubtleEncrypt(headerAuthIv, header)(new Uint8Array(0))