]> git.codecow.com Git - libnemo.git/commitdiff
Deprecate unnecessary and redundant ArrayBuffer convert functions.
authorChris Duncan <chris@zoso.dev>
Sat, 5 Jul 2025 08:36:09 +0000 (01:36 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 5 Jul 2025 08:36:09 +0000 (01:36 -0700)
src/lib/convert.ts
src/lib/workers/safe.ts

index 038a9d6f5ae1ce708d20aa433d4b3a65ac78c489..f2a05907a4872d7fab2b5cef0e43777f40ed44aa 100644 (file)
@@ -75,59 +75,6 @@ export class bin {
        }\r
 }\r
 \r
-export class buffer {\r
-       /**\r
-       * Converts an ArrayBuffer to a base32 string.\r
-       *\r
-       * @param {ArrayBuffer} buffer - Buffer to convert\r
-       * @returns {string} Base32 string representation of the input buffer\r
-       */\r
-       static toBase32 (buffer: ArrayBuffer): string {\r
-               return bytes.toBase32(new Uint8Array(buffer))\r
-       }\r
-\r
-       /**\r
-       * Converts an ArrayBuffer to a binary string.\r
-       *\r
-       * @param {ArrayBuffer} buffer - Buffer to convert\r
-       * @returns {string} Binary string representation of the input buffer\r
-       */\r
-       static toBin (buffer: ArrayBuffer): string {\r
-               return bytes.toBin(new Uint8Array(buffer))\r
-       }\r
-\r
-       /**\r
-       * Sums an ArrayBuffer to a decimal integer. If the result is larger than\r
-       * Number.MAX_SAFE_INTEGER, it will be returned as a bigint.\r
-       *\r
-       * @param {ArrayBuffer} buffer - Buffer to convert\r
-       * @returns {bigint|number} Decimal sum of the literal buffer values\r
-       */\r
-       static toDec (buffer: ArrayBuffer): bigint | number {\r
-               return bytes.toDec(new Uint8Array(buffer))\r
-       }\r
-\r
-       /**\r
-       * Converts an ArrayBuffer to a hexadecimal string.\r
-       *\r
-       * @param {ArrayBuffer} buffer - Buffer to convert\r
-       * @returns {string} Hexadecimal string representation of the input buffer\r
-       */\r
-       static toHex (buffer: ArrayBuffer): string {\r
-               return bytes.toHex(new Uint8Array(buffer))\r
-       }\r
-\r
-       /**\r
-       * Converts an ArrayBuffer to a UTF-8 text string.\r
-       *\r
-       * @param {ArrayBuffer} buffer - Buffer to convert\r
-       * @returns {string} UTF-8 encoded text string\r
-       */\r
-       static toUtf8 (buffer: ArrayBuffer): string {\r
-               return bytes.toUtf8(new Uint8Array(buffer))\r
-       }\r
-}\r
-\r
 export class bytes {\r
        /**\r
        * Converts a Uint8Aarray of bytes to a base32 string.\r
@@ -365,7 +312,6 @@ export class utf8 {
 export default `\r
        const base32 = ${base32}\r
        const bin = ${bin}\r
-       const buffer = ${buffer}\r
        const bytes = ${bytes}\r
        const dec = ${dec}\r
        const hex = ${hex}\r
index 1860874effea00cb9fb6e7484f638fe16541edf1..233af55b05aaf97e2438226ea5d906b2c381f613 100644 (file)
@@ -3,7 +3,7 @@
 
 'use strict'
 
-import { buffer, hex, obj, utf8, default as Convert } from '#src/lib/convert.js'
+import { bytes, hex, obj, utf8, default as Convert } from '#src/lib/convert.js'
 import { Entropy } from '#src/lib/entropy.js'
 import { WorkerInterface } from '#src/lib/pool.js'
 
@@ -132,7 +132,7 @@ export class Safe extends WorkerInterface {
                        passkey = await globalThis.crypto.subtle.deriveKey(derivationAlgorithm, passkey, derivedKeyType, false, ['encrypt'])
                        const encrypted = await globalThis.crypto.subtle.encrypt({ name: 'AES-GCM', iv: iv.buffer }, passkey, utf8.toBytes(data))
                        const record = {
-                               encrypted: buffer.toHex(encrypted),
+                               encrypted: bytes.toHex(new Uint8Array(encrypted)),
                                iv: iv.hex
                        }
                        return await this.#put(record, name)
@@ -182,7 +182,7 @@ export class Safe extends WorkerInterface {
                        }
                        passkey = await globalThis.crypto.subtle.deriveKey(derivationAlgorithm, passkey, derivedKeyType, false, ['decrypt'])
                        const decrypted = await globalThis.crypto.subtle.decrypt({ name: 'AES-GCM', iv: iv.buffer }, passkey, encrypted)
-                       const decoded = buffer.toUtf8(decrypted)
+                       const decoded = bytes.toUtf8(new Uint8Array(decrypted))
                        const data = JSON.parse(decoded)
                        await this.destroy(name)
                        return data