UNPKG

557 BJavaScriptView Raw
1module.exports = loadCAFile
2
3var fs = require('fs')
4
5function loadCAFile(cafilePath, cb) {
6 if (!cafilePath)
7 return process.nextTick(cb)
8
9 fs.readFile(cafilePath, 'utf8', afterCARead.bind(this))
10
11 function afterCARead(er, cadata) {
12 if (er)
13 return cb(er)
14
15 var delim = '-----END CERTIFICATE-----'
16 var output
17
18 output = cadata
19 .split(delim)
20 .filter(function(xs) {
21 return !!xs.trim()
22 })
23 .map(function(xs) {
24 return xs.trimLeft() + delim
25 })
26
27 this.set('ca', output)
28 cb(null)
29 }
30
31}