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.
@@ -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,20 @@ 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);
649
- }
650
- str += `-----END ${pemType}-----`;
651
- return str;
648
+ const b = raw_key.toString("base64");
649
+ const strBody = _optionalChain([b, 'access', _9 => _9.match, 'call', _10 => _10(/.{1,64}/g), 'optionalAccess', _11 => _11.join, 'call', _12 => _12("\n")]) || "";
650
+ return `-----BEGIN ${pemType}-----
651
+ ${strBody}
652
+ -----END ${pemType}-----`;
652
653
  }
653
654
  }
654
655
  function convertPEMtoDER(raw_key) {
@@ -1342,7 +1343,7 @@ async function verifyCertificateChain(certificateChain) {
1342
1343
  const cert = certificateChain[index - 1];
1343
1344
  const certParent = certificateChain[index];
1344
1345
  const certParentInfo = exploreCertificate(certParent);
1345
- const keyUsage = _optionalChain([certParentInfo, 'access', _9 => _9.tbsCertificate, 'access', _10 => _10.extensions, 'optionalAccess', _11 => _11.keyUsage]);
1346
+ const keyUsage = _optionalChain([certParentInfo, 'access', _13 => _13.tbsCertificate, 'access', _14 => _14.extensions, 'optionalAccess', _15 => _15.keyUsage]);
1346
1347
  if (!keyUsage || !keyUsage.keyCertSign) {
1347
1348
  return {
1348
1349
  status: "BadCertificateIssuerUseNotAllowed",
@@ -1749,7 +1750,7 @@ var _crypto;
1749
1750
  var ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;
1750
1751
  if (typeof window === "undefined") {
1751
1752
  _crypto = _crypto3.default;
1752
- if (!_optionalChain([_crypto, 'optionalAccess', _12 => _12.subtle]) || ignoreCrypto) {
1753
+ if (!_optionalChain([_crypto, 'optionalAccess', _16 => _16.subtle]) || ignoreCrypto) {
1753
1754
  _crypto = new (0, _webcrypto.Crypto)();
1754
1755
  doDebug3 && console.warn("using @peculiar/webcrypto");
1755
1756
  } else {
@@ -6267,7 +6268,7 @@ async function createSelfSignedCertificate({
6267
6268
  function rsaLengthPrivateKey(key) {
6268
6269
  const keyPem = typeof key.hidden === "string" ? key.hidden : key.hidden.export({ type: "pkcs1", format: "pem" }).toString();
6269
6270
  const keyObject = _crypto2.createPrivateKey.call(void 0, keyPem);
6270
- const modulusLength = _optionalChain([keyObject, 'access', _13 => _13.asymmetricKeyDetails, 'optionalAccess', _14 => _14.modulusLength]);
6271
+ const modulusLength = _optionalChain([keyObject, 'access', _17 => _17.asymmetricKeyDetails, 'optionalAccess', _18 => _18.modulusLength]);
6271
6272
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from private key");
6272
6273
  return modulusLength / 8;
6273
6274
  }
@@ -6310,7 +6311,7 @@ function rsaLengthPublicKey(key) {
6310
6311
  key = coercePublicKeyPem(key);
6311
6312
  _assert2.default.call(void 0, typeof key === "string");
6312
6313
  const keyObject = _crypto2.createPublicKey.call(void 0, key);
6313
- const modulusLength = _optionalChain([keyObject, 'access', _15 => _15.asymmetricKeyDetails, 'optionalAccess', _16 => _16.modulusLength]);
6314
+ const modulusLength = _optionalChain([keyObject, 'access', _19 => _19.asymmetricKeyDetails, 'optionalAccess', _20 => _20.modulusLength]);
6314
6315
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from public key");
6315
6316
  return modulusLength / 8;
6316
6317
  }
@@ -6318,7 +6319,7 @@ function rsaLengthRsaPublicKey(key) {
6318
6319
  key = coerceRsaPublicKeyPem(key);
6319
6320
  _assert2.default.call(void 0, typeof key === "string");
6320
6321
  const keyObject = _crypto2.createPublicKey.call(void 0, key);
6321
- const modulusLength = _optionalChain([keyObject, 'access', _17 => _17.asymmetricKeyDetails, 'optionalAccess', _18 => _18.modulusLength]);
6322
+ const modulusLength = _optionalChain([keyObject, 'access', _21 => _21.asymmetricKeyDetails, 'optionalAccess', _22 => _22.modulusLength]);
6322
6323
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from public key");
6323
6324
  return modulusLength / 8;
6324
6325
  }
@@ -6623,4 +6624,4 @@ asn1js/build/index.es.js:
6623
6624
  *
6624
6625
  *)
6625
6626
  */
6626
- //# sourceMappingURL=chunk-R6I4NJSZ.cjs.map
6627
+ //# sourceMappingURL=chunk-AZUYUXWD.cjs.map