Skip to content

Commit 52ed3ad

Browse files
committed
More refactoring
1 parent 2ecde8e commit 52ed3ad

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

lib/mcapi/encryption/field-level-encryption.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function encrypt(endpoint, header, body) {
6565
}
6666
return {
6767
header: header,
68-
body: fleConfig ? computeBody(fleConfig.toEncrypt, body, bodyMap) : body,
68+
body: fleConfig ? utils.computeBody(fleConfig.toEncrypt, body, bodyMap) : body,
6969
};
7070
}
7171

@@ -89,7 +89,7 @@ function decrypt(response) {
8989
}
9090
});
9191
}
92-
return fleConfig ? computeBody(fleConfig.toDecrypt, body, bodyMap) : body;
92+
return fleConfig ? utils.computeBody(fleConfig.toDecrypt, body, bodyMap) : body;
9393
}
9494

9595
/**
@@ -191,12 +191,4 @@ function decryptWithHeader(path, body, response) {
191191
}
192192
}
193193

194-
function computeBody(configParam, body, bodyMap) {
195-
return hasEncryptionParam(configParam, bodyMap) ? bodyMap.pop() : body;
196-
}
197-
198-
function hasEncryptionParam(encParams, bodyMap) {
199-
return encParams && encParams.length === 1 && bodyMap && bodyMap[0];
200-
}
201-
202194
module.exports = FieldLevelEncryption;

lib/mcapi/encryption/jwe-encryption.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function decrypt(response) {
5353
return decryptBody.call(this, v, body);
5454
});
5555
}
56-
return fleConfig ? computeBody(fleConfig.toDecrypt, body, bodyMap) : body;
56+
return fleConfig ? utils.computeBody(fleConfig.toDecrypt, body, bodyMap) : body;
5757
}
5858

5959
/**
@@ -104,12 +104,4 @@ function decryptBody(path, body) {
104104
return body;
105105
}
106106

107-
function computeBody(configParam, body, bodyMap) {
108-
return hasEncryptionParam(configParam, bodyMap) ? bodyMap.pop() : body;
109-
}
110-
111-
function hasEncryptionParam(encParams, bodyMap) {
112-
return encParams && encParams.length === 1 && bodyMap && bodyMap[0];
113-
}
114-
115107
module.exports = JweEncryption;

lib/mcapi/utils/utils.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ module.exports.hasConfig = function(config, endpoint) {
380380
return null;
381381
};
382382

383-
module.exports.elemFromPath = function(path, obj) {
383+
module.exports.elemFromPath = function (path, obj) {
384384
try {
385385
let parent = null;
386386
const paths = path.split(".");
@@ -405,6 +405,15 @@ module.exports.isJsonRoot = function(elem) {
405405

406406
function isJsonRoot(elem){
407407
return elem === "$";
408+
}
409+
410+
module.exports.computeBody = function (configParam, body, bodyMap) {
411+
return hasEncryptionParam(configParam, bodyMap) ? bodyMap.pop() : body;
408412
};
409413

414+
function hasEncryptionParam(encParams, bodyMap) {
415+
return encParams && encParams.length === 1 && bodyMap && bodyMap[0];
416+
}
417+
418+
410419

0 commit comments

Comments
 (0)