All files / lib/internal/tls parse-cert-string.js

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

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 368x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 2308x 2308x 2308x 15311x 15311x 15308x 15308x 15308x 15x 15x 15x 15x 15308x 15293x 15293x 15308x 2308x 2308x 2308x 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;
}
 
exports.parseCertString = parseCertString;