1 'use strict'; 2 3 const { 4 ArrayIsArray, 5 ObjectCreate, 6 } = primordials; 7 8 // Example: 9 // C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\nemailAddress=ry@clouds.org 10 function parseCertString(s) { 11 const out = ObjectCreate(null); 12 for (const part of s.split('\n')) { 13 const sepIndex = part.indexOf('='); 14 if (sepIndex > 0) { 15 const key = part.slice(0, sepIndex); 16 const value = part.slice(sepIndex + 1); 17 if (key in out) { 18 if (!ArrayIsArray(out[key])) { 19 out[key] = [out[key]]; 20 } 21 out[key].push(value); 22 } else { 23 out[key] = value; 24 } 25 } 26 } 27 return out; 28 } 29 30 module.exports = { 31 parseCertString 32 }; 33