You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
760 B
JavaScript

"use strict";
const withoutKeys = require("../without-keys");
module.exports = function mapEncryptedWrapper(wrapperObject, permitPassthrough = false) {
return {
// TODO: Add a `decrypt` method?
encryptedPayloads: Object.entries(wrapperObject).map(([ keyID, data ]) => {
if (data.passthrough === true) {
if (permitPassthrough) {
return {
keyID: keyID,
isKeyPassthrough: true,
encryptionConfiguration: {}
};
} else {
throw new Error(`Encountered a 'passthrough' encryption object where it is not allowed`);
}
} else {
return {
keyID: keyID,
isKeyPassthrough: false,
ciphertext: data.ciphertext,
encryptionConfiguration: withoutKeys(data, [ "ciphertext" ])
};
}
})
};
};