From 1b4da6d9a01900d9d27866be82bb14ae89fd5b2b Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 17 Jun 2014 20:03:47 -0600 Subject: [PATCH] save pems by name --- ca-store-generator.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/ca-store-generator.js b/ca-store-generator.js index 9f854f4..86f8e93 100644 --- a/ca-store-generator.js +++ b/ca-store-generator.js @@ -34,10 +34,13 @@ Certificate.prototype.quasiPEM = function quasiPEM() { converted.writeUInt8(parseInt(bytes.shift(), 8), offset++); } - return ' // ' + this.name + '\n' + - ' "-----BEGIN CERTIFICATE-----\\n" +\n' + - converted.toString('base64').replace(/(.{1,76})/g, ' "$1\\n" +\n') + - ' "-----END CERTIFICATE-----\\n"'; + return { + name: this.name + , value: ' // ' + this.name + '\n' + + ' "-----BEGIN CERTIFICATE-----\\n" +\n' + + converted.toString('base64').replace(/(.{1,76})/g, ' "$1\\n" +\n') + + ' "-----END CERTIFICATE-----\\n"' + }; }; function parseBody(current, lines) { @@ -113,8 +116,12 @@ function parseCertData(lines) { function dumpCerts(certs, filename, pemsDir) { certs.forEach(function (cert, i) { - var pemsFile = path.join(pemsDir, 'ca-' + i + '.pem'); - fs.writeFileSync(pemsFile, cert.quasiPEM()); + var pem = cert.quasiPEM() + , pemName = pem.name.toLowerCase().replace(/\W/, '-').replace(/-+/, '-') + , pemsFile = path.join(pemsDir, pemName + '.pem') + ; + + fs.writeFileSync(pemsFile, pem.value); }); console.info("Wrote " + certs.length + " certificates in '" + path.join(__dirname, 'pems/').replace(/'/g, "\\'") + "'."); @@ -123,7 +130,7 @@ function dumpCerts(certs, filename, pemsDir) { filename , HEADER + 'var cas = module.exports = [\n' - + certs.map(function (cert) { return cert.quasiPEM(); }).join(',\n\n') + + certs.map(function (cert) { return cert.quasiPEM().value; }).join(',\n\n') + '\n];\n' + "module.exports.rootCas = cas;\n" + "module.exports.inject = function () {\n"