2017-09-08 09:58:54 +02:00
|
|
|
'use strict';
|
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
const {
|
2019-11-23 10:09:05 +01:00
|
|
|
ArrayIsArray,
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectCreate,
|
|
|
|
} = primordials;
|
2019-04-09 09:55:53 +02:00
|
|
|
|
2017-09-08 09:58:54 +02:00
|
|
|
// Example:
|
|
|
|
// C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\nemailAddress=ry@clouds.org
|
|
|
|
function parseCertString(s) {
|
2019-11-22 18:04:46 +01:00
|
|
|
const out = ObjectCreate(null);
|
2019-12-14 16:30:40 +01:00
|
|
|
for (const part of s.split('\n')) {
|
|
|
|
const sepIndex = part.indexOf('=');
|
2017-09-08 09:58:54 +02:00
|
|
|
if (sepIndex > 0) {
|
2019-12-14 16:30:40 +01:00
|
|
|
const key = part.slice(0, sepIndex);
|
|
|
|
const value = part.slice(sepIndex + 1);
|
2017-09-08 09:58:54 +02:00
|
|
|
if (key in out) {
|
2019-11-23 10:09:05 +01:00
|
|
|
if (!ArrayIsArray(out[key])) {
|
2017-09-08 09:58:54 +02:00
|
|
|
out[key] = [out[key]];
|
|
|
|
}
|
|
|
|
out[key].push(value);
|
|
|
|
} else {
|
|
|
|
out[key] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
parseCertString
|
|
|
|
};
|