node-opcua-crypto 5.3.3 → 5.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -627,6 +627,9 @@ function hexy(buffer, { width, format } = {}) {
627
627
  var PEM_REGEX = /^(-----BEGIN (.*)-----\r?\n([/+=a-zA-Z0-9\r\n]*)\r?\n-----END \2-----\r?\n?)/gm;
628
628
  var PEM_TYPE_REGEX = /^(-----BEGIN (.*)-----)/m;
629
629
  function identifyPemType(rawKey) {
630
+ if (Array.isArray(rawKey)) {
631
+ return void 0;
632
+ }
630
633
  if (Buffer.isBuffer(rawKey)) {
631
634
  rawKey = rawKey.toString("utf8");
632
635
  }
@@ -640,22 +643,20 @@ function removeTrailingLF(str) {
640
643
  function toPem(raw_key, pem) {
641
644
  assert2(raw_key, "expecting a key");
642
645
  assert2(typeof pem === "string");
646
+ if (Array.isArray(raw_key)) {
647
+ return raw_key.map((cert) => toPem(cert, pem)).join("\n");
648
+ }
643
649
  let pemType = identifyPemType(raw_key);
644
650
  if (pemType) {
645
651
  return Buffer.isBuffer(raw_key) ? removeTrailingLF(raw_key.toString("utf8")) : removeTrailingLF(raw_key);
646
652
  } else {
647
653
  pemType = pem;
648
654
  assert2(["CERTIFICATE REQUEST", "CERTIFICATE", "RSA PRIVATE KEY", "PUBLIC KEY", "X509 CRL"].indexOf(pemType) >= 0);
649
- let b = raw_key.toString("base64");
650
- let str = `-----BEGIN ${pemType}-----
651
- `;
652
- while (b.length) {
653
- str += `${b.substring(0, 64)}
654
- `;
655
- b = b.substring(64);
656
- }
657
- str += `-----END ${pemType}-----`;
658
- return str;
655
+ const b = raw_key.toString("base64");
656
+ const strBody = b.match(/.{1,64}/g)?.join("\n") || "";
657
+ return `-----BEGIN ${pemType}-----
658
+ ${strBody}
659
+ -----END ${pemType}-----`;
659
660
  }
660
661
  }
661
662
  function convertPEMtoDER(raw_key) {
@@ -6631,4 +6632,4 @@ asn1js/build/index.es.js:
6631
6632
  *
6632
6633
  *)
6633
6634
  */
6634
- //# sourceMappingURL=chunk-MFGOTDMX.js.map
6635
+ //# sourceMappingURL=chunk-P5QLLSP2.js.map