Reverted parsePEM from utils to pass.js

This commit is contained in:
Alexander Cerutti
2019-04-30 22:11:08 +02:00
parent 339a8b79d2
commit fb2338e760
2 changed files with 21 additions and 20 deletions

View File

@@ -17,7 +17,7 @@ const FieldsArray = require("./fieldsArray");
const {
assignLength, generateStringFile,
removeHidden, dateToW3CString,
isValidRGB, parsePEM
isValidRGB
} = require("./utils");
const readdir = promisify(fs.readdir);
@@ -218,6 +218,8 @@ class Pass {
// No model available at this path - renaming the error
throw new Error(formatMessage("MODEL_NOT_FOUND", this.model));
}
throw new Error(err);
}
}
@@ -769,6 +771,23 @@ function readCertificates(certificates) {
});
}
/**
* Parses the PEM-formatted passed text (certificates)
*
* @function parsePEM
* @params {String} element - Text content of .pem files
* @params {String=} passphrase - passphrase for the key
* @returns {Object} The parsed certificate or key in node forge format
*/
function parsePEM(pemName, element, passphrase) {
if (pemName === "signerKey" && passphrase) {
return forge.pki.decryptRsaPrivateKey(element, String(passphrase));
} else {
return forge.pki.certificateFromPem(element);
}
}
/**
* Automatically generates barcodes for all the types given common info
*

View File

@@ -1,23 +1,6 @@
const moment = require("moment");
const { EOL } = require("os");
/**
* Parses the PEM-formatted passed text (certificates)
*
* @function parsePEM
* @params {String} element - Text content of .pem files
* @params {String=} passphrase - passphrase for the key
* @returns {Object} The parsed certificate or key in node forge format
*/
function parsePEM(pemName, element, passphrase) {
if (pemName === "signerKey" && passphrase) {
return forge.pki.decryptRsaPrivateKey(element, String(passphrase));
} else {
return forge.pki.certificateFromPem(element);
}
}
/**
* Checks if an rgb value is compliant with CSS-like syntax
*
@@ -114,6 +97,5 @@ module.exports = {
generateStringFile,
removeHidden,
dateToW3CString,
isValidRGB,
parsePEM
isValidRGB
};