node-opcua-crypto 5.3.3 → 5.3.5

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.
@@ -620,6 +620,9 @@ function hexy(buffer, { width, format } = {}) {
620
620
  var PEM_REGEX = /^(-----BEGIN (.*)-----\r?\n([/+=a-zA-Z0-9\r\n]*)\r?\n-----END \2-----\r?\n?)/gm;
621
621
  var PEM_TYPE_REGEX = /^(-----BEGIN (.*)-----)/m;
622
622
  function identifyPemType(rawKey) {
623
+ if (Array.isArray(rawKey)) {
624
+ return void 0;
625
+ }
623
626
  if (Buffer.isBuffer(rawKey)) {
624
627
  rawKey = rawKey.toString("utf8");
625
628
  }
@@ -633,22 +636,30 @@ function removeTrailingLF(str) {
633
636
  function toPem(raw_key, pem) {
634
637
  _assert2.default.call(void 0, raw_key, "expecting a key");
635
638
  _assert2.default.call(void 0, typeof pem === "string");
639
+ if (Array.isArray(raw_key)) {
640
+ return raw_key.map((cert) => toPem(cert, pem)).join("\n");
641
+ }
636
642
  let pemType = identifyPemType(raw_key);
637
643
  if (pemType) {
638
644
  return Buffer.isBuffer(raw_key) ? removeTrailingLF(raw_key.toString("utf8")) : removeTrailingLF(raw_key);
639
645
  } else {
640
646
  pemType = pem;
641
647
  _assert2.default.call(void 0, ["CERTIFICATE REQUEST", "CERTIFICATE", "RSA PRIVATE KEY", "PUBLIC KEY", "X509 CRL"].indexOf(pemType) >= 0);
642
- let b = raw_key.toString("base64");
643
- let str = `-----BEGIN ${pemType}-----
644
- `;
645
- while (b.length) {
646
- str += `${b.substring(0, 64)}
647
- `;
648
- b = b.substring(64);
648
+ const buffer = raw_key;
649
+ if (pemType === "CERTIFICATE" && buffer.length > 0) {
650
+ try {
651
+ const parts = split_der(buffer);
652
+ if (parts.length > 1) {
653
+ return parts.map((cert) => toPem(cert, pem)).join("\n");
654
+ }
655
+ } catch (err) {
656
+ }
649
657
  }
650
- str += `-----END ${pemType}-----`;
651
- return str;
658
+ const b = buffer.toString("base64");
659
+ const strBody = _optionalChain([b, 'access', _9 => _9.match, 'call', _10 => _10(/.{1,64}/g), 'optionalAccess', _11 => _11.join, 'call', _12 => _12("\n")]) || "";
660
+ return `-----BEGIN ${pemType}-----
661
+ ${strBody}
662
+ -----END ${pemType}-----`;
652
663
  }
653
664
  }
654
665
  function convertPEMtoDER(raw_key) {
@@ -1342,7 +1353,7 @@ async function verifyCertificateChain(certificateChain) {
1342
1353
  const cert = certificateChain[index - 1];
1343
1354
  const certParent = certificateChain[index];
1344
1355
  const certParentInfo = exploreCertificate(certParent);
1345
- const keyUsage = _optionalChain([certParentInfo, 'access', _9 => _9.tbsCertificate, 'access', _10 => _10.extensions, 'optionalAccess', _11 => _11.keyUsage]);
1356
+ const keyUsage = _optionalChain([certParentInfo, 'access', _13 => _13.tbsCertificate, 'access', _14 => _14.extensions, 'optionalAccess', _15 => _15.keyUsage]);
1346
1357
  if (!keyUsage || !keyUsage.keyCertSign) {
1347
1358
  return {
1348
1359
  status: "BadCertificateIssuerUseNotAllowed",
@@ -1749,7 +1760,7 @@ var _crypto;
1749
1760
  var ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;
1750
1761
  if (typeof window === "undefined") {
1751
1762
  _crypto = _crypto3.default;
1752
- if (!_optionalChain([_crypto, 'optionalAccess', _12 => _12.subtle]) || ignoreCrypto) {
1763
+ if (!_optionalChain([_crypto, 'optionalAccess', _16 => _16.subtle]) || ignoreCrypto) {
1753
1764
  _crypto = new (0, _webcrypto.Crypto)();
1754
1765
  doDebug3 && console.warn("using @peculiar/webcrypto");
1755
1766
  } else {
@@ -6267,7 +6278,7 @@ async function createSelfSignedCertificate({
6267
6278
  function rsaLengthPrivateKey(key) {
6268
6279
  const keyPem = typeof key.hidden === "string" ? key.hidden : key.hidden.export({ type: "pkcs1", format: "pem" }).toString();
6269
6280
  const keyObject = _crypto2.createPrivateKey.call(void 0, keyPem);
6270
- const modulusLength = _optionalChain([keyObject, 'access', _13 => _13.asymmetricKeyDetails, 'optionalAccess', _14 => _14.modulusLength]);
6281
+ const modulusLength = _optionalChain([keyObject, 'access', _17 => _17.asymmetricKeyDetails, 'optionalAccess', _18 => _18.modulusLength]);
6271
6282
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from private key");
6272
6283
  return modulusLength / 8;
6273
6284
  }
@@ -6310,7 +6321,7 @@ function rsaLengthPublicKey(key) {
6310
6321
  key = coercePublicKeyPem(key);
6311
6322
  _assert2.default.call(void 0, typeof key === "string");
6312
6323
  const keyObject = _crypto2.createPublicKey.call(void 0, key);
6313
- const modulusLength = _optionalChain([keyObject, 'access', _15 => _15.asymmetricKeyDetails, 'optionalAccess', _16 => _16.modulusLength]);
6324
+ const modulusLength = _optionalChain([keyObject, 'access', _19 => _19.asymmetricKeyDetails, 'optionalAccess', _20 => _20.modulusLength]);
6314
6325
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from public key");
6315
6326
  return modulusLength / 8;
6316
6327
  }
@@ -6318,7 +6329,7 @@ function rsaLengthRsaPublicKey(key) {
6318
6329
  key = coerceRsaPublicKeyPem(key);
6319
6330
  _assert2.default.call(void 0, typeof key === "string");
6320
6331
  const keyObject = _crypto2.createPublicKey.call(void 0, key);
6321
- const modulusLength = _optionalChain([keyObject, 'access', _17 => _17.asymmetricKeyDetails, 'optionalAccess', _18 => _18.modulusLength]);
6332
+ const modulusLength = _optionalChain([keyObject, 'access', _21 => _21.asymmetricKeyDetails, 'optionalAccess', _22 => _22.modulusLength]);
6322
6333
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from public key");
6323
6334
  return modulusLength / 8;
6324
6335
  }
@@ -6623,4 +6634,4 @@ asn1js/build/index.es.js:
6623
6634
  *
6624
6635
  *)
6625
6636
  */
6626
- //# sourceMappingURL=chunk-R6I4NJSZ.cjs.map
6637
+ //# sourceMappingURL=chunk-LRB5Q533.cjs.map