Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const _unwrapKey = async (material: NodeDecryptionMaterial, edk: EncryptedDataKey) => {
/* Precondition: Private key must be defined to support decrypt. */
if (!privateKey) throw new Error('No private key defined in constructor. Decrypt disabled.')
const trace: KeyringTrace = {
keyName: this.keyName,
keyNamespace: this.keyNamespace,
flags: KeyringTraceFlag.WRAPPING_KEY_DECRYPTED_DATA_KEY
}
const { buffer, byteOffset, byteLength } = edk.encryptedDataKey
const encryptedDataKey = Buffer.from(buffer, byteOffset, byteLength)
const unencryptedDataKey = privateDecrypt(
{ key: privateKey, padding },
encryptedDataKey)
return material.setUnencryptedDataKey(unencryptedDataKey, trace)
}