node-opcua-crypto 5.3.2 → 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",
@@ -1741,6 +1742,7 @@ var Subject = class _Subject {
1741
1742
  // source/x509/_crypto.ts
1742
1743
 
1743
1744
  var _webcrypto = require('@peculiar/webcrypto');
1745
+ require('reflect-metadata');
1744
1746
  var _x509 = require('@peculiar/x509'); var x509 = _interopRequireWildcard(_x509); var x5092 = _interopRequireWildcard(_x509);
1745
1747
 
1746
1748
  var doDebug3 = false;
@@ -1748,7 +1750,7 @@ var _crypto;
1748
1750
  var ignoreCrypto = process.env.IGNORE_SUBTLE_FROM_CRYPTO;
1749
1751
  if (typeof window === "undefined") {
1750
1752
  _crypto = _crypto3.default;
1751
- if (!_optionalChain([_crypto, 'optionalAccess', _12 => _12.subtle]) || ignoreCrypto) {
1753
+ if (!_optionalChain([_crypto, 'optionalAccess', _16 => _16.subtle]) || ignoreCrypto) {
1752
1754
  _crypto = new (0, _webcrypto.Crypto)();
1753
1755
  doDebug3 && console.warn("using @peculiar/webcrypto");
1754
1756
  } else {
@@ -6266,7 +6268,7 @@ async function createSelfSignedCertificate({
6266
6268
  function rsaLengthPrivateKey(key) {
6267
6269
  const keyPem = typeof key.hidden === "string" ? key.hidden : key.hidden.export({ type: "pkcs1", format: "pem" }).toString();
6268
6270
  const keyObject = _crypto2.createPrivateKey.call(void 0, keyPem);
6269
- 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]);
6270
6272
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from private key");
6271
6273
  return modulusLength / 8;
6272
6274
  }
@@ -6309,7 +6311,7 @@ function rsaLengthPublicKey(key) {
6309
6311
  key = coercePublicKeyPem(key);
6310
6312
  _assert2.default.call(void 0, typeof key === "string");
6311
6313
  const keyObject = _crypto2.createPublicKey.call(void 0, key);
6312
- 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]);
6313
6315
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from public key");
6314
6316
  return modulusLength / 8;
6315
6317
  }
@@ -6317,7 +6319,7 @@ function rsaLengthRsaPublicKey(key) {
6317
6319
  key = coerceRsaPublicKeyPem(key);
6318
6320
  _assert2.default.call(void 0, typeof key === "string");
6319
6321
  const keyObject = _crypto2.createPublicKey.call(void 0, key);
6320
- 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]);
6321
6323
  _assert2.default.call(void 0, modulusLength, "Cannot determine modulus length from public key");
6322
6324
  return modulusLength / 8;
6323
6325
  }
@@ -6622,4 +6624,4 @@ asn1js/build/index.es.js:
6622
6624
  *
6623
6625
  *)
6624
6626
  */
6625
- //# sourceMappingURL=chunk-TSW463FI.cjs.map
6627
+ //# sourceMappingURL=chunk-AZUYUXWD.cjs.map