mol_crypto2_lib 0.0.13 → 0.0.15

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.
package/node.mjs CHANGED
@@ -541,12 +541,23 @@ var $;
541
541
  static from(serial) {
542
542
  if (typeof serial === 'string') {
543
543
  serial = new Uint8Array(serial.match(/.{43}/g)
544
- .flatMap(chunk => [...$mol_base64_url_decode(chunk)]));
544
+ ?.flatMap(chunk => [...$mol_base64_url_decode(chunk)])
545
+ ?? $mol_fail(new Error('Str key too short', { cause: {
546
+ min: 43,
547
+ real: serial.length,
548
+ } })));
545
549
  }
546
550
  return super.from(serial);
547
551
  }
548
552
  asArray() {
549
- return new Uint8Array(this.buffer, this.byteOffset, this.constructor.size_bin);
553
+ const size = this.constructor.size_bin;
554
+ if (this.byteLength < size) {
555
+ return $mol_fail(new Error('Bin key too short', { cause: {
556
+ min: size,
557
+ real: this.byteLength,
558
+ } }));
559
+ }
560
+ return new Uint8Array(this.buffer, this.byteOffset, size);
550
561
  }
551
562
  toString() {
552
563
  return $mol_base64_url_encode(this.asArray());
package/node.test.js CHANGED
@@ -532,12 +532,23 @@ var $;
532
532
  static from(serial) {
533
533
  if (typeof serial === 'string') {
534
534
  serial = new Uint8Array(serial.match(/.{43}/g)
535
- .flatMap(chunk => [...$mol_base64_url_decode(chunk)]));
535
+ ?.flatMap(chunk => [...$mol_base64_url_decode(chunk)])
536
+ ?? $mol_fail(new Error('Str key too short', { cause: {
537
+ min: 43,
538
+ real: serial.length,
539
+ } })));
536
540
  }
537
541
  return super.from(serial);
538
542
  }
539
543
  asArray() {
540
- return new Uint8Array(this.buffer, this.byteOffset, this.constructor.size_bin);
544
+ const size = this.constructor.size_bin;
545
+ if (this.byteLength < size) {
546
+ return $mol_fail(new Error('Bin key too short', { cause: {
547
+ min: size,
548
+ real: this.byteLength,
549
+ } }));
550
+ }
551
+ return new Uint8Array(this.buffer, this.byteOffset, size);
541
552
  }
542
553
  toString() {
543
554
  return $mol_base64_url_encode(this.asArray());