Skip to content

Conversation

jimhark
Copy link

@jimhark jimhark commented Jul 20, 2025

Summary

Use Uint8Array to store binary data. This is a major refactor based on number of lines, but low in complexity, most of the changes are almost mechanical.

Resolves

Resolves #215, #216, #217, #218

Details

  • The big change is to prefer Uint8Array for holding binary data
  • Hex strings are converted to Uint8Array on input
  • Uint8Aarray is converted hex strings for output where needed
  • API calls that accept binary data no longer need conversion from hex strings
  • For large files, memory use is greatly reduced
  • For large files, speed in noticeably improved

Testing

I manually tested node encrypt, node decrypt, and HTML wrapper decrypt.

Notes for Reviewers

The scope should have been limited strictly to the switch from hex strings to Uint8Array, but I included other changes related to memory reduction. I admit that was a mistake. I regret including these smaller changes which should have been separate commits:

jimhark and others added 2 commits July 20, 2025 12:07
This is part of a push to support larger files. The focus is the switch
to using Uint8Array to store binary data. But also includes:

- When running on Node, use Buffer.from() for hex string conversions.

- To avoid large buffer copy, signedMsg as been replaced by an object
    containing  iv, encrypted, and hmac.

- hmac calculation has changed so it avoids copying (possibly very
    large) encrypted data. See signDigest() in lib/codec.js.

- Minor cleanup

Handling hex encode/decode at the input/output boundaries and using
Uint8Array internally for representing binary data has these benefits:

- More memory efficient, allows processing of 2x larger files.

- Aligns with cryptographic best practices: hashing is now performed
  on raw binary data (Uint8Array) instead of hex strings.

- Behavior is (mostly) unchanged
  - scripts/index_template.html textContent is not implemented and
    needs to be redesigned.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use UInt8Array to represent binary data
1 participant