node/deps/npm/lib/config/load-cafile.js

31 lines
556 B
JavaScript
Raw Normal View History

2014-08-01 00:05:30 +08:00
module.exports = loadCAFile
2014-11-05 07:08:12 +08:00
var fs = require("fs")
2014-08-01 00:05:30 +08:00
function loadCAFile(cafilePath, cb) {
if (!cafilePath)
return process.nextTick(cb)
2014-11-05 07:08:12 +08:00
fs.readFile(cafilePath, "utf8", afterCARead.bind(this))
2014-08-01 00:05:30 +08:00
function afterCARead(er, cadata) {
if (er)
return cb(er)
2014-11-05 07:08:12 +08:00
var delim = "-----END CERTIFICATE-----"
2014-08-01 00:05:30 +08:00
var output
output = cadata
.split(delim)
.filter(function(xs) {
return !!xs.trim()
})
.map(function(xs) {
return xs.trimLeft() + delim
})
2014-11-05 07:08:12 +08:00
this.set("ca", output)
2014-08-01 00:05:30 +08:00
cb(null)
}
}