All files / lib/internal tls.js

100% Statements 37/37
100% Branches 6/6
100% Functions 1/1
100% Lines 37/37

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 388x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 2296x 2296x 2296x 15251x 15251x 15248x 15248x 15248x 15x 15x 15x 15x 15248x 15233x 15233x 15248x 2296x 2296x 2296x 8x 8x 8x 8x  
'use strict';
 
const {
  ArrayIsArray,
  ArrayPrototypeForEach,
  ArrayPrototypePush,
  StringPrototypeIndexOf,
  StringPrototypeSlice,
  StringPrototypeSplit,
  ObjectCreate,
} = primordials;
 
// Example:
// C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\[email protected]
function parseCertString(s) {
  const out = ObjectCreate(null);
  ArrayPrototypeForEach(StringPrototypeSplit(s, '\n'), (part) => {
    const sepIndex = StringPrototypeIndexOf(part, '=');
    if (sepIndex > 0) {
      const key = StringPrototypeSlice(part, 0, sepIndex);
      const value = StringPrototypeSlice(part, sepIndex + 1);
      if (key in out) {
        if (!ArrayIsArray(out[key])) {
          out[key] = [out[key]];
        }
        ArrayPrototypePush(out[key], value);
      } else {
        out[key] = value;
      }
    }
  });
  return out;
}
 
module.exports = {
  parseCertString
};