mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 23:43:09 +01:00
7f536f2455
PR-URL: https://github.com/nodejs/node/pull/30961 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
33 lines
671 B
JavaScript
33 lines
671 B
JavaScript
'use strict';
|
|
|
|
const {
|
|
ArrayIsArray,
|
|
ObjectCreate,
|
|
} = primordials;
|
|
|
|
// Example:
|
|
// C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\nemailAddress=ry@clouds.org
|
|
function parseCertString(s) {
|
|
const out = ObjectCreate(null);
|
|
for (const part of s.split('\n')) {
|
|
const sepIndex = part.indexOf('=');
|
|
if (sepIndex > 0) {
|
|
const key = part.slice(0, sepIndex);
|
|
const value = part.slice(sepIndex + 1);
|
|
if (key in out) {
|
|
if (!ArrayIsArray(out[key])) {
|
|
out[key] = [out[key]];
|
|
}
|
|
out[key].push(value);
|
|
} else {
|
|
out[key] = value;
|
|
}
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
module.exports = {
|
|
parseCertString
|
|
};
|