@guanghechen/byte 2.0.2 → 2.0.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 2.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Overwrite buffers with cryptographically strong random data.
8
+
3
9
  ## 2.0.2
4
10
 
5
11
  ### Patch Changes
package/lib/cjs/index.cjs CHANGED
@@ -187,9 +187,7 @@ function bytes2text(bytes, encoding) {
187
187
  }
188
188
 
189
189
  function destroyBytes(bytes) {
190
- bytes.fill(0);
191
- bytes.fill(1);
192
- bytes.fill(Math.random() * 127);
190
+ node_crypto.randomFillSync(bytes);
193
191
  }
194
192
  function destroyBytesList(bytesList) {
195
193
  for (const bytes of bytesList)
package/lib/esm/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { randomBytes as randomBytes$1 } from 'node:crypto';
1
+ import { randomFillSync, randomBytes as randomBytes$1 } from 'node:crypto';
2
2
 
3
3
  const CODES = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
4
4
  const CODE_PADDING = '=';
@@ -185,9 +185,7 @@ function bytes2text(bytes, encoding) {
185
185
  }
186
186
 
187
187
  function destroyBytes(bytes) {
188
- bytes.fill(0);
189
- bytes.fill(1);
190
- bytes.fill(Math.random() * 127);
188
+ randomFillSync(bytes);
191
189
  }
192
190
  function destroyBytesList(bytesList) {
193
191
  for (const bytes of bytesList)
@@ -20,7 +20,7 @@ declare function utf8Text2bytes(utf8Text: string): Uint8Array;
20
20
  declare function bytes2utf8Text(bytes: Readonly<Uint8Array>): string;
21
21
 
22
22
  /**
23
- * Fill the bytes with random numbers.
23
+ * Overwrite the bytes in place with cryptographically strong random data.
24
24
  * @param bytes
25
25
  */
26
26
  declare function destroyBytes(bytes: Uint8Array): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guanghechen/byte",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Utility functions for bytes (Uint8Array).",
5
5
  "author": {
6
6
  "name": "guanghechen",